Commit a0dbcce7 authored by clabby's avatar clabby

Start l1 head loading spike

parent 5bf5f9a8
This diff is collapsed.
This diff is collapsed.
......@@ -16,6 +16,7 @@ AssetReceiverTest:test_withdrawETHwithAmount_unauthorized_reverts() (gas: 10738)
AttestationStationTest:test_attest_bulk_succeeds() (gas: 703740)
AttestationStationTest:test_attest_individual_succeeds() (gas: 632078)
AttestationStationTest:test_attest_single_succeeds() (gas: 651316)
BlockHashOracle_Test:test_load_reverts() (gas: 10436)
Bytes_slice_Test:test_slice_acrossMultipleWords_works() (gas: 9413)
Bytes_slice_Test:test_slice_acrossWords_works() (gas: 1430)
Bytes_slice_Test:test_slice_fromNonZeroIdx_works() (gas: 17240)
......@@ -85,36 +86,36 @@ FaucetTest:test_nonAdmin_drip_fails() (gas: 262520)
FaucetTest:test_receive_succeeds() (gas: 17401)
FaucetTest:test_withdraw_nonAdmin_reverts() (gas: 13145)
FaucetTest:test_withdraw_succeeds() (gas: 78359)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 501957)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 508759)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 505478)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 508657)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 507974)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 500722)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 507524)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 504243)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 505422)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 504739)
FaultDisputeGame_Test:test_extraData_succeeds() (gas: 17404)
FaultDisputeGame_Test:test_gameData_succeeds() (gas: 17939)
FaultDisputeGame_Test:test_gameStart_succeeds() (gas: 10315)
FaultDisputeGame_Test:test_gameType_succeeds() (gas: 8260)
FaultDisputeGame_Test:test_initialRootClaimData_succeeds() (gas: 17624)
FaultDisputeGame_Test:test_move_clockCorrectness_succeeds() (gas: 419180)
FaultDisputeGame_Test:test_move_clockTimeExceeded_reverts() (gas: 26421)
FaultDisputeGame_Test:test_move_defendRoot_reverts() (gas: 13360)
FaultDisputeGame_Test:test_move_duplicateClaim_reverts() (gas: 104120)
FaultDisputeGame_Test:test_move_gameDepthExceeded_reverts() (gas: 411546)
FaultDisputeGame_Test:test_move_gameNotInProgress_reverts() (gas: 11012)
FaultDisputeGame_Test:test_move_nonExistentParent_reverts() (gas: 24677)
FaultDisputeGame_Test:test_move_simpleAttack_succeeds() (gas: 108110)
FaultDisputeGame_Test:test_resolve_challengeContested_succeeds() (gas: 226511)
FaultDisputeGame_Test:test_resolve_notInProgress_reverts() (gas: 9657)
FaultDisputeGame_Test:test_resolve_rootContested_succeeds() (gas: 110642)
FaultDisputeGame_Test:test_resolve_rootUncontestedClockNotExpired_succeeds() (gas: 21437)
FaultDisputeGame_Test:test_resolve_rootUncontested_succeeds() (gas: 27288)
FaultDisputeGame_Test:test_resolve_teamDeathmatch_succeeds() (gas: 398859)
FaultDisputeGame_Test:test_rootClaim_succeeds() (gas: 8225)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 502154)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 508940)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 505653)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 508860)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 508149)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 500919)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 507705)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 504418)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 505625)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 504914)
FaultDisputeGame_Test:test_extraData_succeeds() (gas: 25514)
FaultDisputeGame_Test:test_gameData_succeeds() (gas: 26005)
FaultDisputeGame_Test:test_gameStart_succeeds() (gas: 10299)
FaultDisputeGame_Test:test_gameType_succeeds() (gas: 8288)
FaultDisputeGame_Test:test_initialRootClaimData_succeeds() (gas: 17627)
FaultDisputeGame_Test:test_move_clockCorrectness_succeeds() (gas: 419219)
FaultDisputeGame_Test:test_move_clockTimeExceeded_reverts() (gas: 26427)
FaultDisputeGame_Test:test_move_defendRoot_reverts() (gas: 13344)
FaultDisputeGame_Test:test_move_duplicateClaim_reverts() (gas: 104132)
FaultDisputeGame_Test:test_move_gameDepthExceeded_reverts() (gas: 411559)
FaultDisputeGame_Test:test_move_gameNotInProgress_reverts() (gas: 11046)
FaultDisputeGame_Test:test_move_nonExistentParent_reverts() (gas: 24667)
FaultDisputeGame_Test:test_move_simpleAttack_succeeds() (gas: 108122)
FaultDisputeGame_Test:test_resolve_challengeContested_succeeds() (gas: 226557)
FaultDisputeGame_Test:test_resolve_notInProgress_reverts() (gas: 9685)
FaultDisputeGame_Test:test_resolve_rootContested_succeeds() (gas: 110704)
FaultDisputeGame_Test:test_resolve_rootUncontestedClockNotExpired_succeeds() (gas: 21465)
FaultDisputeGame_Test:test_resolve_rootUncontested_succeeds() (gas: 27344)
FaultDisputeGame_Test:test_resolve_teamDeathmatch_succeeds() (gas: 398895)
FaultDisputeGame_Test:test_rootClaim_succeeds() (gas: 8253)
FeeVault_Test:test_constructor_succeeds() (gas: 18185)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 352113)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_1() (gas: 2950320)
......
......@@ -9,30 +9,28 @@ import { stdJson } from "forge-std/StdJson.sol";
import { Deployer } from "./Deployer.sol";
import { DeployConfig } from "./DeployConfig.s.sol";
import { ProxyAdmin } from "../src/universal/ProxyAdmin.sol";
import { AddressManager } from "../src/legacy/AddressManager.sol";
import { Proxy } from "../src/universal/Proxy.sol";
import { L1StandardBridge } from "../src/L1/L1StandardBridge.sol";
import { OptimismPortal } from "../src/L1/OptimismPortal.sol";
import { L1ChugSplashProxy } from "../src/legacy/L1ChugSplashProxy.sol";
import { ResolvedDelegateProxy } from "../src/legacy/ResolvedDelegateProxy.sol";
import { L1CrossDomainMessenger } from "../src/L1/L1CrossDomainMessenger.sol";
import { L2OutputOracle } from "../src/L1/L2OutputOracle.sol";
import { OptimismMintableERC20Factory } from "../src/universal/OptimismMintableERC20Factory.sol";
import { SystemConfig } from "../src/L1/SystemConfig.sol";
import { ResourceMetering } from "../src/L1/ResourceMetering.sol";
import { Constants } from "../src/libraries/Constants.sol";
import { DisputeGameFactory } from "../src/dispute/DisputeGameFactory.sol";
import { FaultDisputeGame } from "../src/dispute/FaultDisputeGame.sol";
import { PreimageOracle } from "../src/cannon/PreimageOracle.sol";
import { MIPS } from "../src/cannon/MIPS.sol";
import { L1ERC721Bridge } from "../src/L1/L1ERC721Bridge.sol";
import { Predeploys } from "../src/libraries/Predeploys.sol";
import { Chains } from "./Chains.sol";
import { IBigStepper } from "../src/dispute/interfaces/IBigStepper.sol";
import { ProxyAdmin } from "src/universal/ProxyAdmin.sol";
import { AddressManager } from "src/legacy/AddressManager.sol";
import { Proxy } from "src/universal/Proxy.sol";
import { L1StandardBridge } from "src/L1/L1StandardBridge.sol";
import { OptimismPortal } from "src/L1/OptimismPortal.sol";
import { L1ChugSplashProxy } from "src/legacy/L1ChugSplashProxy.sol";
import { ResolvedDelegateProxy } from "src/legacy/ResolvedDelegateProxy.sol";
import { L1CrossDomainMessenger } from "src/L1/L1CrossDomainMessenger.sol";
import { L2OutputOracle } from "src/L1/L2OutputOracle.sol";
import { OptimismMintableERC20Factory } from "src/universal/OptimismMintableERC20Factory.sol";
import { SystemConfig } from "src/L1/SystemConfig.sol";
import { ResourceMetering } from "src/L1/ResourceMetering.sol";
import { Constants } from "src/libraries/Constants.sol";
import { DisputeGameFactory } from "src/dispute/DisputeGameFactory.sol";
import { FaultDisputeGame } from "src/dispute/FaultDisputeGame.sol";
import { BlockHashOracle } from "src/dispute/BlockHashOracle.sol";
import { L1ERC721Bridge } from "src/L1/L1ERC721Bridge.sol";
import { Predeploys } from "src/libraries/Predeploys.sol";
import { IBigStepper } from "src/dispute/interfaces/IBigStepper.sol";
import { AlphabetVM } from "../test/FaultDisputeGame.t.sol";
import "../src/libraries/DisputeTypes.sol";
import "src/libraries/DisputeTypes.sol";
/// @title Deploy
/// @notice Script used to deploy a bedrock system. The entire system is deployed within the `run` function.
......
......@@ -26,4 +26,3 @@
"src/universal/OptimismMintableERC20Factory.sol": "0x1d48aaec29c6732e5d25652a568c4f58a9606656711a14ef98c7cdd5768d9677",
"src/universal/OptimismMintableERC721.sol": "0x72c9c204caddf5a48b6a704621363926714162c2453392b922091d80aa73924f",
"src/universal/OptimismMintableERC721Factory.sol": "0x138d1cecb3c0daa85c73617a1c5d0956544bf65153c13dc11529a71f4b70fb3b"
}
\ No newline at end of file
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import "../libraries/DisputeTypes.sol";
import "../libraries/DisputeErrors.sol";
/// @title BlockHashOracle
/// @notice Stores a map of block numbers => block hashes for use in dispute resolution
contract BlockHashOracle {
/// @notice Maps block numbers to block hashes
mapping(uint256 => Hash) internal blockHashes;
/// @notice Loads a block hash for a given block number, assuming that the block number
/// has been stored in the oracle.
/// @param _blockNumber The block number to load the block hash for.
/// @return blockHash_ The block hash for the given block number.
function load(uint256 _blockNumber) external view returns (Hash blockHash_) {
blockHash_ = blockHashes[_blockNumber];
if (Hash.unwrap(blockHash_) == 0) {
revert BlockHashNotPresent();
}
}
/// @notice Stores a block hash for a given block number, assuming that the block number
/// is within the acceptable range of [tip - 256, tip].
/// @param _blockNumber The block number to persist the block hash for.
function store(uint256 _blockNumber) external {
bytes32 blockHash = blockhash(_blockNumber);
if (blockHash == bytes32(0)) {
revert BlockNumberOOB();
}
blockHashes[_blockNumber] = Hash.wrap(blockHash);
}
}
......@@ -7,6 +7,7 @@ import { IInitializable } from "./interfaces/IInitializable.sol";
import { IBondManager } from "./interfaces/IBondManager.sol";
import { IBigStepper, IPreimageOracle } from "./interfaces/IBigStepper.sol";
import { L2OutputOracle } from "../L1/L2OutputOracle.sol";
import { BlockHashOracle } from "./BlockHashOracle.sol";
import { Clone } from "../libraries/Clone.sol";
import { Types } from "../libraries/Types.sol";
......@@ -41,6 +42,10 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
/// @notice The trusted L2OutputOracle contract.
L2OutputOracle public immutable L2_OUTPUT_ORACLE;
/// @notice The block hash oracle, used for loading block hashes further back
/// than the `BLOCKHASH` opcode allows.
BlockHashOracle public immutable BLOCK_HASH_ORACLE;
/// @notice The root claim's position is always at gindex 1.
Position internal constant ROOT_POSITION = Position.wrap(1);
......@@ -68,19 +73,21 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
/// @param _vm An onchain VM that performs single instruction steps on a fault proof program
/// trace.
/// @param _l2oo The trusted L2OutputOracle contract.
/// @custom:semver 0.0.4
/// @custom:semver 0.0.5
constructor(
Claim _absolutePrestate,
uint256 _maxGameDepth,
Duration _gameDuration,
IBigStepper _vm,
L2OutputOracle _l2oo
) Semver(0, 0, 4) {
L2OutputOracle _l2oo,
BlockHashOracle _blockHashOracle
) Semver(0, 0, 5) {
ABSOLUTE_PRESTATE = _absolutePrestate;
MAX_GAME_DEPTH = _maxGameDepth;
GAME_DURATION = _gameDuration;
VM = _vm;
L2_OUTPUT_ORACLE = _l2oo;
BLOCK_HASH_ORACLE = _blockHashOracle;
}
////////////////////////////////////////////////////////////////
......@@ -294,6 +301,11 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
l2BlockNumber_ = _getArgUint256(0x20);
}
/// @inheritdoc IFaultDisputeGame
function l1BlockNumber() public pure returns (uint256 l1BlockNumber_) {
l1BlockNumber_ = _getArgUint256(0x40);
}
////////////////////////////////////////////////////////////////
// `IDisputeGame` impl //
////////////////////////////////////////////////////////////////
......@@ -384,8 +396,9 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
/// @inheritdoc IDisputeGame
function extraData() public pure returns (bytes memory extraData_) {
// The extra data starts at the second word within the cwia calldata.
extraData_ = _getArgDynBytes(0x20, 0x20);
// The extra data starts at the second word within the cwia calldata and
// is 64 bytes long.
extraData_ = _getArgDynBytes(0x20, 0x40);
}
/// @inheritdoc IDisputeGame
......@@ -425,8 +438,8 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
})
);
// Set the L1 head hash at the time of the game's creation.
l1Head = Hash.wrap(blockhash(block.number - 1));
// Set the L1 head hash to the block hash of the L1 block number provided.
l1Head = BLOCK_HASH_ORACLE.load(_getArgUint256(0x40));
}
/// @notice Returns the length of the `claimData` array.
......
......@@ -63,6 +63,8 @@ interface IFaultDisputeGame is IDisputeGame {
/// @notice The l2BlockNumber that the `rootClaim` commits to. The trace being bisected within
/// the game is from `l2BlockNumber - 1` -> `l2BlockNumber`.
/// @return l2BlockNumber_ The l2BlockNumber that the `rootClaim` commits to.
function l2BlockNumber() external view returns (uint256 l2BlockNumber_);
/// @notice The l1BlockNumber that Cannon was ran from to generate the root claim.
function l1BlockNumber() external view returns (uint256 l1BlockNumber_);
}
......@@ -72,3 +72,14 @@ error AlreadyChallenged();
/// @notice Thrown when a function that is protected by the `onlyOwner` modifier
/// is called from an account other than the owner.
error NotOwner();
////////////////////////////////////////////////////////////////
// `BlockHashOracle.sol` Errors //
////////////////////////////////////////////////////////////////
/// @notice Thrown when a block that is out of the range of the `BLOCKHASH` opcode
/// is attempted to be loaded.
error BlockNumberOOB();
/// @notice Thrown when a block hash is attempted to be loaded that has not been stored.
error BlockHashNotPresent();
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import { Test } from "forge-std/Test.sol";
import { BlockHashOracle } from "src/dispute/BlockHashOracle.sol";
import "src/libraries/DisputeTypes.sol";
import "src/libraries/DisputeErrors.sol";
contract BlockHashOracle_Test is Test {
BlockHashOracle oracle;
function setUp() public {
oracle = new BlockHashOracle();
vm.roll(block.number + 255);
}
/// @notice Tests that loading a block hash for a block number within the range of the
/// `BLOCKHASH` opcode succeeds.
function testFuzz_store_succeeds(uint256 _blockNumber) public {
_blockNumber = bound(_blockNumber, 0, 255);
oracle.store(_blockNumber);
assertEq(Hash.unwrap(oracle.load(_blockNumber)), blockhash(_blockNumber));
}
/// @notice Tests that loading a block hash for a block number outside the range of the
/// `BLOCKHASH` opcode fails.
function testFuzz_store_reverts(uint256 _blockNumber) public {
// Fast forward another 256 blocks.
vm.roll(block.number + 256);
// Bound the block number to the set { 0, ..., 255 } ∪ { 512, ..., type(uint256).max }
_blockNumber = _blockNumber % 2 == 0
? bound(_blockNumber, 0, 255)
: bound(_blockNumber, 512, type(uint256).max);
// Attempt to load the block hash, which should fail.
vm.expectRevert(BlockNumberOOB.selector);
oracle.store(_blockNumber);
}
/// @notice Tests that the `load` function reverts if the block hash for the given block
/// number has not been stored.
function test_load_reverts() public {
vm.expectRevert(BlockHashNotPresent.selector);
oracle.load(0);
}
}
......@@ -7,6 +7,7 @@ import { DisputeGameFactory_Init } from "./DisputeGameFactory.t.sol";
import { DisputeGameFactory } from "src/dispute/DisputeGameFactory.sol";
import { FaultDisputeGame } from "src/dispute/FaultDisputeGame.sol";
import { L2OutputOracle } from "src/L1/L2OutputOracle.sol";
import { BlockHashOracle } from "src/dispute/BlockHashOracle.sol";
import "src/libraries/DisputeTypes.sol";
import "src/libraries/DisputeErrors.sol";
......@@ -16,7 +17,7 @@ import { IBigStepper, IPreimageOracle } from "src/dispute/interfaces/IBigStepper
contract FaultDisputeGame_Init is DisputeGameFactory_Init {
/// @dev The extra data passed to the game for initialization.
bytes internal constant EXTRA_DATA = abi.encode(1);
bytes internal constant EXTRA_DATA = abi.encode(1, 0);
/// @dev The type of the game being tested.
GameType internal constant GAME_TYPE = GameType.wrap(0);
......@@ -30,13 +31,21 @@ contract FaultDisputeGame_Init is DisputeGameFactory_Init {
function init(Claim rootClaim, Claim absolutePrestate) public {
super.setUp();
// Advance the block number by 1.
vm.roll(block.number + 1);
// Deploy a new block hash oracle and store the block hash for the genesis block.
BlockHashOracle blockHashOracle = new BlockHashOracle();
blockHashOracle.store(0);
// Deploy an implementation of the fault game
gameImpl = new FaultDisputeGame(
absolutePrestate,
4,
Duration.wrap(7 days),
new AlphabetVM(absolutePrestate),
L2OutputOracle(deployNoop())
L2OutputOracle(deployNoop()),
blockHashOracle
);
// Register the game implementation with the factory.
factory.setImplementation(GAME_TYPE, gameImpl);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment