-
Notifications
You must be signed in to change notification settings - Fork 25
Optimize contracts #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize contracts #123
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,25 +23,24 @@ contract Ethscriptions is ERC721EthscriptionsUpgradeable { | |
| // STRUCTS | ||
| // ============================================================= | ||
|
|
||
| struct ContentInfo { | ||
| bytes32 contentUriHash; // SHA256 of raw content URI string (for protocol uniqueness) | ||
| bytes32 contentSha; // SHA256 of decoded raw bytes (for storage reference) | ||
| string mimetype; // Full MIME type (e.g., "text/plain") | ||
| string mediaType; // e.g., "text", "image" | ||
| string mimeSubtype; // e.g., "plain", "png" | ||
| bool esip6; | ||
| } | ||
|
|
||
| struct Ethscription { | ||
| ContentInfo content; | ||
| // Full slots | ||
| bytes32 contentUriHash; | ||
| bytes32 contentSha; | ||
| bytes32 l1BlockHash; | ||
| // Packed slot (32 bytes) | ||
| address creator; | ||
| uint48 createdAt; | ||
| uint48 l1BlockNumber; | ||
|
Comment on lines
+33
to
+34
|
||
| // Dynamic | ||
| string mimetype; | ||
| // Packed slot (27 bytes used, 5 free) | ||
| address initialOwner; | ||
| uint48 ethscriptionNumber; | ||
| bool esip6; | ||
| // Packed slot (26 bytes used, 6 free) | ||
| address previousOwner; | ||
| uint256 ethscriptionNumber; | ||
| uint256 createdAt; // Timestamp when created | ||
| uint64 l1BlockNumber; // L1 block number when created | ||
| uint64 l2BlockNumber; // L2 block number when created | ||
| bytes32 l1BlockHash; // L1 block hash when created | ||
| uint48 l2BlockNumber; | ||
| } | ||
|
|
||
| struct ProtocolParams { | ||
|
|
@@ -56,8 +55,6 @@ contract Ethscriptions is ERC721EthscriptionsUpgradeable { | |
| address initialOwner; | ||
| bytes content; // Raw decoded bytes (not Base64) | ||
| string mimetype; | ||
| string mediaType; | ||
| string mimeSubtype; | ||
| bool esip6; | ||
| ProtocolParams protocolParams; // Protocol operation data (optional) | ||
| } | ||
|
|
@@ -216,22 +213,18 @@ contract Ethscriptions is ERC721EthscriptionsUpgradeable { | |
| bytes32 contentSha = _storeContent(params.content); | ||
|
|
||
| ethscriptions[params.transactionHash] = Ethscription({ | ||
| content: ContentInfo({ | ||
| contentUriHash: params.contentUriHash, | ||
| contentSha: contentSha, | ||
| mimetype: params.mimetype, | ||
| mediaType: params.mediaType, | ||
| mimeSubtype: params.mimeSubtype, | ||
| esip6: params.esip6 | ||
| }), | ||
| contentUriHash: params.contentUriHash, | ||
| contentSha: contentSha, | ||
| l1BlockHash: l1Block.hash(), | ||
| creator: creator, | ||
| createdAt: uint48(block.timestamp), | ||
| l1BlockNumber: uint48(l1Block.number()), | ||
| mimetype: params.mimetype, | ||
| initialOwner: params.initialOwner, | ||
| previousOwner: creator, // Initially same as creator | ||
| ethscriptionNumber: totalSupply(), | ||
| createdAt: block.timestamp, | ||
| l1BlockNumber: l1Block.number(), | ||
| l2BlockNumber: uint64(block.number), | ||
| l1BlockHash: l1Block.hash() | ||
| ethscriptionNumber: uint48(totalSupply()), | ||
| esip6: params.esip6, | ||
| previousOwner: creator, | ||
| l2BlockNumber: uint48(block.number) | ||
| }); | ||
|
|
||
| // Use ethscription number as token ID | ||
|
|
@@ -377,7 +370,7 @@ contract Ethscriptions is ERC721EthscriptionsUpgradeable { | |
| /// @notice Get content for an ethscription | ||
| function getEthscriptionContent(bytes32 txHash) public view requireExists(txHash) returns (bytes memory) { | ||
| Ethscription storage etsc = ethscriptions[txHash]; | ||
| address[] storage pointers = contentPointersBySha[etsc.content.contentSha]; | ||
| address[] storage pointers = contentPointersBySha[etsc.contentSha]; | ||
| // Empty content is valid - returns "" for empty pointers array | ||
| return pointers.read(); | ||
| } | ||
|
|
@@ -388,7 +381,7 @@ contract Ethscriptions is ERC721EthscriptionsUpgradeable { | |
| /// @return content The content bytes | ||
| function getEthscriptionWithContent(bytes32 txHash) external view requireExists(txHash) returns (Ethscription memory ethscription, bytes memory content) { | ||
| ethscription = ethscriptions[txHash]; | ||
| address[] storage pointers = contentPointersBySha[ethscription.content.contentSha]; | ||
| address[] storage pointers = contentPointersBySha[ethscription.contentSha]; | ||
| // Empty content is valid - returns "" for empty pointers array | ||
| content = pointers.read(); | ||
| } | ||
|
|
@@ -620,8 +613,8 @@ contract Ethscriptions is ERC721EthscriptionsUpgradeable { | |
| txHash, | ||
| etsc.creator, | ||
| etsc.initialOwner, | ||
| etsc.content.contentUriHash, | ||
| etsc.content.contentSha, | ||
| etsc.contentUriHash, | ||
| etsc.contentSha, | ||
| etsc.ethscriptionNumber | ||
| ); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,26 +19,26 @@ contract EthscriptionsProver { | |
|
|
||
| /// @notice Info stored when an ethscription is queued for proving | ||
| struct QueuedProof { | ||
| uint256 l2BlockNumber; | ||
| uint256 l2BlockTimestamp; | ||
| bytes32 l1BlockHash; | ||
| uint256 l1BlockNumber; | ||
| uint48 l2BlockNumber; | ||
| uint48 l2BlockTimestamp; | ||
| uint48 l1BlockNumber; | ||
|
Comment on lines
+23
to
+25
|
||
| } | ||
|
|
||
| /// @notice Struct for ethscription data proof | ||
| struct EthscriptionDataProof { | ||
| bytes32 ethscriptionTxHash; | ||
| bytes32 contentSha; | ||
| bytes32 contentUriHash; | ||
| bytes32 l1BlockHash; | ||
| address creator; | ||
| address currentOwner; | ||
| address previousOwner; | ||
| uint256 ethscriptionNumber; | ||
| bool esip6; | ||
| bytes32 l1BlockHash; | ||
| uint256 l1BlockNumber; | ||
| uint256 l2BlockNumber; | ||
| uint256 l2Timestamp; | ||
| uint48 ethscriptionNumber; | ||
| uint48 l1BlockNumber; | ||
| uint48 l2BlockNumber; | ||
| uint48 l2Timestamp; | ||
| } | ||
|
|
||
| // ============================================================= | ||
|
|
@@ -99,10 +99,10 @@ contract EthscriptionsProver { | |
| // Capture the L1 block hash and number at the time of queuing | ||
| L1Block l1Block = L1Block(L1_BLOCK); | ||
| queuedProofInfo[txHash] = QueuedProof({ | ||
| l2BlockNumber: block.number, | ||
| l2BlockTimestamp: block.timestamp, | ||
| l1BlockHash: l1Block.hash(), | ||
| l1BlockNumber: l1Block.number() | ||
| l2BlockNumber: uint48(block.number), | ||
| l2BlockTimestamp: uint48(block.timestamp), | ||
| l1BlockNumber: uint48(l1Block.number()) | ||
| }); | ||
| } | ||
| } | ||
|
|
@@ -143,14 +143,14 @@ contract EthscriptionsProver { | |
| // Create proof struct with all ethscription data | ||
| EthscriptionDataProof memory proof = EthscriptionDataProof({ | ||
| ethscriptionTxHash: ethscriptionTxHash, | ||
| contentSha: etsc.content.contentSha, | ||
| contentUriHash: etsc.content.contentUriHash, | ||
| contentSha: etsc.contentSha, | ||
| contentUriHash: etsc.contentUriHash, | ||
| l1BlockHash: proofInfo.l1BlockHash, | ||
| creator: etsc.creator, | ||
| currentOwner: currentOwner, | ||
| previousOwner: etsc.previousOwner, | ||
| esip6: etsc.esip6, | ||
| ethscriptionNumber: etsc.ethscriptionNumber, | ||
| esip6: etsc.content.esip6, | ||
| l1BlockHash: proofInfo.l1BlockHash, | ||
| l1BlockNumber: proofInfo.l1BlockNumber, | ||
| l2BlockNumber: proofInfo.l2BlockNumber, | ||
| l2Timestamp: proofInfo.l2BlockTimestamp | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
firstmethod on String returns the first character, not the first N characters. Use[0, MAX_MIMETYPE_LENGTH]ortruncate(MAX_MIMETYPE_LENGTH, omission: '')instead to limit the mimetype length properly.