22pragma solidity 0.8.24 ;
33
44import "./Ethscriptions.sol " ;
5- import "./TokenManager.sol " ;
6- import "./EthscriptionsERC20.sol " ;
75import "./L2/L2ToL1MessagePasser.sol " ;
6+ import "./L2/L1Block.sol " ;
87import "./libraries/Predeploys.sol " ;
98import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol " ;
109
@@ -16,8 +15,10 @@ contract EthscriptionsProver {
1615
1716 /// @notice Info stored when an ethscription is queued for proving
1817 struct QueuedProof {
19- uint256 blockNumber;
20- uint256 blockTimestamp;
18+ uint256 l2BlockNumber;
19+ uint256 l2BlockTimestamp;
20+ bytes32 l1BlockHash;
21+ uint256 l1BlockNumber;
2122 }
2223
2324 /// @notice Set of all ethscription transaction hashes queued for proving
@@ -35,83 +36,29 @@ contract EthscriptionsProver {
3536 /// @notice The Ethscriptions contract (pre-deployed at known address)
3637 Ethscriptions public constant ethscriptions = Ethscriptions (Predeploys.ETHSCRIPTIONS);
3738
38- /// @notice The TokenManager contract (pre-deployed at known address)
39- TokenManager public constant tokenManager = TokenManager (Predeploys.TOKEN_MANAGER);
40-
41- /// @notice Struct for token balance proof data
42- struct TokenBalanceProof {
43- address holder;
44- string protocol;
45- string tick;
46- uint256 balance;
47- uint256 l2BlockNumber;
48- uint256 l2Timestamp;
49- // TODO: Add l1BlockNumber once we have L2->L1 block mapping
50- }
51-
5239 /// @notice Struct for ethscription data proof
5340 struct EthscriptionDataProof {
5441 bytes32 ethscriptionTxHash;
5542 bytes32 contentSha;
43+ bytes32 contentUriHash;
5644 address creator;
5745 address currentOwner;
5846 address previousOwner;
5947 uint256 ethscriptionNumber;
60- bool isToken;
61- uint256 tokenAmount;
48+ bool esip6;
49+ bytes32 l1BlockHash;
50+ uint256 l1BlockNumber;
6251 uint256 l2BlockNumber;
6352 uint256 l2Timestamp;
64- // TODO: Add l1BlockNumber once we have L2->L1 block mapping
6553 }
6654
6755 /// @notice Events for tracking proofs
68- event TokenBalanceProofSent (
69- address indexed holder ,
70- string tick ,
71- uint256 indexed l2BlockNumber ,
72- uint256 l2Timestamp
73- );
74-
7556 event EthscriptionDataProofSent (
7657 bytes32 indexed ethscriptionTxHash ,
7758 uint256 indexed l2BlockNumber ,
7859 uint256 l2Timestamp
7960 );
8061
81- /// @notice Emitted when a batch of proofs is flushed
82- event ProofBatchFlushed (uint256 count , uint256 blockNumber );
83-
84- /// @notice Prove token balance for an address
85- /// @param holder The address to prove balance for
86- /// @param deployTxHash The deploy transaction hash (identifies the token type)
87- function proveTokenBalance (
88- address holder ,
89- bytes32 deployTxHash
90- ) external {
91- // Get token info from TokenManager
92- TokenManager.TokenInfo memory tokenInfo = tokenManager.getTokenInfo (deployTxHash);
93-
94- // Get balance
95- EthscriptionsERC20 token = EthscriptionsERC20 (tokenInfo.tokenContract);
96- uint256 balance = token.balanceOf (holder);
97-
98- // Create proof struct
99- TokenBalanceProof memory proof = TokenBalanceProof ({
100- holder: holder,
101- protocol: tokenInfo.protocol,
102- tick: tokenInfo.tick,
103- balance: balance,
104- l2BlockNumber: block .number ,
105- l2Timestamp: block .timestamp
106- });
107-
108- // Encode and send to L1 with zero address and gas (only for state recording)
109- bytes memory proofData = abi.encode (proof);
110- L2_TO_L1_MESSAGE_PASSER.initiateWithdrawal (address (0 ), 0 , proofData);
111-
112- emit TokenBalanceProofSent (holder, tokenInfo.tick, block .number , block .timestamp );
113- }
114-
11562 /// @notice Queue an ethscription for proving
11663 /// @dev Only callable by the Ethscriptions contract
11764 /// @param txHash The transaction hash of the ethscription
@@ -121,9 +68,13 @@ contract EthscriptionsProver {
12168 // Add to the set (deduplicates automatically)
12269 if (queuedEthscriptions.add (txHash)) {
12370 // Only store info if this is the first time we're queueing this txHash
71+ // Capture the L1 block hash and number at the time of queuing
72+ L1Block l1Block = L1Block (L1_BLOCK);
12473 queuedProofInfo[txHash] = QueuedProof ({
125- blockNumber: block .number ,
126- blockTimestamp: block .timestamp
74+ l2BlockNumber: block .number ,
75+ l2BlockTimestamp: block .timestamp ,
76+ l1BlockHash: l1Block.hash (),
77+ l1BlockNumber: l1Block.number ()
12778 });
12879 }
12980 }
@@ -140,55 +91,44 @@ contract EthscriptionsProver {
14091 for (uint256 i = count; i > 0 ; i-- ) {
14192 bytes32 txHash = queuedEthscriptions.at (i - 1 );
14293
143- // Get the stored proof info to know which block this was from
144- QueuedProof memory proofInfo = queuedProofInfo[txHash];
145-
14694 // Create and send proof for current state with stored block info
147- _createAndSendProof (txHash, proofInfo.blockNumber, proofInfo.blockTimestamp );
95+ _createAndSendProof (txHash, queuedProofInfo[txHash] );
14896
14997 // Clean up: remove from set and delete the proof info
15098 queuedEthscriptions.remove (txHash);
15199 delete queuedProofInfo[txHash];
152100 }
153-
154- emit ProofBatchFlushed (count, block .number - 1 );
155101 }
156102
157103 /// @notice Internal function to create and send proof for an ethscription
158104 /// @param ethscriptionTxHash The transaction hash of the ethscription
159- /// @param blockNumber The L2 block number being proved
160- /// @param blockTimestamp The timestamp of the L2 block being proved
161- function _createAndSendProof (bytes32 ethscriptionTxHash , uint256 blockNumber , uint256 blockTimestamp ) internal {
105+ /// @param proofInfo The queued proof info containing block data
106+ function _createAndSendProof (bytes32 ethscriptionTxHash , QueuedProof storage proofInfo ) internal {
162107 // Get ethscription data including previous owner
163108 Ethscriptions.Ethscription memory etsc = ethscriptions.getEthscription (ethscriptionTxHash);
164109 address currentOwner = ethscriptions.currentOwner (ethscriptionTxHash);
165110
166- // Check if it's a token item
167- bool isToken = tokenManager.isTokenItem (ethscriptionTxHash);
168- uint256 tokenAmount = 0 ;
169- if (isToken) {
170- tokenAmount = tokenManager.getTokenAmount (ethscriptionTxHash);
171- }
172-
173- // Create proof struct with previous owner
111+ // Create proof struct with all ethscription data
174112 EthscriptionDataProof memory proof = EthscriptionDataProof ({
175113 ethscriptionTxHash: ethscriptionTxHash,
176114 contentSha: etsc.content.contentSha,
115+ contentUriHash: etsc.content.contentUriHash,
177116 creator: etsc.creator,
178117 currentOwner: currentOwner,
179118 previousOwner: etsc.previousOwner,
180119 ethscriptionNumber: etsc.ethscriptionNumber,
181- isToken: isToken,
182- tokenAmount: tokenAmount,
183- l2BlockNumber: blockNumber,
184- l2Timestamp: blockTimestamp
120+ esip6: etsc.content.esip6,
121+ l1BlockHash: proofInfo.l1BlockHash,
122+ l1BlockNumber: proofInfo.l1BlockNumber,
123+ l2BlockNumber: proofInfo.l2BlockNumber,
124+ l2Timestamp: proofInfo.l2BlockTimestamp
185125 });
186126
187127 // Encode and send to L1 with zero address and gas (only for state recording)
188128 bytes memory proofData = abi.encode (proof);
189129 L2_TO_L1_MESSAGE_PASSER.initiateWithdrawal (address (0 ), 0 , proofData);
190130
191- emit EthscriptionDataProofSent (ethscriptionTxHash, blockNumber, blockTimestamp );
131+ emit EthscriptionDataProofSent (ethscriptionTxHash, proofInfo.l2BlockNumber, proofInfo.l2BlockTimestamp );
192132 }
193133
194134}
0 commit comments