Skip to content

Commit

Permalink
feat(contracts): add chain id in public input hash (#517)
Browse files Browse the repository at this point in the history
Co-authored-by: Haichen Shen <shenhaichen@gmail.com>
Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
  • Loading branch information
3 people committed May 28, 2023
1 parent 4398a36 commit aa24cdd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion contracts/scripts/foundry/DeployL1BridgeContracts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {Whitelist} from "../../src/L2/predeploys/Whitelist.sol";
contract DeployL1BridgeContracts is Script {
uint256 L1_DEPLOYER_PRIVATE_KEY = vm.envUint("L1_DEPLOYER_PRIVATE_KEY");

uint256 CHAIN_ID_L2 = vm.envUint("CHAIN_ID_L2");
uint32 CHAIN_ID_L2 = uint32(vm.envUint("CHAIN_ID_L2"));

address L1_WETH_ADDR = vm.envAddress("L1_WETH_ADDR");
address L2_WETH_ADDR = vm.envAddress("L2_WETH_ADDR");
Expand Down
9 changes: 6 additions & 3 deletions contracts/src/L1/rollup/ScrollChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {BatchHeaderV0Codec} from "../../libraries/codec/BatchHeaderV0Codec.sol";
import {ChunkCodec} from "../../libraries/codec/ChunkCodec.sol";
import {IRollupVerifier} from "../../libraries/verifier/IRollupVerifier.sol";

// solhint-disable no-inline-assembly
// solhint-disable reason-string

/// @title ScrollChain
Expand Down Expand Up @@ -39,7 +40,7 @@ contract ScrollChain is OwnableUpgradeable, IScrollChain {
*************/

/// @notice The chain id of the corresponding layer 2 chain.
uint256 public immutable layer2ChainId;
uint32 public immutable layer2ChainId;

/*************
* Variables *
Expand Down Expand Up @@ -83,7 +84,7 @@ contract ScrollChain is OwnableUpgradeable, IScrollChain {
* Constructor *
***************/

constructor(uint256 _chainId) {
constructor(uint32 _chainId) {
layer2ChainId = _chainId;
}

Expand Down Expand Up @@ -295,7 +296,9 @@ contract ScrollChain is OwnableUpgradeable, IScrollChain {
require(finalizedStateRoots[_batchIndex] == bytes32(0), "batch already verified");

// compute public input hash
bytes32 _publicInputHash = keccak256(abi.encode(_prevStateRoot, _postStateRoot, _withdrawRoot, _dataHash));
bytes32 _publicInputHash = keccak256(
abi.encodePacked(layer2ChainId, _prevStateRoot, _postStateRoot, _withdrawRoot, _dataHash)
);

// verify batch
IRollupVerifier(verifier).verifyAggregateProof(_aggrProof, _publicInputHash);
Expand Down
2 changes: 2 additions & 0 deletions contracts/src/libraries/codec/BatchHeaderV0Codec.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

pragma solidity ^0.8.0;

// solhint-disable no-inline-assembly

/// @dev Below is the encoding for `BatchHeader` V0, total 89 + ceil(l1MessagePopped / 256) * 32 bytes.
/// ```text
/// * Field Bytes Type Index Comments
Expand Down

0 comments on commit aa24cdd

Please sign in to comment.