Commit 25876600 authored by clabby's avatar clabby

`FaultDisputeGame` `loadLocalData` func

parent f43e8cd4
This diff is collapsed.
......@@ -381,23 +381,23 @@ func (_PreimageOracle *PreimageOracleTransactorSession) LoadKeccak256PreimagePar
return _PreimageOracle.Contract.LoadKeccak256PreimagePart(&_PreimageOracle.TransactOpts, _partOffset, _preimage)
}
// LoadLocalPart is a paid mutator transaction binding the contract method 0x90fbc1e2.
// LoadLocalData is a paid mutator transaction binding the contract method 0xe52f0937.
//
// Solidity: function loadLocalPart(uint256 _partOffset, uint256 _ident, bytes32 _part, uint256 _size) returns()
func (_PreimageOracle *PreimageOracleTransactor) LoadLocalPart(opts *bind.TransactOpts, _partOffset *big.Int, _ident *big.Int, _part [32]byte, _size *big.Int) (*types.Transaction, error) {
return _PreimageOracle.contract.Transact(opts, "loadLocalPart", _partOffset, _ident, _part, _size)
// Solidity: function loadLocalData(uint256 _ident, bytes32 _word, uint8 _size) returns()
func (_PreimageOracle *PreimageOracleTransactor) LoadLocalData(opts *bind.TransactOpts, _ident *big.Int, _word [32]byte, _size uint8) (*types.Transaction, error) {
return _PreimageOracle.contract.Transact(opts, "loadLocalData", _ident, _word, _size)
}
// LoadLocalPart is a paid mutator transaction binding the contract method 0x90fbc1e2.
// LoadLocalData is a paid mutator transaction binding the contract method 0xe52f0937.
//
// Solidity: function loadLocalPart(uint256 _partOffset, uint256 _ident, bytes32 _part, uint256 _size) returns()
func (_PreimageOracle *PreimageOracleSession) LoadLocalPart(_partOffset *big.Int, _ident *big.Int, _part [32]byte, _size *big.Int) (*types.Transaction, error) {
return _PreimageOracle.Contract.LoadLocalPart(&_PreimageOracle.TransactOpts, _partOffset, _ident, _part, _size)
// Solidity: function loadLocalData(uint256 _ident, bytes32 _word, uint8 _size) returns()
func (_PreimageOracle *PreimageOracleSession) LoadLocalData(_ident *big.Int, _word [32]byte, _size uint8) (*types.Transaction, error) {
return _PreimageOracle.Contract.LoadLocalData(&_PreimageOracle.TransactOpts, _ident, _word, _size)
}
// LoadLocalPart is a paid mutator transaction binding the contract method 0x90fbc1e2.
// LoadLocalData is a paid mutator transaction binding the contract method 0xe52f0937.
//
// Solidity: function loadLocalPart(uint256 _partOffset, uint256 _ident, bytes32 _part, uint256 _size) returns()
func (_PreimageOracle *PreimageOracleTransactorSession) LoadLocalPart(_partOffset *big.Int, _ident *big.Int, _part [32]byte, _size *big.Int) (*types.Transaction, error) {
return _PreimageOracle.Contract.LoadLocalPart(&_PreimageOracle.TransactOpts, _partOffset, _ident, _part, _size)
// Solidity: function loadLocalData(uint256 _ident, bytes32 _word, uint8 _size) returns()
func (_PreimageOracle *PreimageOracleTransactorSession) LoadLocalData(_ident *big.Int, _word [32]byte, _size uint8) (*types.Transaction, error) {
return _PreimageOracle.Contract.LoadLocalData(&_PreimageOracle.TransactOpts, _ident, _word, _size)
}
......@@ -85,36 +85,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: 502252)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 509098)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 505795)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 508974)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 508291)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 501017)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 507863)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 504560)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 505739)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 505056)
FaultDisputeGame_Test:test_extraData_succeeds() (gas: 17404)
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_Test:test_extraData_succeeds() (gas: 17449)
FaultDisputeGame_Test:test_gameData_succeeds() (gas: 17917)
FaultDisputeGame_Test:test_gameStart_succeeds() (gas: 10315)
FaultDisputeGame_Test:test_gameType_succeeds() (gas: 8260)
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: 13360)
FaultDisputeGame_Test:test_move_duplicateClaim_reverts() (gas: 104076)
FaultDisputeGame_Test:test_move_gameDepthExceeded_reverts() (gas: 411436)
FaultDisputeGame_Test:test_move_gameNotInProgress_reverts() (gas: 10968)
FaultDisputeGame_Test:test_move_nonExistentParent_reverts() (gas: 24655)
FaultDisputeGame_Test:test_move_simpleAttack_succeeds() (gas: 108178)
FaultDisputeGame_Test:test_resolve_challengeContested_succeeds() (gas: 226467)
FaultDisputeGame_Test:test_resolve_notInProgress_reverts() (gas: 9657)
FaultDisputeGame_Test:test_resolve_rootContested_succeeds() (gas: 110598)
FaultDisputeGame_Test:test_resolve_rootUncontestedClockNotExpired_succeeds() (gas: 21437)
FaultDisputeGame_Test:test_resolve_rootUncontested_succeeds() (gas: 27266)
FaultDisputeGame_Test:test_resolve_teamDeathmatch_succeeds() (gas: 398793)
FaultDisputeGame_Test:test_rootClaim_succeeds() (gas: 8225)
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_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_resolve_notInProgress_reverts() (gas: 9702)
FaultDisputeGame_Test:test_resolve_rootContested_succeeds() (gas: 110621)
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_rootClaim_succeeds() (gas: 8203)
FeeVault_Test:test_constructor_succeeds() (gas: 18185)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 352113)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_1() (gas: 2950320)
......@@ -575,4 +575,3 @@ TransactorTest:test_constructor_succeeds() (gas: 9739)
TransactorTest:test_delegateCall_succeeds() (gas: 20909)
TransactorTest:test_delegateCall_unauthorized_reverts() (gas: 16550)
TransferOnionTest:test_constructor_succeeds() (gas: 564855)
TransferOnionTest:test_unwrap_succeeds() (gas: 724955)
\ No newline at end of file
......@@ -53,24 +53,49 @@ contract PreimageOracle {
preimageLengths[key] = size;
}
/// @notice Loads a local data part into the preimage oracle.
/// @param _partOffset The offset of the local data part.
/// @notice Loads a word of local data into the preimage oracle in two separate parts.
/// @param _ident The identifier of the local data.
/// @param _part The local data part.
/// @param _size The size of the local data.
/// @dev The local data part is loaded into the preimage oracle under the context
/// @param _word The local data word.
/// @param _size The number of bytes in `_word` to load.
/// @dev The local data parts are loaded into the preimage oracle under the context
/// of the caller - no other account can write to the caller's context
/// specific data.
function loadLocalPart(
uint256 _partOffset,
uint256 _ident,
bytes32 _part,
uint256 _size
) external {
///
/// There are 5 local data identifiers:
/// ┌────────────┬─────────────────┐
/// │ Identifier │ Data │
/// ├────────────┼─────────────────┤
/// │ 1 │ L1 Head Hash │
/// │ 2 │ Output Root │
/// │ 3 │ Root Claim │
/// │ 4 │ L2 Block Number │
/// │ 5 │ Chain ID │
/// └────────────┴─────────────────┘
function loadLocalData(uint256 _ident, bytes32 _word, uint8 _size) external {
// Compute the localized key from the given local identifier.
bytes32 key = PreimageKeyLib.localizeIdent(_ident);
preimagePartOk[key][_partOffset] = true;
preimageParts[key][_partOffset] = _part;
// Load both parts of the local data word into storage for future
// reads.
bytes32 part1;
assembly {
// The first part is prepended with an 8 byte length prefix and contains
// the first 24 bytes of the passed word.
part1 := or(shl(192, _size), shr(64, _word))
}
// Store the first part with offset 0.
preimagePartOk[key][0] = true;
preimageParts[key][0] = part1;
// If the size is greater than 24, we need to store a second part as well.
if (_size > 24) {
bytes32 part2 = _word << 192;
preimagePartOk[key][32] = true;
preimageParts[key][32] = part2;
}
// Assign the length of the preimage at the localized key.
preimageLengths[key] = _size;
}
......
......@@ -5,7 +5,7 @@ import { IDisputeGame } from "./interfaces/IDisputeGame.sol";
import { IFaultDisputeGame } from "./interfaces/IFaultDisputeGame.sol";
import { IInitializable } from "./interfaces/IInitializable.sol";
import { IBondManager } from "./interfaces/IBondManager.sol";
import { IBigStepper } from "./interfaces/IBigStepper.sol";
import { IBigStepper, IPreimageOracle } from "./interfaces/IBigStepper.sol";
import { Clone } from "../libraries/Clone.sol";
import { Semver } from "../universal/Semver.sol";
......@@ -244,6 +244,35 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
move(_parentIndex, _claim, false);
}
/// @inheritdoc IFaultDisputeGame
function addLocalData(uint256 _ident) external {
// INVARIANT: Local data can only be added if the game is currently in progress.
if (status != GameStatus.IN_PROGRESS) revert GameNotInProgress();
IPreimageOracle oracle = VM.oracle();
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);
} 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.
} 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);
} else if (_ident == 4) {
// Load the L2 block number into the game's local context in the preimage oracle.
// The L2 block number is stored as a big-endian uint64 in the upper 8 bytes of the
// passed word.
oracle.loadLocalData(_ident, bytes32(l2BlockNumber() << 192), 8);
} else if (_ident == 5) {
// Load the chain ID into the game's local context in the preimage oracle.
// The chain ID is stored as a big-endian uint64 in the upper 8 bytes of the
// passed word.
oracle.loadLocalData(_ident, bytes32(block.chainid << 192), 8);
}
}
/// @inheritdoc IFaultDisputeGame
function l2BlockNumber() public pure returns (uint256 l2BlockNumber_) {
l2BlockNumber_ = _getArgUint256(0x20);
......
......@@ -39,15 +39,5 @@ interface IBigStepper {
/// @notice Temporary interface for the `IPreimageOracle`. Remove once we've upgraded
/// the cannon contracts to a newer version of solc.
interface IPreimageOracle {
/// @notice Loads a local data part into the preimage oracle.
/// @param _partOffset The offset of the local data part.
/// @param _ident The identifier of the local data.
/// @param _part The local data part.
/// @param _size The size of the local data.
function loadLocalPart(
uint256 _partOffset,
uint256 _ident,
bytes32 _part,
uint256 _size
) external;
function loadLocalData(uint256 _ident, bytes32 _word, uint8 _size) external;
}
......@@ -53,6 +53,10 @@ interface IFaultDisputeGame is IDisputeGame {
bytes calldata _proof
) external;
/// @notice Posts the requested local data to the VM's `PreimageOralce`.
/// @param _ident The local identifier of the data to post.
function addLocalData(uint256 _ident) external;
/// @notice Returns the L1 block hash at the time of the game's creation.
function l1Head() external view returns (Hash l1Head_);
......
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