Skip to content

Commit 26dc704

Browse files
authored
Merge pull request #6 from init4tech/anna/bad-sig
update: unify BadSignature / NotSequencer errors
2 parents 617b96f + 263d0be commit 26dc704

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

src/Zenith.sol

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,10 @@ contract Zenith is HostPassage, AccessControlDefaultAdminRules {
3636
/// @notice Thrown when a block submission is attempted when the confirmBy time has passed.
3737
error BlockExpired();
3838

39-
/// @notice Thrown when a block submission is attempted with a signature over different data.
40-
/// @param hashes - the encoded blob hashes attached to the transaction.
41-
/// @param v - the v component of the Sequencer's ECSDA signature over the block commitment.
42-
/// @param r - the r component of the Sequencer's ECSDA signature over the block commitment.
43-
/// @param s - the s component of the Sequencer's ECSDA signature over the block commitment.
44-
error BadSignature(bytes hashes, uint8 v, bytes32 r, bytes32 s);
45-
46-
/// @notice Thrown when a block submission is attempted with a signature by a non-permissioned sequencer.
47-
/// @param sequencer - the signer of the block data that is not a permissioned sequencer.
48-
error NotSequencer(address sequencer);
39+
/// @notice Thrown when a block submission is attempted with a signature by a non-permissioned sequencer,
40+
/// OR when signature is produced over different data than is provided.
41+
/// @param derivedSequencer - the derived signer of the block data that is not a permissioned sequencer.
42+
error BadSignature(address derivedSequencer);
4943

5044
/// @notice Emitted when a new rollup block is successfully submitted.
5145
/// @param sequencer - the address of the sequencer that signed the block.
@@ -69,8 +63,8 @@ contract Zenith is HostPassage, AccessControlDefaultAdminRules {
6963
/// @param s - the s component of the Sequencer's ECSDA signature over the block commitment.
7064
/// @custom:reverts BadSequence if the sequence number is not the next block for the given rollup chainId.
7165
/// @custom:reverts BlockExpired if the confirmBy time has passed.
72-
/// @custom:reverts BadSignature if the signature provided commits to different block data.
73-
/// @custom:reverts NotSequencer if the signer is not a permissioned sequencer.
66+
/// @custom:reverts BadSignature if the signer is not a permissioned sequencer,
67+
/// OR if the signature provided commits to different block data.
7468
/// @custom:emits BlockSubmitted if the block is successfully submitted.
7569
function submitBlock(BlockHeader memory header, uint32[] memory blobIndices, uint8 v, bytes32 r, bytes32 s)
7670
external
@@ -83,17 +77,13 @@ contract Zenith is HostPassage, AccessControlDefaultAdminRules {
8377
if (block.timestamp > header.confirmBy) revert BlockExpired();
8478

8579
// derive block commitment from sequence number and blobhashes
86-
(bytes32 blockCommit, bytes memory hashes) = blockCommitment(header, blobIndices);
80+
bytes32 blockCommit = blockCommitment(header, blobIndices);
8781

8882
// derive sequencer from signature
8983
address sequencer = ecrecover(blockCommit, v, r, s);
9084

91-
// if the derived signer is address(0), the signature is invalid over the derived blockCommit
92-
// emit the data required to inspect the signature off-chain
93-
if (sequencer == address(0)) revert BadSignature(hashes, v, r, s);
94-
95-
// assert that sequencer is permissioned
96-
if (!hasRole(SEQUENCER_ROLE, sequencer)) revert NotSequencer(sequencer);
85+
// assert that signature is valid && sequencer is permissioned
86+
if (!hasRole(SEQUENCER_ROLE, sequencer)) revert BadSignature(sequencer);
9787

9888
// emit event
9989
emit BlockSubmitted(sequencer, header, blobIndices);
@@ -132,10 +122,9 @@ contract Zenith is HostPassage, AccessControlDefaultAdminRules {
132122
function blockCommitment(BlockHeader memory header, uint32[] memory blobIndices)
133123
internal
134124
view
135-
returns (bytes32 commit, bytes memory hashes)
125+
returns (bytes32 commit)
136126
{
137-
hashes = getHashes(blobIndices);
138-
commit = getCommit(header, hashes);
127+
commit = getCommit(header, getHashes(blobIndices));
139128
}
140129

141130
/// @notice Encode an array of blob hashes, given their indices in the transaction.

test/Zenith.t.sol

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ contract ZenithTest is Test {
8181
// sign block commitmenet with NOT sequencer key
8282
(uint8 v, bytes32 r, bytes32 s) = vm.sign(notSequencerKey, commit);
8383

84-
vm.expectRevert(abi.encodeWithSelector(Zenith.NotSequencer.selector, vm.addr(notSequencerKey)));
84+
vm.expectRevert(abi.encodeWithSelector(Zenith.BadSignature.selector, vm.addr(notSequencerKey)));
8585
target.submitBlock(header, blobIndices, v, r, s);
8686
}
8787

@@ -93,7 +93,10 @@ contract ZenithTest is Test {
9393
// change header data from what was signed by sequencer
9494
header.confirmBy = block.timestamp + 15 minutes;
9595

96-
vm.expectRevert(abi.encodeWithSelector(Zenith.BadSignature.selector, target.packHashes(blobHashes), v, r, s));
96+
bytes32 newCommit = target.blockCommitment(header, blobHashes);
97+
address derivedSigner = ecrecover(newCommit, v, r, s);
98+
99+
vm.expectRevert(abi.encodeWithSelector(Zenith.BadSignature.selector, derivedSigner));
97100
target.submitBlock(header, blobIndices, v, r, s);
98101
}
99102

@@ -105,7 +108,10 @@ contract ZenithTest is Test {
105108
blobHashes[0] = bytes32("DIFFERENT BLOBHASH");
106109
// TODO: vm.blobhashes(blobHashes);
107110

108-
vm.expectRevert(abi.encodeWithSelector(Zenith.BadSignature.selector, target.packHashes(blobHashes), v, r, s));
111+
bytes32 newCommit = target.blockCommitment(header, blobHashes);
112+
address derivedSigner = ecrecover(newCommit, v, r, s);
113+
114+
vm.expectRevert(abi.encodeWithSelector(Zenith.BadSignature.selector, derivedSigner));
109115
target.submitBlock(header, blobIndices, v, r, s);
110116
}
111117
}

0 commit comments

Comments
 (0)