Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions snapshots/verifyBroadcastMessage.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"EthereumToOptimism": "1639195",
"EthereumToOptimism": "1639239",
"EthereumToTaikoL2": "1052214",
"LineaL2ToEthereum": "2551776",
"ScrollL2ToEthereum": "1361940",
"ScrollToOptimism": "1348688",
"ScrollToOptimism": "1348710",
"TaikoL2ToEthereum": "1022277",
"ZkSyncL2ToEthereum": "125663"
}
14 changes: 7 additions & 7 deletions src/contracts/provers/arbitrum/ChildToParentProver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol";
contract ChildToParentProver is IStateProver {
/// @dev Address of the block hash buffer contract
/// See https://github.com/OffchainLabs/block-hash-pusher/blob/a1e26f2e42e6306d1e7f03c5d20fa6aa64ff7a12/.env.example#L12
address public constant blockHashBuffer = 0x0000000048C4Ed10cF14A02B9E0AbDDA5227b071;
address public constant BLOCK_HASH_BUFFER = 0x0000000048C4Ed10cF14A02B9E0AbDDA5227b071;
/// @dev Storage slot the buffer contract uses to store block hashes.
/// See https://github.com/OffchainLabs/block-hash-pusher/blob/a1e26f2e42e6306d1e7f03c5d20fa6aa64ff7a12/contracts/Buffer.sol#L32
uint256 public constant blockHashMappingSlot = 51;
uint256 public constant BLOCK_HASH_MAPPING_SLOT = 51;

/// @dev The chain Id of the home chain, i.e., the child chain.
uint256 public immutable homeChainId;
Expand All @@ -28,7 +28,7 @@ contract ChildToParentProver is IStateProver {
homeChainId = _homeChainId;
}

/// @notice Get a parent chain block hash from the buffer at `blockHashBuffer` using a storage proof
/// @notice Get a parent chain block hash from the buffer at `BLOCK_HASH_BUFFER` using a storage proof
/// @param homeBlockHash The block hash of the home chain.
/// @param input ABI encoded (bytes blockHeader, uint256 targetBlockNumber, bytes accountProof, bytes storageProof)
function verifyTargetStateCommitment(bytes32 homeBlockHash, bytes calldata input)
Expand All @@ -45,15 +45,15 @@ contract ChildToParentProver is IStateProver {

// calculate the slot based on the provided block number
// see: https://github.com/OffchainLabs/block-hash-pusher/blob/a1e26f2e42e6306d1e7f03c5d20fa6aa64ff7a12/contracts/Buffer.sol#L32
uint256 slot = uint256(SlotDerivation.deriveMapping(bytes32(blockHashMappingSlot), targetBlockNumber));
uint256 slot = uint256(SlotDerivation.deriveMapping(bytes32(BLOCK_HASH_MAPPING_SLOT), targetBlockNumber));

// verify proofs and get the block hash
targetStateCommitment = ProverUtils.getSlotFromBlockHeader(
homeBlockHash, rlpBlockHeader, blockHashBuffer, slot, accountProof, storageProof
homeBlockHash, rlpBlockHeader, BLOCK_HASH_BUFFER, slot, accountProof, storageProof
);
}

/// @notice Get a parent chain block hash from the buffer at `blockHashBuffer`.
/// @notice Get a parent chain block hash from the buffer at `BLOCK_HASH_BUFFER`.
/// @param input ABI encoded (uint256 targetBlockNumber)
function getTargetStateCommitment(bytes calldata input) external view returns (bytes32 targetStateCommitment) {
if (block.chainid != homeChainId) {
Expand All @@ -63,7 +63,7 @@ contract ChildToParentProver is IStateProver {
uint256 targetBlockNumber = abi.decode(input, (uint256));

// get the block hash from the buffer
targetStateCommitment = IBuffer(blockHashBuffer).parentChainBlockHash(targetBlockNumber);
targetStateCommitment = IBuffer(BLOCK_HASH_BUFFER).parentChainBlockHash(targetBlockNumber);
}

/// @notice Verify a storage slot given a target chain block hash and a proof.
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/provers/linea/ChildToParentProver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract ChildToParentProver is IStateProver {
address public immutable blockHashBuffer;
/// @dev Storage slot the buffer contract uses to store block hashes.
/// See https://github.com/openintentsframework/broadcaster/blob/main/src/contracts/block-hash-pusher/BaseBuffer.sol
uint256 public constant blockHashMappingSlot = 1;
uint256 public constant BLOCK_HASH_MAPPING_SLOT = 1;

/// @dev The chain ID of the home chain (child chain).
uint256 public immutable homeChainId;
Expand Down Expand Up @@ -44,7 +44,7 @@ contract ChildToParentProver is IStateProver {

// calculate the slot based on the provided block number
// see: https://github.com/OffchainLabs/block-hash-pusher/blob/a1e26f2e42e6306d1e7f03c5d20fa6aa64ff7a12/contracts/Buffer.sol#L32
uint256 slot = uint256(SlotDerivation.deriveMapping(bytes32(blockHashMappingSlot), targetBlockNumber));
uint256 slot = uint256(SlotDerivation.deriveMapping(bytes32(BLOCK_HASH_MAPPING_SLOT), targetBlockNumber));

// verify proofs and get the block hash
targetStateCommitment = ProverUtils.getSlotFromBlockHeader(
Expand Down
8 changes: 4 additions & 4 deletions src/contracts/provers/optimism/ChildToParentProver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ interface IL1Block {
/// Pre-generated proofs become stale when L1Block updates (~5 minutes).
/// Operational difference from Arbitrum: proofs must be generated just-in-time rather than pre-cached.
contract ChildToParentProver is IStateProver {
address public constant l1BlockPredeploy = 0x4200000000000000000000000000000000000015;
uint256 public constant l1BlockHashSlot = 2; // hash is at slot 2
address public constant L1_BLOCK_PREDEPLOY = 0x4200000000000000000000000000000000000015;
uint256 public constant L1_BLOCK_HASH_SLOT = 2; // hash is at slot 2

/// @dev The chain ID of the home chain (Optimism L2)
uint256 public immutable homeChainId;
Expand Down Expand Up @@ -50,7 +50,7 @@ contract ChildToParentProver is IStateProver {

// verify proofs and get the value
targetStateCommitment = ProverUtils.getSlotFromBlockHeader(
homeBlockHash, rlpBlockHeader, l1BlockPredeploy, l1BlockHashSlot, accountProof, storageProof
homeBlockHash, rlpBlockHeader, L1_BLOCK_PREDEPLOY, L1_BLOCK_HASH_SLOT, accountProof, storageProof
);
}

Expand All @@ -67,7 +67,7 @@ contract ChildToParentProver is IStateProver {
if (block.chainid != homeChainId) {
revert CallNotOnHomeChain();
}
return IL1Block(l1BlockPredeploy).hash();
return IL1Block(L1_BLOCK_PREDEPLOY).hash();
}

/// @notice Verify a storage slot given a target chain block hash and a proof.
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/provers/scroll/ChildToParentProver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract ChildToParentProver is IStateProver {
address public immutable blockHashBuffer;
/// @dev Storage slot the buffer contract uses to store block hashes.
/// https://github.com/openintentsframework/broadcaster/blob/main/src/contracts/block-hash-pusher/BaseBuffer.sol
uint256 public constant blockHashMappingSlot = 1;
uint256 public constant BLOCK_HASH_MAPPING_SLOT = 1;

/// @dev The chain ID of the home chain (child chain).
uint256 public immutable homeChainId;
Expand Down Expand Up @@ -45,7 +45,7 @@ contract ChildToParentProver is IStateProver {

// calculate the slot based on the provided block number
// see: https://github.com/OffchainLabs/block-hash-pusher/blob/a1e26f2e42e6306d1e7f03c5d20fa6aa64ff7a12/contracts/Buffer.sol#L32
uint256 slot = uint256(SlotDerivation.deriveMapping(bytes32(blockHashMappingSlot), targetBlockNumber));
uint256 slot = uint256(SlotDerivation.deriveMapping(bytes32(BLOCK_HASH_MAPPING_SLOT), targetBlockNumber));

// verify proofs and get the block hash
targetStateCommitment = ProverUtils.getSlotFromBlockHeader(
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/provers/zksync/ChildToParentProver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract ChildToParentProver is IStateProver {
address public immutable blockHashBuffer;
/// @dev Storage slot the buffer contract uses to store block hashes.
/// See https://github.com/openintentsframework/broadcaster/blob/main/src/contracts/block-hash-pusher/BaseBuffer.sol
uint256 public constant blockHashMappingSlot = 1;
uint256 public constant BLOCK_HASH_MAPPING_SLOT = 1;

/// @dev The chain ID of the home chain (child chain).
uint256 public immutable homeChainId;
Expand Down Expand Up @@ -45,7 +45,7 @@ contract ChildToParentProver is IStateProver {

// calculate the slot based on the provided block number
// see: https://github.com/OffchainLabs/block-hash-pusher/blob/a1e26f2e42e6306d1e7f03c5d20fa6aa64ff7a12/contracts/Buffer.sol#L32
uint256 slot = uint256(SlotDerivation.deriveMapping(bytes32(blockHashMappingSlot), targetBlockNumber));
uint256 slot = uint256(SlotDerivation.deriveMapping(bytes32(BLOCK_HASH_MAPPING_SLOT), targetBlockNumber));

// verify proofs and get the block hash
targetStateCommitment = ProverUtils.getSlotFromBlockHeader(
Expand Down
10 changes: 5 additions & 5 deletions test/Receiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ contract ReceiverTest is Test {
assertEq(blockHash, expectedBlockHash);
bytes memory input = abi.encode(rlpBlockHeader, account, slot, rlpAccountProof, rlpStorageProof);

IL1Block l1Block = IL1Block(childToParentProver.l1BlockPredeploy());
IL1Block l1Block = IL1Block(childToParentProver.L1_BLOCK_PREDEPLOY());

vm.prank(l1Block.DEPOSITOR_ACCOUNT());
l1Block.setL1BlockValues(
Expand Down Expand Up @@ -369,7 +369,7 @@ contract ReceiverTest is Test {
assertEq(blockHash, expectedBlockHash);
bytes memory input = abi.encode(rlpBlockHeader, account, slot, rlpAccountProof, rlpStorageProof);

IL1Block l1Block = IL1Block(childToParentProver.l1BlockPredeploy());
IL1Block l1Block = IL1Block(childToParentProver.L1_BLOCK_PREDEPLOY());

vm.prank(l1Block.DEPOSITOR_ACCOUNT());
l1Block.setL1BlockValues(
Expand Down Expand Up @@ -446,7 +446,7 @@ contract ReceiverTest is Test {
assertEq(blockHash, expectedBlockHash);
bytes memory input = abi.encode(rlpBlockHeader, account, slot, rlpAccountProof, rlpStorageProof);

IL1Block l1Block = IL1Block(childToParentProver.l1BlockPredeploy());
IL1Block l1Block = IL1Block(childToParentProver.L1_BLOCK_PREDEPLOY());

vm.prank(l1Block.DEPOSITOR_ACCOUNT());
l1Block.setL1BlockValues(
Expand Down Expand Up @@ -515,7 +515,7 @@ contract ReceiverTest is Test {
bytes memory inputForOPChildToParentProver =
abi.encode(rlpBlockHeader, account, slot, rlpAccountProof, rlpStorageProof);

IL1Block l1Block = IL1Block(childToParentProver.l1BlockPredeploy());
IL1Block l1Block = IL1Block(childToParentProver.L1_BLOCK_PREDEPLOY());

vm.prank(l1Block.DEPOSITOR_ACCOUNT());
l1Block.setL1BlockValues(
Expand Down Expand Up @@ -579,7 +579,7 @@ contract ReceiverTest is Test {
bytes memory rlpAccountProofArbitrum = jsonArbitrum.readBytes(".rlpAccountProof");
bytes memory rlpStorageProofArbitrum = jsonArbitrum.readBytes(".rlpStorageProof");

IL1Block l1Block = IL1Block(childToParentProver.l1BlockPredeploy());
IL1Block l1Block = IL1Block(childToParentProver.L1_BLOCK_PREDEPLOY());

vm.prank(l1Block.DEPOSITOR_ACCOUNT());
l1Block.setL1BlockValues(
Expand Down
4 changes: 2 additions & 2 deletions test/VerifyBroadcastMessageBenchmark.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ contract VerifyBroadcastMessageBenchmark is Test {
address publisher = 0x9a56fFd72F4B526c523C733F1F74197A51c495E1;

// Mock L1Block predeploy
address l1Block = prover.l1BlockPredeploy();
address l1Block = prover.L1_BLOCK_PREDEPLOY();
vm.mockCall(l1Block, abi.encodeWithSignature("hash()"), abi.encode(blockHash));
vm.mockCall(l1Block, abi.encodeWithSignature("number()"), abi.encode(blockNumber));

Expand Down Expand Up @@ -435,7 +435,7 @@ contract VerifyBroadcastMessageBenchmark is Test {
bytes32 ethBlockHash = ethJson.readBytes32(".blockHash");

// Mock L1Block predeploy for first hop
address l1Block = opC2PProver.l1BlockPredeploy();
address l1Block = opC2PProver.L1_BLOCK_PREDEPLOY();
vm.mockCall(l1Block, abi.encodeWithSignature("hash()"), abi.encode(ethBlockHash));
vm.mockCall(l1Block, abi.encodeWithSignature("number()"), abi.encode(ethBlockNumber));

Expand Down