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
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/block-hash-pusher"]
path = lib/block-hash-pusher
url = https://github.com/Offchainlabs/block-hash-pusher
[submodule "lib/scroll-contracts"]
path = lib/scroll-contracts
url = https://github.com/scroll-tech/scroll-contracts
Expand Down
3 changes: 0 additions & 3 deletions foundry.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"lib/block-hash-pusher": {
"rev": "085872efb820563b9c50d85732457147523fbe67"
},
"lib/forge-std": {
"rev": "8bbcf6e3f8f62f419e5429a0bd89331c85c37824"
},
Expand Down
1 change: 0 additions & 1 deletion lib/block-hash-pusher
Submodule block-hash-pusher deleted from 085872
1 change: 0 additions & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ forge-std/=lib/forge-std/src/
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
@eth-optimism/=node_modules/@eth-optimism/
@arbitrum/nitro-contracts/=node_modules/@arbitrum/nitro-contracts
block-hash-pusher/=lib/block-hash-pusher/
@scroll-tech/scroll-contracts/=lib/scroll-contracts/src/
@linea-contracts/=lib/linea-monorepo/contracts/src/
10 changes: 5 additions & 5 deletions snapshots/verifyBroadcastMessage.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"EthereumToOptimism": "1642608",
"EthereumToTaikoL2": "1055627",
"EthereumToOptimism": "1639195",
"EthereumToTaikoL2": "1052214",
"LineaL2ToEthereum": "2551776",
"ScrollL2ToEthereum": "1363077",
"ScrollToOptimism": "1349825",
"TaikoL2ToEthereum": "1025690",
"ScrollL2ToEthereum": "1361940",
"ScrollToOptimism": "1348688",
"TaikoL2ToEthereum": "1022277",
"ZkSyncL2ToEthereum": "125479"
}
31 changes: 13 additions & 18 deletions src/contracts/block-hash-pusher/BaseBuffer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,14 @@ abstract contract BaseBuffer is IBuffer {
/// @dev The block number of the newest block in the buffer.
uint256 private _newestBlockNumber;

struct BufferSlot {
uint256 blockNumber;
bytes32 blockHash;
}
/// @dev Mapping of block numbers to block hashes.
mapping(uint256 blockNumber => bytes32 blockHash) private _blockHashes;

BufferSlot[_BUFFER_SIZE] private _buffer;
uint256[_BUFFER_SIZE] private _blockNumberBuffer;

/// @inheritdoc IBuffer
function parentChainBlockHash(uint256 parentChainBlockNumber) external view returns (bytes32) {
BufferSlot storage s = _buffer[parentChainBlockNumber % _BUFFER_SIZE];

if (s.blockNumber != parentChainBlockNumber) {
revert UnknownParentChainBlockHash(parentChainBlockNumber);
}

bytes32 blockHash = s.blockHash;
bytes32 blockHash = _blockHashes[parentChainBlockNumber];
if (blockHash == 0) {
revert UnknownParentChainBlockHash(parentChainBlockNumber);
}
Expand All @@ -54,19 +46,22 @@ abstract contract BaseBuffer is IBuffer {
revert EmptyBlockHashes();
}

// write the hashes to the buffer, evicting old hashes as necessary
// write the hashes to both the mapping and circular buffer
for (uint256 i = 0; i < blockHashesLength; i++) {
uint256 blockNumber = firstBlockNumber + i;
uint256 bufferIndex = blockNumber % _BUFFER_SIZE;
uint256 existingBlockNumber = _blockNumberBuffer[bufferIndex];

BufferSlot storage bufferSlot = _buffer[bufferIndex];
if (blockNumber <= bufferSlot.blockNumber) {
// noop
if (blockNumber <= existingBlockNumber) {
continue;
}

bufferSlot.blockNumber = blockNumber;
bufferSlot.blockHash = blockHashes[i];
if (existingBlockNumber != 0) {
_blockHashes[existingBlockNumber] = 0;
}

_blockHashes[blockNumber] = blockHashes[i];
_blockNumberBuffer[bufferIndex] = blockNumber;
}

uint256 lastBlockNumber = firstBlockNumber + blockHashesLength - 1;
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/provers/arbitrum/ChildToParentProver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.30;

import {ProverUtils} from "../../libraries/ProverUtils.sol";
import {IStateProver} from "../../interfaces/IStateProver.sol";
import {IBuffer} from "block-hash-pusher/contracts/interfaces/IBuffer.sol";
import {IBuffer} from "../../block-hash-pusher/interfaces/IBuffer.sol";
import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol";

/// @notice Arbitrum implementation of a child to parent IStateProver.
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 @@ -3,7 +3,7 @@ pragma solidity 0.8.30;

import {ProverUtils} from "../../libraries/ProverUtils.sol";
import {IStateProver} from "../../interfaces/IStateProver.sol";
import {IBuffer} from "block-hash-pusher/contracts/interfaces/IBuffer.sol";
import {IBuffer} from "../../block-hash-pusher/interfaces/IBuffer.sol";
import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol";

/// @notice Linea implementation of a child to parent IStateProver.
Expand All @@ -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 = 51;
uint256 public constant blockHashMappingSlot = 1;

/// @dev The chain ID of the home chain (child chain).
uint256 public immutable homeChainId;
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 @@ -3,7 +3,7 @@ pragma solidity 0.8.30;

import {ProverUtils} from "../../libraries/ProverUtils.sol";
import {IStateProver} from "../../interfaces/IStateProver.sol";
import {IBuffer} from "block-hash-pusher/contracts/interfaces/IBuffer.sol";
import {IBuffer} from "../../block-hash-pusher/interfaces/IBuffer.sol";
import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol";

/// @notice Scroll implementation of a child to parent IStateProver.
Expand All @@ -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 = 51;
uint256 public constant blockHashMappingSlot = 1;

/// @dev The chain ID of the home chain (child chain).
uint256 public immutable homeChainId;
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 @@ -3,7 +3,7 @@ pragma solidity 0.8.30;

import {ProverUtils} from "../../libraries/ProverUtils.sol";
import {IStateProver} from "../../interfaces/IStateProver.sol";
import {IBuffer} from "block-hash-pusher/contracts/interfaces/IBuffer.sol";
import {IBuffer} from "../../block-hash-pusher/interfaces/IBuffer.sol";
import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol";

/// @notice ZkSync implementation of a child to parent IStateProver.
Expand All @@ -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 = 51;
uint256 public constant blockHashMappingSlot = 1;

/// @dev The chain ID of the home chain (child chain).
uint256 public immutable homeChainId;
Expand Down
2 changes: 1 addition & 1 deletion test/Receiver.ethereum.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {IOutbox} from "@arbitrum/nitro-contracts/src/bridge/IOutbox.sol";
import {IStateProverPointer} from "../src/contracts/interfaces/IStateProverPointer.sol";
import {STATE_PROVER_POINTER_SLOT} from "../src/contracts/StateProverPointer.sol";
import {BlockHeaders} from "./utils/BlockHeaders.sol";
import {IBuffer} from "block-hash-pusher/contracts/interfaces/IBuffer.sol";
import {IBuffer} from "../src/contracts/block-hash-pusher/interfaces/IBuffer.sol";
import {BufferMock} from "./mocks/BufferMock.sol";

import {ChildToParentProver as ArbChildToParentProver} from "../src/contracts/provers/arbitrum/ChildToParentProver.sol";
Expand Down
2 changes: 1 addition & 1 deletion test/Receiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {IOutbox} from "@arbitrum/nitro-contracts/src/bridge/IOutbox.sol";
import {IStateProverPointer} from "../src/contracts/interfaces/IStateProverPointer.sol";
import {STATE_PROVER_POINTER_SLOT} from "../src/contracts/StateProverPointer.sol";
import {BlockHeaders} from "./utils/BlockHeaders.sol";
import {IBuffer} from "block-hash-pusher/contracts/interfaces/IBuffer.sol";
import {IBuffer} from "../src/contracts/block-hash-pusher/interfaces/IBuffer.sol";
import {BufferMock} from "./mocks/BufferMock.sol";

import {ChildToParentProver as ArbChildToParentProver} from "../src/contracts/provers/arbitrum/ChildToParentProver.sol";
Expand Down
30 changes: 4 additions & 26 deletions test/mocks/BufferMock.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;

import {IBuffer} from "block-hash-pusher/contracts/interfaces/IBuffer.sol";
import {IBuffer} from "../../src/contracts/block-hash-pusher/interfaces/IBuffer.sol";

contract BufferMock is IBuffer {
mapping(uint256 => bytes32) public parentChainBlockHash;

uint64 public newestBlockNumber;
uint256 public newestBlockNumber;

function receiveHashes(uint256 firstBlockNumber, bytes32[] memory blockHashes) external {
for (uint256 i = 0; i < blockHashes.length; i++) {
Expand All @@ -16,30 +16,8 @@ contract BufferMock is IBuffer {
newestBlockNumber = uint64(firstBlockNumber + blockHashes.length - 1);
}

function bufferSize() external view returns (uint256) {
return 0;
}

function systemPusher() external view returns (address) {
return address(0);
}

/// @dev The aliased address of the pusher contract on the parent chain.
function aliasedPusher() external view returns (address) {
/// @dev The address of the pusher contract on the parent chain.
function pusher() external view returns (address) {
return address(0);
}

function blockHashMapping(uint256) external view returns (bytes32) {
return bytes32(0);
}

function blockNumberBuffer(uint256) external view returns (uint256) {
return 0;
}

/// @dev Whether the system address has pushed a block hash to the buffer.
/// Once this is set, only the system address can push more hashes.
function systemHasPushed() external view returns (bool) {
return false;
}
}
2 changes: 1 addition & 1 deletion test/provers/arbitrum/ChildToParentProver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {ParentToChildProver} from "../../../src/contracts/provers/arbitrum/Paren
import {IOutbox} from "@arbitrum/nitro-contracts/src/bridge/IOutbox.sol";
import {ChildToParentProver} from "../../../src/contracts/provers/arbitrum/ChildToParentProver.sol";
import {Bytes} from "@openzeppelin/contracts/utils/Bytes.sol";
import {IBuffer} from "block-hash-pusher/contracts/interfaces/IBuffer.sol";
import {IBuffer} from "../../../src/contracts/block-hash-pusher/interfaces/IBuffer.sol";

import {RLP} from "@openzeppelin/contracts/utils/RLP.sol";
import {BlockHeaders} from "../../utils/BlockHeaders.sol";
Expand Down
2 changes: 1 addition & 1 deletion test/provers/linea/ChildToParentProver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {IBroadcaster} from "../../../src/contracts/interfaces/IBroadcaster.sol";
import {IOutbox} from "@arbitrum/nitro-contracts/src/bridge/IOutbox.sol";
import {ChildToParentProver} from "../../../src/contracts/provers/linea/ChildToParentProver.sol";
import {Bytes} from "@openzeppelin/contracts/utils/Bytes.sol";
import {IBuffer} from "block-hash-pusher/contracts/interfaces/IBuffer.sol";
import {IBuffer} from "../../../src/contracts/block-hash-pusher/interfaces/IBuffer.sol";
import {BufferMock} from "../../mocks/BufferMock.sol";
import {RLP} from "@openzeppelin/contracts/utils/RLP.sol";
import {BlockHeaders} from "../../utils/BlockHeaders.sol";
Expand Down
2 changes: 1 addition & 1 deletion test/provers/scroll/ChildToParentProver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {IBroadcaster} from "../../../src/contracts/interfaces/IBroadcaster.sol";
import {IOutbox} from "@arbitrum/nitro-contracts/src/bridge/IOutbox.sol";
import {ChildToParentProver} from "../../../src/contracts/provers/scroll/ChildToParentProver.sol";
import {Bytes} from "@openzeppelin/contracts/utils/Bytes.sol";
import {IBuffer} from "block-hash-pusher/contracts/interfaces/IBuffer.sol";
import {IBuffer} from "../../../src/contracts/block-hash-pusher/interfaces/IBuffer.sol";
import {BufferMock} from "../../mocks/BufferMock.sol";
import {RLP} from "@openzeppelin/contracts/utils/RLP.sol";
import {BlockHeaders} from "../../utils/BlockHeaders.sol";
Expand Down
2 changes: 1 addition & 1 deletion test/provers/zksync/ChildToParentProver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {IBroadcaster} from "../../../src/contracts/interfaces/IBroadcaster.sol";
import {IOutbox} from "@arbitrum/nitro-contracts/src/bridge/IOutbox.sol";
import {ChildToParentProver} from "../../../src/contracts/provers/zksync/ChildToParentProver.sol";
import {Bytes} from "@openzeppelin/contracts/utils/Bytes.sol";
import {IBuffer} from "block-hash-pusher/contracts/interfaces/IBuffer.sol";
import {IBuffer} from "../../../src/contracts/block-hash-pusher/interfaces/IBuffer.sol";
import {BufferMock} from "../../mocks/BufferMock.sol";
import {RLP} from "@openzeppelin/contracts/utils/RLP.sol";
import {BlockHeaders} from "../../utils/BlockHeaders.sol";
Expand Down