Skip to content

Commit

Permalink
feat(contracts): make sure prover and sequencer is EOA (#1002)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimpha authored Nov 3, 2023
1 parent 50040a1 commit e6db4ac
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 13 deletions.
7 changes: 7 additions & 0 deletions contracts/src/L1/rollup/ScrollChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
/// @notice Add an account to the sequencer list.
/// @param _account The address of account to add.
function addSequencer(address _account) external onlyOwner {
// @note Currently many external services rely on EOA sequencer to decode metadata directly from tx.calldata.
// So we explicitly make sure the account is EOA.
require(_account.code.length == 0, "not EOA");

isSequencer[_account] = true;

emit UpdateSequencer(_account, true);
Expand All @@ -376,6 +380,9 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
/// @notice Add an account to the prover list.
/// @param _account The address of account to add.
function addProver(address _account) external onlyOwner {
// @note Currently many external services rely on EOA prover to decode metadata directly from tx.calldata.
// So we explicitly make sure the account is EOA.
require(_account.code.length == 0, "not EOA");
isProver[_account] = true;

emit UpdateProver(_account, true);
Expand Down
8 changes: 6 additions & 2 deletions contracts/src/test/L1GatewayTestBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ abstract contract L1GatewayTestBase is DSTestPlus {
}

function prepareL2MessageRoot(bytes32 messageHash) internal {
rollup.addSequencer(address(this));
rollup.addProver(address(this));
rollup.addSequencer(address(0));
rollup.addProver(address(0));

// import genesis batch
bytes memory batchHeader0 = new bytes(89);
Expand All @@ -122,7 +122,9 @@ abstract contract L1GatewayTestBase is DSTestPlus {
bytes memory chunk0 = new bytes(1 + 60);
chunk0[0] = bytes1(uint8(1)); // one block in this chunk
chunks[0] = chunk0;
hevm.startPrank(address(0));
rollup.commitBatch(0, batchHeader0, chunks, new bytes(0));
hevm.stopPrank();

bytes memory batchHeader1 = new bytes(89);
assembly {
Expand All @@ -134,12 +136,14 @@ abstract contract L1GatewayTestBase is DSTestPlus {
mstore(add(batchHeader1, add(0x20, 57)), batchHash0) // parentBatchHash
}

hevm.startPrank(address(0));
rollup.finalizeBatchWithProof(
batchHeader1,
bytes32(uint256(1)),
bytes32(uint256(2)),
messageHash,
new bytes(0)
);
hevm.stopPrank();
}
}
Loading

0 comments on commit e6db4ac

Please sign in to comment.