Commit c66091d3 authored by smartcontracts's avatar smartcontracts Committed by GitHub

fix: use correct chain ID in fault dispute game (#9734)

* fix: use correct chain ID in fault dispute game

Updates the fault dispute game to insert the correct chain ID in
the local preimages. Was previously inserting the L1 chain ID but
needs to be inserting the L2 chain ID or two chains using the same
L1 can't be distinguished from one another.

* fix(ctb): snapshots

---------
Co-authored-by: default avatarrefcell <abigger87@gmail.com>
parent 44201560
This diff is collapsed.
......@@ -1326,7 +1326,8 @@ contract Deploy is Deployer {
_splitDepth: cfg.faultGameSplitDepth(),
_gameDuration: Duration.wrap(uint64(cfg.faultGameMaxDuration())),
_vm: _params.faultVm,
_weth: _params.weth
_weth: _params.weth,
_l2ChainId: cfg.l2ChainID()
})
);
} else {
......@@ -1342,6 +1343,7 @@ contract Deploy is Deployer {
_gameDuration: Duration.wrap(uint64(cfg.faultGameMaxDuration())),
_vm: _params.faultVm,
_weth: _params.weth,
_l2ChainId: cfg.l2ChainID(),
_proposer: cfg.l2OutputOracleProposer(),
_challenger: cfg.l2OutputOracleChallenger()
})
......
......@@ -100,8 +100,8 @@
"sourceCodeHash": "0x1e5a6deded88804971fc1847c9eac65921771bff353437c0b29ed2f55513b984"
},
"src/dispute/FaultDisputeGame.sol": {
"initCodeHash": "0x1db101f0c3613d5e3f7e4f5f73e3f4e50917aef72abd7c28571d9be6cd76e4ad",
"sourceCodeHash": "0x7bea42037f03604a2781c238426af34d46bd85a6520cb884045dd13b33139b34"
"initCodeHash": "0xe78a025dc7e95b4767ec683b0f188565c45cc5f0236e8706fd86d2fddcee59d5",
"sourceCodeHash": "0xb70cd464f9b6f444b489b2cdd6a2d69fd7f14db8eba535b2289974f51061b3c2"
},
"src/dispute/weth/DelayedWETH.sol": {
"initCodeHash": "0x41e274b12dc48658d073dfea67ef694c5cce3963757911ee4cecc9f4c312e4bb",
......
......@@ -45,6 +45,11 @@
"internalType": "contract IDelayedWETH",
"name": "_weth",
"type": "address"
},
{
"internalType": "uint256",
"name": "_l2ChainId",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
......@@ -390,6 +395,19 @@
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [],
"name": "l2ChainId",
"outputs": [
{
"internalType": "uint256",
"name": "l2ChainId_",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "maxGameDepth",
......
......@@ -46,6 +46,11 @@
"name": "_weth",
"type": "address"
},
{
"internalType": "uint256",
"name": "_l2ChainId",
"type": "uint256"
},
{
"internalType": "address",
"name": "_proposer",
......@@ -400,6 +405,19 @@
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [],
"name": "l2ChainId",
"outputs": [
{
"internalType": "uint256",
"name": "l2ChainId_",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "maxGameDepth",
......
......@@ -39,18 +39,21 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
/// @notice An onchain VM that performs single instruction steps on a fault proof program trace.
IBigStepper internal immutable VM;
/// @notice The genesis block number
/// @notice The genesis block number.
uint256 internal immutable GENESIS_BLOCK_NUMBER;
/// @notice The genesis output root
/// @notice The genesis output root.
Hash internal immutable GENESIS_OUTPUT_ROOT;
/// @notice The game type ID
/// @notice The game type ID.
GameType internal immutable GAME_TYPE;
/// @notice WETH contract for holding ETH
/// @notice WETH contract for holding ETH.
IDelayedWETH internal immutable WETH;
/// @notice The chain ID of the L2 network this contract argues about.
uint256 internal immutable L2_CHAIN_ID;
/// @notice The global root claim's position is always at gindex 1.
Position internal constant ROOT_POSITION = Position.wrap(1);
......@@ -97,6 +100,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
/// @param _gameDuration The duration of the game.
/// @param _vm An onchain VM that performs single instruction steps on an FPP trace.
/// @param _weth WETH contract for holding ETH.
/// @param _l2ChainId Chain ID of the L2 network this contract argues about.
constructor(
GameType _gameType,
Claim _absolutePrestate,
......@@ -106,7 +110,8 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
uint256 _splitDepth,
Duration _gameDuration,
IBigStepper _vm,
IDelayedWETH _weth
IDelayedWETH _weth,
uint256 _l2ChainId
) {
// The split depth cannot be greater than or equal to the max game depth.
if (_splitDepth >= _maxGameDepth) revert InvalidSplitDepth();
......@@ -120,6 +125,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
GAME_DURATION = _gameDuration;
VM = _vm;
WETH = _weth;
L2_CHAIN_ID = _l2ChainId;
}
/// @notice Receive function to allow the contract to receive ETH.
......@@ -350,7 +356,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
oracle.loadLocalData(_ident, uuid.raw(), bytes32(l2Number << 0xC0), 8, _partOffset);
} else if (_ident == LocalPreimageKey.CHAIN_ID) {
// Load the chain ID as a big-endian uint64 in the high order 8 bytes of the word.
oracle.loadLocalData(_ident, uuid.raw(), bytes32(block.chainid << 0xC0), 8, _partOffset);
oracle.loadLocalData(_ident, uuid.raw(), bytes32(L2_CHAIN_ID << 0xC0), 8, _partOffset);
} else {
revert InvalidLocalIdent();
}
......@@ -628,6 +634,11 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
weth_ = WETH;
}
/// @notice Returns the chain ID of the L2 network this contract argues about.
function l2ChainId() external view returns (uint256 l2ChainId_) {
l2ChainId_ = L2_CHAIN_ID;
}
////////////////////////////////////////////////////////////////
// HELPERS //
////////////////////////////////////////////////////////////////
......
......@@ -34,8 +34,11 @@ contract PermissionedDisputeGame is FaultDisputeGame {
/// @param _maxGameDepth The maximum depth of bisection.
/// @param _splitDepth The final depth of the output bisection portion of the game.
/// @param _gameDuration The duration of the game.
/// @param _vm An onchain VM that performs single instruction steps on a fault proof program
/// trace.
/// @param _vm An onchain VM that performs single instruction steps on an FPP trace.
/// @param _weth WETH contract for holding ETH.
/// @param _l2ChainId Chain ID of the L2 network this contract argues about.
/// @param _proposer Address that is allowed to create instances of this contract.
/// @param _challenger Address that is allowed to challenge instances of this contract.
constructor(
GameType _gameType,
Claim _absolutePrestate,
......@@ -46,6 +49,7 @@ contract PermissionedDisputeGame is FaultDisputeGame {
Duration _gameDuration,
IBigStepper _vm,
IDelayedWETH _weth,
uint256 _l2ChainId,
address _proposer,
address _challenger
)
......@@ -58,7 +62,8 @@ contract PermissionedDisputeGame is FaultDisputeGame {
_splitDepth,
_gameDuration,
_vm,
_weth
_weth,
_l2ChainId
)
{
PROPOSER = _proposer;
......
......@@ -59,7 +59,8 @@ contract FaultDisputeGame_Init is DisputeGameFactory_Init {
_splitDepth: 2 ** 2,
_gameDuration: Duration.wrap(7 days),
_vm: _vm,
_weth: delayedWeth
_weth: delayedWeth,
_l2ChainId: 10
});
// Register the game implementation with the factory.
disputeGameFactory.setImplementation(GAME_TYPE, gameImpl);
......@@ -133,7 +134,8 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init {
_splitDepth: _splitDepth,
_gameDuration: Duration.wrap(7 days),
_vm: alphabetVM,
_weth: DelayedWETH(payable(address(0)))
_weth: DelayedWETH(payable(address(0))),
_l2ChainId: 10
});
}
......@@ -893,7 +895,7 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init {
startingClaim,
disputedClaim,
bytes32(uint256(1) << 0xC0),
bytes32(block.chainid << 0xC0)
bytes32(gameProxy.l2ChainId() << 0xC0)
];
for (uint256 i = 1; i <= 5; i++) {
......@@ -939,7 +941,7 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init {
startingClaim,
disputedClaim,
bytes32(uint256(2) << 0xC0),
bytes32(block.chainid << 0xC0)
bytes32(gameProxy.l2ChainId() << 0xC0)
];
for (uint256 i = 1; i <= 5; i++) {
......
......@@ -70,6 +70,7 @@ contract PermissionedDisputeGame_Init is DisputeGameFactory_Init {
_gameDuration: Duration.wrap(7 days),
_vm: _vm,
_weth: _weth,
_l2ChainId: 10,
_proposer: PROPOSER,
_challenger: CHALLENGER
});
......
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