Commit 41dff4ad authored by clabby's avatar clabby

Add L2OO output root fetching

parent 25876600
This diff is collapsed.
......@@ -85,35 +85,35 @@ 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: 501901)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 508725)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 505444)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 508601)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 507940)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 500666)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 507490)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 504209)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 505366)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 504705)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 502209)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 508989)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 505730)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 508887)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 508226)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 500974)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 507754)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 504495)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 505652)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 504991)
FaultDisputeGame_Test:test_extraData_succeeds() (gas: 17449)
FaultDisputeGame_Test:test_gameData_succeeds() (gas: 17917)
FaultDisputeGame_Test:test_gameData_succeeds() (gas: 17939)
FaultDisputeGame_Test:test_gameStart_succeeds() (gas: 10293)
FaultDisputeGame_Test:test_gameType_succeeds() (gas: 8238)
FaultDisputeGame_Test:test_initialRootClaimData_succeeds() (gas: 17647)
FaultDisputeGame_Test:test_move_clockCorrectness_succeeds() (gas: 419119)
FaultDisputeGame_Test:test_move_clockTimeExceeded_reverts() (gas: 26377)
FaultDisputeGame_Test:test_initialRootClaimData_succeeds() (gas: 17669)
FaultDisputeGame_Test:test_move_clockCorrectness_succeeds() (gas: 419317)
FaultDisputeGame_Test:test_move_clockTimeExceeded_reverts() (gas: 26399)
FaultDisputeGame_Test:test_move_defendRoot_reverts() (gas: 13338)
FaultDisputeGame_Test:test_move_duplicateClaim_reverts() (gas: 104032)
FaultDisputeGame_Test:test_move_gameDepthExceeded_reverts() (gas: 411304)
FaultDisputeGame_Test:test_move_gameNotInProgress_reverts() (gas: 10946)
FaultDisputeGame_Test:test_move_nonExistentParent_reverts() (gas: 24611)
FaultDisputeGame_Test:test_move_simpleAttack_succeeds() (gas: 108112)
FaultDisputeGame_Test:test_resolve_challengeContested_succeeds() (gas: 226468)
FaultDisputeGame_Test:test_move_duplicateClaim_reverts() (gas: 104076)
FaultDisputeGame_Test:test_move_gameDepthExceeded_reverts() (gas: 411414)
FaultDisputeGame_Test:test_move_gameNotInProgress_reverts() (gas: 10968)
FaultDisputeGame_Test:test_move_nonExistentParent_reverts() (gas: 24633)
FaultDisputeGame_Test:test_move_simpleAttack_succeeds() (gas: 108178)
FaultDisputeGame_Test:test_resolve_challengeContested_succeeds() (gas: 226490)
FaultDisputeGame_Test:test_resolve_notInProgress_reverts() (gas: 9702)
FaultDisputeGame_Test:test_resolve_rootContested_succeeds() (gas: 110621)
FaultDisputeGame_Test:test_resolve_rootContested_succeeds() (gas: 110643)
FaultDisputeGame_Test:test_resolve_rootUncontestedClockNotExpired_succeeds() (gas: 21482)
FaultDisputeGame_Test:test_resolve_rootUncontested_succeeds() (gas: 27311)
FaultDisputeGame_Test:test_resolve_teamDeathmatch_succeeds() (gas: 398750)
FaultDisputeGame_Test:test_resolve_teamDeathmatch_succeeds() (gas: 398794)
FaultDisputeGame_Test:test_rootClaim_succeeds() (gas: 8203)
FeeVault_Test:test_constructor_succeeds() (gas: 18185)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 352113)
......
......@@ -698,7 +698,8 @@ contract Deploy is Deployer {
_absolutePrestate: absolutePrestate,
_maxGameDepth: cfg.faultGameMaxDepth(),
_gameDuration: Duration.wrap(uint64(cfg.faultGameMaxDuration())),
_vm: faultVm
_vm: faultVm,
_l2OO: L2OutputOracle(mustGetAddress("L2OutputOracleProxy"))
}));
console.log("DisputeGameFactory: set `FaultDisputeGame` implementation");
}
......
......@@ -36,11 +36,7 @@ library PreimageKeyLib {
/// @notice Computes and returns the key for a global keccak pre-image.
/// @param _preimage The pre-image.
/// @return key_ The pre-image key.
function keccak256PreimageKey(bytes memory _preimage)
internal
pure
returns (bytes32 key_)
{
function keccak256PreimageKey(bytes memory _preimage) internal pure returns (bytes32 key_) {
assembly {
// Grab the size of the `_preimage`
let size := mload(_preimage)
......
......@@ -71,7 +71,11 @@ contract PreimageOracle {
/// │ 4 │ L2 Block Number │
/// │ 5 │ Chain ID │
/// └────────────┴─────────────────┘
function loadLocalData(uint256 _ident, bytes32 _word, uint8 _size) external {
function loadLocalData(
uint256 _ident,
bytes32 _word,
uint8 _size
) external {
// Compute the localized key from the given local identifier.
bytes32 key = PreimageKeyLib.localizeIdent(_ident);
......
......@@ -6,8 +6,10 @@ import { IFaultDisputeGame } from "./interfaces/IFaultDisputeGame.sol";
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 { Clone } from "../libraries/Clone.sol";
import { Types } from "../libraries/Types.sol";
import { Semver } from "../universal/Semver.sol";
import { LibHashing } from "./lib/LibHashing.sol";
import { LibPosition } from "./lib/LibPosition.sol";
......@@ -33,9 +35,12 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
/// @notice The duration of the game.
Duration public immutable GAME_DURATION;
/// @notice A hypervisor that performs single instruction steps on a fault proof program trace.
/// @notice An onchain VM that performs single instruction steps on a fault proof program trace.
IBigStepper public immutable VM;
/// @notice The trusted L2OutputOracle contract.
L2OutputOracle public immutable L2_OUTPUT_ORACLE;
/// @notice The root claim's position is always at gindex 1.
Position internal constant ROOT_POSITION = Position.wrap(1);
......@@ -62,12 +67,14 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
Claim _absolutePrestate,
uint256 _maxGameDepth,
Duration _gameDuration,
IBigStepper _vm
IBigStepper _vm,
L2OutputOracle _l2oo
) Semver(0, 0, 3) {
ABSOLUTE_PRESTATE = _absolutePrestate;
MAX_GAME_DEPTH = _maxGameDepth;
GAME_DURATION = _gameDuration;
VM = _vm;
L2_OUTPUT_ORACLE = _l2oo;
}
////////////////////////////////////////////////////////////////
......@@ -256,7 +263,10 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
} else if (_ident == 2) {
// Load the earliest output root that commits to the passed L2 block number
// into the game's local context in the preimage oracle.
// TODO(clabby): Add an immutable for the L2OO.
Types.OutputProposal memory proposal = L2_OUTPUT_ORACLE.getL2OutputAfter(
l2BlockNumber()
);
oracle.loadLocalData(_ident, proposal.outputRoot, 32);
} else if (_ident == 3) {
// Load the root claim into the game's local context in the preimage oracle.
oracle.loadLocalData(_ident, Claim.unwrap(rootClaim()), 32);
......
......@@ -39,5 +39,9 @@ interface IBigStepper {
/// @notice Temporary interface for the `IPreimageOracle`. Remove once we've upgraded
/// the cannon contracts to a newer version of solc.
interface IPreimageOracle {
function loadLocalData(uint256 _ident, bytes32 _word, uint8 _size) external;
function loadLocalData(
uint256 _ident,
bytes32 _word,
uint8 _size
) external;
}
......@@ -4,8 +4,9 @@ pragma solidity ^0.8.15;
import { Test } from "forge-std/Test.sol";
import { Vm } from "forge-std/Vm.sol";
import { DisputeGameFactory_Init } from "./DisputeGameFactory.t.sol";
import { DisputeGameFactory } from "../src/dispute/DisputeGameFactory.sol";
import { FaultDisputeGame } from "../src/dispute/FaultDisputeGame.sol";
import { DisputeGameFactory } from "../dispute/DisputeGameFactory.sol";
import { FaultDisputeGame } from "../dispute/FaultDisputeGame.sol";
import { L2OutputOracle } from "../L1/L2OutputOracle.sol";
import "../libraries/DisputeTypes.sol";
import "../libraries/DisputeErrors.sol";
......@@ -28,12 +29,14 @@ contract FaultDisputeGame_Init is DisputeGameFactory_Init {
function init(Claim rootClaim, Claim absolutePrestate) public {
super.setUp();
// Deploy an implementation of the fault game
gameImpl = new FaultDisputeGame(
absolutePrestate,
4,
Duration.wrap(7 days),
new AlphabetVM(absolutePrestate)
new AlphabetVM(absolutePrestate),
L2OutputOracle(deployNoop())
);
// Register the game implementation with the factory.
factory.setImplementation(GAME_TYPE, gameImpl);
......@@ -893,12 +896,7 @@ contract AlphabetVM is IBigStepper {
constructor(Claim _absolutePrestate) {
ABSOLUTE_PRESTATE = _absolutePrestate;
// Deploy a noop preimage oracle
assembly {
mstore(0x00, 0x60016000F3)
let size := 5
sstore(oracle.slot, create(0, sub(0x20, size), size))
}
oracle = IPreimageOracle(deployNoop());
}
/// @inheritdoc IBigStepper
......@@ -922,3 +920,16 @@ contract AlphabetVM is IBigStepper {
postState_ = keccak256(abi.encode(traceIndex, claim + 1));
}
}
////////////////////////////////////////////////////////////////
// HELPERS //
////////////////////////////////////////////////////////////////
/// @notice Deploys a noop contract.
function deployNoop() returns (address noop_) {
assembly {
mstore(0x00, 0x60016000F3)
let size := 5
noop_ := create(0, sub(0x20, size), size)
}
}
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