Commit 652732fc authored by clabby's avatar clabby

Simplify proposal storage

parent e89bb46d
......@@ -37,7 +37,7 @@ type BlockOracleBlockInfo struct {
// BlockOracleMetaData contains all meta data concerning the BlockOracle contract.
var BlockOracleMetaData = &bind.MetaData{
ABI: "[{\"inputs\":[],\"name\":\"BlockHashNotPresent\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"checkpoint\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"blockNumber_\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_blockNumber\",\"type\":\"uint256\"}],\"name\":\"load\",\"outputs\":[{\"components\":[{\"internalType\":\"Hash\",\"name\":\"hash\",\"type\":\"bytes32\"},{\"internalType\":\"Timestamp\",\"name\":\"childTimestamp\",\"type\":\"uint64\"}],\"internalType\":\"structBlockOracle.BlockInfo\",\"name\":\"blockInfo_\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]",
Bin: "0x608060405234801561001057600080fd5b506101ef806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806399d548aa1461003b578063c2c4c5c114610078575b600080fd5b61004e61004936600461018b565b61008e565b604080518251815260209283015167ffffffffffffffff1692810192909252015b60405180910390f35b61008061010d565b60405190815260200161006f565b604080518082018252600080825260209182018190528381528082528281208351808501909452805480855260019091015467ffffffffffffffff169284019290925203610108576040517f37cf270500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b919050565b6000604051806040016040528060014361012791906101a4565b804082524267ffffffffffffffff908116602093840152600082815280845260409020845181559390920151600190930180547fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000001693909216929092179055919050565b60006020828403121561019d57600080fd5b5035919050565b6000828210156101dd577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b50039056fea164736f6c634300080f000a",
Bin: "0x608060405234801561001057600080fd5b506101e8806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806399d548aa1461003b578063c2c4c5c114610078575b600080fd5b61004e610049366004610184565b61008e565b604080518251815260209283015167ffffffffffffffff1692810192909252015b60405180910390f35b61008061010d565b60405190815260200161006f565b604080518082018252600080825260209182018190528381528082528281208351808501909452805480855260019091015467ffffffffffffffff169284019290925203610108576040517f37cf270500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b919050565b600061011a60014361019d565b604080518082018252824081524267ffffffffffffffff908116602080840191825260008681529081905293909320915182559151600190910180547fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000001691909216179055919050565b60006020828403121561019657600080fd5b5035919050565b6000828210156101d6577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b50039056fea164736f6c634300080f000a",
}
// BlockOracleABI is the input ABI used to generate the binding from.
......
......@@ -13,7 +13,7 @@ const BlockOracleStorageLayoutJSON = "{\"storage\":[{\"astId\":1000,\"contract\"
var BlockOracleStorageLayout = new(solc.StorageLayout)
var BlockOracleDeployedBin = "0x608060405234801561001057600080fd5b50600436106100365760003560e01c806399d548aa1461003b578063c2c4c5c114610078575b600080fd5b61004e61004936600461018b565b61008e565b604080518251815260209283015167ffffffffffffffff1692810192909252015b60405180910390f35b61008061010d565b60405190815260200161006f565b604080518082018252600080825260209182018190528381528082528281208351808501909452805480855260019091015467ffffffffffffffff169284019290925203610108576040517f37cf270500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b919050565b6000604051806040016040528060014361012791906101a4565b804082524267ffffffffffffffff908116602093840152600082815280845260409020845181559390920151600190930180547fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000001693909216929092179055919050565b60006020828403121561019d57600080fd5b5035919050565b6000828210156101dd577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b50039056fea164736f6c634300080f000a"
var BlockOracleDeployedBin = "0x608060405234801561001057600080fd5b50600436106100365760003560e01c806399d548aa1461003b578063c2c4c5c114610078575b600080fd5b61004e610049366004610184565b61008e565b604080518251815260209283015167ffffffffffffffff1692810192909252015b60405180910390f35b61008061010d565b60405190815260200161006f565b604080518082018252600080825260209182018190528381528082528281208351808501909452805480855260019091015467ffffffffffffffff169284019290925203610108576040517f37cf270500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b919050565b600061011a60014361019d565b604080518082018252824081524267ffffffffffffffff908116602080840191825260008681529081905293909320915182559151600190910180547fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000001691909216179055919050565b60006020828403121561019657600080fd5b5035919050565b6000828210156101d6577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b50039056fea164736f6c634300080f000a"
func init() {
if err := json.Unmarshal([]byte(BlockOracleStorageLayoutJSON), BlockOracleStorageLayout); err != nil {
......
This diff is collapsed.
......@@ -73,7 +73,7 @@ func deployDisputeGameContracts(require *require.Assertions, ctx context.Context
big.NewInt(alphabetGameDepth),
gameDuration,
alphaVMAddr,
config.L1Deployments.L2OutputOracle,
config.L1Deployments.L2OutputOracleProxy,
blockHashOracleAddr,
)
require.NoError(err)
......
......@@ -16,7 +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)
BlockOracle_Test:test_checkpointAndLoad_succeeds() (gas: 51477)
BlockOracle_Test:test_checkpointAndLoad_succeeds() (gas: 51465)
BlockOracle_Test:test_load_noBlockHash_reverts() (gas: 12805)
Bytes_slice_Test:test_slice_acrossMultipleWords_works() (gas: 9413)
Bytes_slice_Test:test_slice_acrossWords_works() (gas: 1430)
......@@ -87,37 +87,37 @@ 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: 498866)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 505608)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 502343)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 505550)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 504839)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 497631)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 504373)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 501108)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 502315)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 501604)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 498844)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 505718)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 502387)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 505594)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 504883)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 497609)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 504483)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 501152)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 502359)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 501648)
FaultDisputeGame_Test:test_extraData_succeeds() (gas: 32354)
FaultDisputeGame_Test:test_gameData_succeeds() (gas: 32806)
FaultDisputeGame_Test:test_gameStart_succeeds() (gas: 10410)
FaultDisputeGame_Test:test_gameStart_succeeds() (gas: 10388)
FaultDisputeGame_Test:test_gameType_succeeds() (gas: 8266)
FaultDisputeGame_Test:test_initialize_correctData_succeeds() (gas: 58226)
FaultDisputeGame_Test:test_initialize_correctData_succeeds() (gas: 57716)
FaultDisputeGame_Test:test_initialize_firstOutput_reverts() (gas: 210532)
FaultDisputeGame_Test:test_initialize_l1HeadTooOld_reverts() (gas: 228357)
FaultDisputeGame_Test:test_initialize_l1HeadTooOld_reverts() (gas: 228402)
FaultDisputeGame_Test:test_move_clockCorrectness_succeeds() (gas: 415921)
FaultDisputeGame_Test:test_move_clockTimeExceeded_reverts() (gas: 26428)
FaultDisputeGame_Test:test_move_defendRoot_reverts() (gas: 13322)
FaultDisputeGame_Test:test_move_defendRoot_reverts() (gas: 13388)
FaultDisputeGame_Test:test_move_duplicateClaim_reverts() (gas: 103377)
FaultDisputeGame_Test:test_move_gameDepthExceeded_reverts() (gas: 408316)
FaultDisputeGame_Test:test_move_gameNotInProgress_reverts() (gas: 11046)
FaultDisputeGame_Test:test_move_nonExistentParent_reverts() (gas: 24623)
FaultDisputeGame_Test:test_move_gameDepthExceeded_reverts() (gas: 408294)
FaultDisputeGame_Test:test_move_gameNotInProgress_reverts() (gas: 11024)
FaultDisputeGame_Test:test_move_nonExistentParent_reverts() (gas: 24689)
FaultDisputeGame_Test:test_move_simpleAttack_succeeds() (gas: 107300)
FaultDisputeGame_Test:test_resolve_challengeContested_succeeds() (gas: 224847)
FaultDisputeGame_Test:test_resolve_notInProgress_reverts() (gas: 9686)
FaultDisputeGame_Test:test_resolve_rootContested_succeeds() (gas: 109882)
FaultDisputeGame_Test:test_resolve_rootUncontestedClockNotExpired_succeeds() (gas: 21465)
FaultDisputeGame_Test:test_resolve_rootUncontested_succeeds() (gas: 27322)
FaultDisputeGame_Test:test_resolve_teamDeathmatch_succeeds() (gas: 395519)
FaultDisputeGame_Test:test_resolve_challengeContested_succeeds() (gas: 224869)
FaultDisputeGame_Test:test_resolve_notInProgress_reverts() (gas: 9664)
FaultDisputeGame_Test:test_resolve_rootContested_succeeds() (gas: 109838)
FaultDisputeGame_Test:test_resolve_rootUncontestedClockNotExpired_succeeds() (gas: 21443)
FaultDisputeGame_Test:test_resolve_rootUncontested_succeeds() (gas: 27278)
FaultDisputeGame_Test:test_resolve_teamDeathmatch_succeeds() (gas: 395607)
FaultDisputeGame_Test:test_rootClaim_succeeds() (gas: 8253)
FeeVault_Test:test_constructor_succeeds() (gas: 18185)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 352113)
......
......@@ -32,8 +32,9 @@ contract BlockOracle {
// SAFETY: This block hash will always be accessible by the `BLOCKHASH` opcode,
// and in the case of `block.number = 0`, we'll underflow.
// Persist the block information.
blockNumber_ = block.number - 1;
blocks[blockNumber_] = BlockInfo({
hash: Hash.wrap(blockhash(blockNumber_ = block.number - 1)),
hash: Hash.wrap(blockhash(blockNumber_)),
childTimestamp: Timestamp.wrap(uint64(block.timestamp))
});
}
......
......@@ -67,7 +67,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
/// @notice The starting and disputed output proposal for the game. Includes information about
/// the output indexes in the `L2OutputOracle` and the output roots at the time of
/// game creation.
OutputProposal[2] public proposals;
OutputProposals public proposals;
/// @notice An internal mapping to allow for constant-time lookups of existing claims.
mapping(ClaimHash => bool) internal claims;
......@@ -281,18 +281,21 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
if (_ident == 1) {
// Load the L1 head hash into the game's local context in the preimage oracle.
oracle.loadLocalData(_ident, Hash.unwrap(l1Head), 32, _partOffset);
} else if (_ident < 4) {
// Grab the index of the proposal to load at the given ident.
// Ident 2 loads the starting output root, and ident 3 loads the disputed output root.
uint256 proposal;
assembly {
proposal := iszero(mod(_ident, 2))
}
} else if (_ident == 2) {
// Load the starting or disputed output root into the game's local context in the
// preimage oracle.
oracle.loadLocalData(
_ident,
Hash.unwrap(proposals.starting.outputRoot),
32,
_partOffset
);
} else if (_ident == 3) {
// Load the starting or disputed output root into the game's local context in the
// preimage oracle.
oracle.loadLocalData(
_ident,
Hash.unwrap(proposals[proposal].outputRoot),
Hash.unwrap(proposals.disputed.outputRoot),
32,
_partOffset
);
......@@ -302,7 +305,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
// of the passed word.
oracle.loadLocalData(
_ident,
bytes32(uint256(proposals[0].l2BlockNumber) << 192),
bytes32(uint256(proposals.starting.l2BlockNumber) << 192),
8,
_partOffset
);
......@@ -496,15 +499,17 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
// for loading local data into the preimage oracle as well as to authenticate the game's
// resolution. If the disputed output has changed in the oracle, the game cannot be
// resolved.
proposals[0] = OutputProposal({
index: uint128(proposalIdx - 1),
l2BlockNumber: starting.l2BlockNumber,
outputRoot: Hash.wrap(starting.outputRoot)
});
proposals[1] = OutputProposal({
index: uint128(proposalIdx),
l2BlockNumber: disputed.l2BlockNumber,
outputRoot: Hash.wrap(disputed.outputRoot)
proposals = OutputProposals({
starting: OutputProposal({
index: uint128(proposalIdx - 1),
l2BlockNumber: starting.l2BlockNumber,
outputRoot: Hash.wrap(starting.outputRoot)
}),
disputed: OutputProposal({
index: uint128(proposalIdx),
l2BlockNumber: disputed.l2BlockNumber,
outputRoot: Hash.wrap(disputed.outputRoot)
})
});
// Persist the L1 head hash of the L1 block number provided.
......
......@@ -26,6 +26,12 @@ interface IFaultDisputeGame is IDisputeGame {
Hash outputRoot;
}
/// @notice A container for two consecutive `OutputProposal`s.
struct OutputProposals {
OutputProposal starting;
OutputProposal disputed;
}
/// @notice Emitted when a new claim is added to the DAG by `claimant`
/// @param parentIndex The index within the `claimData` array of the parent claim
/// @param claim The claim being added
......
......@@ -148,17 +148,16 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init {
/// @dev Tests that the game is initialized with the correct data.
function test_initialize_correctData_succeeds() public {
// Starting
(uint128 index, uint128 l2BlockNumber, Hash outputRoot) = gameProxy.proposals(0);
Types.OutputProposal memory starting = oracle.getL2Output(index);
assertEq(index, 0);
assertEq(l2BlockNumber, starting.l2BlockNumber);
assertEq(Hash.unwrap(outputRoot), starting.outputRoot);
(FaultDisputeGame.OutputProposal memory startingProp, FaultDisputeGame.OutputProposal memory disputedProp) = gameProxy.proposals();
Types.OutputProposal memory starting = oracle.getL2Output(startingProp.index);
assertEq(startingProp.index, 0);
assertEq(startingProp.l2BlockNumber, starting.l2BlockNumber);
assertEq(Hash.unwrap(startingProp.outputRoot), starting.outputRoot);
// Disputed
(uint128 _index, uint128 _l2BlockNumber, Hash _outputRoot) = gameProxy.proposals(1);
Types.OutputProposal memory disputed = oracle.getL2Output(_index);
assertEq(_index, 1);
assertEq(_l2BlockNumber, disputed.l2BlockNumber);
assertEq(Hash.unwrap(_outputRoot), disputed.outputRoot);
Types.OutputProposal memory disputed = oracle.getL2Output(disputedProp.index);
assertEq(disputedProp.index, 1);
assertEq(disputedProp.l2BlockNumber, disputed.l2BlockNumber);
assertEq(Hash.unwrap(disputedProp.outputRoot), disputed.outputRoot);
// L1 head
(, uint256 l1HeadNumber) = abi.decode(gameProxy.extraData(), (uint256, uint256));
......
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