@@ -20,6 +20,7 @@ contract Zenith is HostPassage, AccessControlDefaultAdminRules {
20
20
/// @param confirmBy - the timestamp by which the block must be submitted. Enforced by the contract.
21
21
/// @param gasLimit - the gas limit for the rollup block. Ignored by the contract; enforced by the Node.
22
22
/// @param rewardAddress - the address to receive the rollup block reward. Ignored by the contract; enforced by the Node.
23
+
23
24
struct BlockHeader {
24
25
uint256 rollupChainId;
25
26
uint256 sequence;
@@ -75,8 +76,10 @@ contract Zenith is HostPassage, AccessControlDefaultAdminRules {
75
76
/// @param s - see _submitBlock.
76
77
/// @custom:reverts see _submitBlock.
77
78
/// @custom:emits see _submitBlock.
78
- function submitBlock (BlockHeader memory header , bytes memory blockData , uint8 v , bytes32 r , bytes32 s ) external {
79
- _submitBlock (DataLocation.Calldata, header, blockData, v, r, s);
79
+ function submitBlock (BlockHeader memory header , bytes calldata blockData , uint8 v , bytes32 r , bytes32 s ) external {
80
+ bytes32 blockCommit = blockCommitment (header, blockData);
81
+
82
+ _submitBlock (DataLocation.Calldata, header, blockCommit, v, r, s);
80
83
81
84
emit BlockData (blockData);
82
85
}
@@ -89,23 +92,20 @@ contract Zenith is HostPassage, AccessControlDefaultAdminRules {
89
92
/// @param s - see _submitBlock.
90
93
/// @custom:reverts see _submitBlock.
91
94
/// @custom:emits see _submitBlock.
92
- function submitBlock (BlockHeader memory header , uint32 [] memory blobIndices , uint8 v , bytes32 r , bytes32 s )
95
+ function submitBlock (BlockHeader memory header , uint32 [] calldata blobIndices , uint8 v , bytes32 r , bytes32 s )
93
96
external
94
97
{
95
- // query the blob hashes via the indices in order to
96
- // ensure that the committed blob hashes are available in the transaction.
97
- bytes memory encodedHashes = getHashes (blobIndices);
98
+ bytes32 blockCommit = blockCommitment (header, blobIndices);
98
99
99
- _submitBlock (DataLocation.Blobs, header, encodedHashes , v, r, s);
100
+ _submitBlock (DataLocation.Blobs, header, blockCommit , v, r, s);
100
101
101
102
emit BlobIndices (blobIndices);
102
103
}
103
104
104
105
/// @notice Submit a rollup block.
105
106
/// @dev Blocks are submitted by Builders, with an attestation to the block data signed by a Sequencer.
106
107
/// @param header - the header information for the rollup block.
107
- /// @param committedData - if DataLocation = Blobs, committedData = encoded blob hashes for the blobs where the block data resides.
108
- /// if DataLocation = Calldata, committedData = full block data.
108
+ /// @param blockCommit - the hashes `blockCommitment` signed by the Sequencer.
109
109
/// @param v - the v component of the Sequencer's ECSDA signature over the block commitment.
110
110
/// @param r - the r component of the Sequencer's ECSDA signature over the block commitment.
111
111
/// @param s - the s component of the Sequencer's ECSDA signature over the block commitment.
@@ -117,7 +117,7 @@ contract Zenith is HostPassage, AccessControlDefaultAdminRules {
117
117
function _submitBlock (
118
118
DataLocation location ,
119
119
BlockHeader memory header ,
120
- bytes memory committedData ,
120
+ bytes32 blockCommit ,
121
121
uint8 v ,
122
122
bytes32 r ,
123
123
bytes32 s
@@ -129,9 +129,6 @@ contract Zenith is HostPassage, AccessControlDefaultAdminRules {
129
129
// assert that confirmBy time has not passed
130
130
if (block .timestamp > header.confirmBy) revert BlockExpired ();
131
131
132
- // derive block commitment from sequence number and blobhashes
133
- bytes32 blockCommit = blockCommitment (header, committedData);
134
-
135
132
// derive sequencer from signature
136
133
address sequencer = ecrecover (blockCommit, v, r, s);
137
134
@@ -145,19 +142,18 @@ contract Zenith is HostPassage, AccessControlDefaultAdminRules {
145
142
/// @notice Encode an array of blob hashes, given their indices in the transaction.
146
143
/// @param blobIndices - the indices of the 4844 blob hashes for the block data.
147
144
/// @return encodedHashes - the encoded blob hashes.
148
- function getHashes (uint32 [] memory blobIndices ) internal view returns (bytes memory encodedHashes ) {
145
+ function getHashes (uint32 [] calldata blobIndices ) internal view returns (bytes memory encodedHashes ) {
149
146
for (uint32 i = 0 ; i < blobIndices.length ; i++ ) {
150
147
encodedHashes = abi.encodePacked (encodedHashes, blobhash (blobIndices[i]));
151
148
}
152
149
}
153
150
154
151
/// @notice Construct hash of block details that the sequencer signs.
152
+ /// @dev NOTE: we have separate blockCommitment functions in order to keep `blockData` as `calldata`, which is not possible for `encodedHashes`
155
153
/// @param header - the header information for the rollup block.
156
- /// @param committedData - the data for the rollup block that was signed by the sequencer.
157
- /// if DataLocation = Blobs, committedData = encoded blob hashes.
158
- /// if DataLocation = Blobs, committedData = full block data.
154
+ /// @param blockData - full data for the block supplied directly.
159
155
/// @return commit - the hash of the encoded block details.
160
- function blockCommitment (BlockHeader memory header , bytes memory committedData )
156
+ function blockCommitment (BlockHeader memory header , bytes calldata blockData )
161
157
public
162
158
view
163
159
returns (bytes32 commit )
@@ -170,8 +166,35 @@ contract Zenith is HostPassage, AccessControlDefaultAdminRules {
170
166
header.gasLimit,
171
167
header.confirmBy,
172
168
header.rewardAddress,
173
- committedData.length ,
174
- committedData
169
+ blockData.length ,
170
+ blockData
171
+ );
172
+ commit = keccak256 (encoded);
173
+ }
174
+
175
+ /// @notice Construct hash of block details that the sequencer signs.
176
+ /// @param header - the header information for the rollup block.
177
+ /// @param blobIndices - the indices of the 4844 blob hashes for the block data.
178
+ /// @return commit - the hash of the encoded block details.
179
+ function blockCommitment (BlockHeader memory header , uint32 [] calldata blobIndices )
180
+ public
181
+ view
182
+ returns (bytes32 commit )
183
+ {
184
+ // query the blob hashes via the indices in order to
185
+ // ensure that the committed blob hashes are available in the transaction.
186
+ bytes memory encodedHashes = getHashes (blobIndices);
187
+
188
+ bytes memory encoded = abi.encodePacked (
189
+ "init4.sequencer.v0 " ,
190
+ block .chainid ,
191
+ header.rollupChainId,
192
+ header.sequence,
193
+ header.gasLimit,
194
+ header.confirmBy,
195
+ header.rewardAddress,
196
+ encodedHashes.length ,
197
+ encodedHashes
175
198
);
176
199
commit = keccak256 (encoded);
177
200
}
0 commit comments