Skip to content

Commit

Permalink
fix: ASR initializer encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
maurelian committed Sep 19, 2024
1 parent 98c5c10 commit b40bb4a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
6 changes: 0 additions & 6 deletions packages/contracts-bedrock/scripts/DeployOPChain.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,7 @@ contract DeployOPChainInput is BaseDeployIO {
}

function startingAnchorRoots() public view returns (bytes memory) {
// TODO: figure out how to assert this properly.
// Per mofi: It may make sense to not set any startingAnchor roots if you're running permissioned games for a
// new chain and you don't yet have a genesis state available for the initial anchor.
// And provided it'll remain permissioned unless the anchor state is fixed.
require(_startingAnchorRoots.length > 0, "DeployOPChainInput: not set");
// The op-deployer tooling does not support structs, therefore we need to
// return a more generic type for compatibility.
return abi.encode(_startingAnchorRoots);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/semver-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"sourceCodeHash": "0xde4df0f9633dc0cdb1c9f634003ea5b0f7c5c1aebc407bc1b2f44c0ecf938649"
},
"src/L1/OPStackManager.sol": {
"initCodeHash": "0xd43fe2151fbd64ef82d5f785d72fd69e5112b4db08e5e34ec107254056c53aba",
"sourceCodeHash": "0xdb26a154b2607100f9ec29bf20e743cdf393f12d70d5bf193137a42b851e7fca"
"initCodeHash": "0xf624ceae7a4ea10238f63a545dc66a109e84ea5a29a5cc9b682f056e2de7ed93",
"sourceCodeHash": "0x7c4d8311b71759a36651cc3b2daa742571c822f54cfbaa4cdc1d48f5f684d27c"
},
"src/L1/OptimismPortal.sol": {
"initCodeHash": "0xb7a7a28d5b3b88334e7cb4bc1c5fbbf9f691d934e907a2fed6a30e461eb1c0f6",
Expand Down
7 changes: 5 additions & 2 deletions packages/contracts-bedrock/src/L1/OPStackManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ contract OPStackManager is ISemver, Initializable {
uint32 basefeeScalar;
uint32 blobBasefeeScalar;
uint256 l2ChainId;
// The correct type is AnchorStateRegistry.StartingAnchorRoot[] memory,
// but OP Deployer does not yet support structs.
bytes startingAnchorRoots;
}

Expand Down Expand Up @@ -207,7 +209,6 @@ contract OPStackManager is ISemver, Initializable {
// -------- TODO: Placeholders --------
// For contracts we don't yet deploy, we set the outputs to dummy proxies so they have code to pass assertions.
// We do these first, that way the disputeGameFactoryProxy is set when passed to the SystemConfig input.
output.anchorStateRegistryImpl = AnchorStateRegistry(deployProxy(l2ChainId, output.opChainProxyAdmin, "4"));
output.faultDisputeGame = FaultDisputeGame(deployProxy(l2ChainId, output.opChainProxyAdmin, "5"));
output.permissionedDisputeGame = PermissionedDisputeGame(deployProxy(l2ChainId, output.opChainProxyAdmin, "6"));
output.delayedWETHPermissionedGameProxy =
Expand Down Expand Up @@ -479,7 +480,9 @@ contract OPStackManager is ISemver, Initializable {
virtual
returns (bytes memory)
{
return abi.encodeWithSelector(_selector, _input.startingAnchorRoots, superchainConfig);
AnchorStateRegistry.StartingAnchorRoot[] memory startingAnchorRoots =
abi.decode(_input.startingAnchorRoots, (AnchorStateRegistry.StartingAnchorRoot[]));
return abi.encodeWithSelector(_selector, startingAnchorRoots, superchainConfig);
}

/// @notice Returns default, standard config arguments for the SystemConfig initializer.
Expand Down
45 changes: 33 additions & 12 deletions packages/contracts-bedrock/test/DeployOPChain.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { L1ERC721Bridge } from "src/L1/L1ERC721Bridge.sol";
import { L1StandardBridge } from "src/L1/L1StandardBridge.sol";
import { OptimismMintableERC20Factory } from "src/universal/OptimismMintableERC20Factory.sol";

import "src/dispute/lib/Types.sol";
import { GameType, GameTypes, Hash, OutputRoot } from "src/dispute/lib/Types.sol";

contract DeployOPChainInput_Test is Test {
DeployOPChainInput doi;
Expand Down Expand Up @@ -343,10 +343,21 @@ contract DeployOPChain_TestBase is Test {

function setUp() public virtual {
// Set defaults for reference types
uint256 cannonBlock = 400;
uint256 permissionedBlock = 500;
startingAnchorRoots.push(
AnchorStateRegistry.StartingAnchorRoot({
gameType: GameTypes.CANNON,
outputRoot: OutputRoot({ root: Hash.wrap(keccak256("defaultOutputRoot")), l2BlockNumber: 400 })
outputRoot: OutputRoot({ root: Hash.wrap(keccak256("defaultOutputRootCannon")), l2BlockNumber: cannonBlock })
})
);
startingAnchorRoots.push(
AnchorStateRegistry.StartingAnchorRoot({
gameType: GameTypes.PERMISSIONED_CANNON,
outputRoot: OutputRoot({
root: Hash.wrap(keccak256("defaultOutputRootPermissioned")),
l2BlockNumber: permissionedBlock
})
})
);

Expand Down Expand Up @@ -400,7 +411,7 @@ contract DeployOPChain_Test is DeployOPChain_TestBase {
return keccak256(abi.encode(_seed, _i));
}

function testFuzz_run_memory_succeedsX(bytes32 _seed) public {
function testFuzz_run_memory_succeed(bytes32 _seed) public {
opChainProxyAdminOwner = address(uint160(uint256(hash(_seed, 0))));
systemConfigOwner = address(uint160(uint256(hash(_seed, 1))));
batcher = address(uint160(uint256(hash(_seed, 2))));
Expand All @@ -409,16 +420,26 @@ contract DeployOPChain_Test is DeployOPChain_TestBase {
challenger = address(uint160(uint256(hash(_seed, 5))));
basefeeScalar = uint32(uint256(hash(_seed, 6)));
blobBaseFeeScalar = uint32(uint256(hash(_seed, 7)));
l2ChainId = uint256(uint256(hash(_seed, 8)));
uint256 numStartingAnchorRoots = bound(uint256(uint256(hash(_seed, 9))), 1, 10);
for (uint256 i = 0; i < numStartingAnchorRoots; i++) {
startingAnchorRoots.push(
AnchorStateRegistry.StartingAnchorRoot({
gameType: GameTypes.CANNON,
outputRoot: OutputRoot({ root: Hash.wrap(keccak256(abi.encode(_seed, i))), l2BlockNumber: 400 + i })
l2ChainId = uint256(hash(_seed, 8));

// Set the initial anchor states. The typical usage we expect is to pass in one root per game type.
uint256 cannonBlock = uint256(hash(_seed, 9));
uint256 permissionedBlock = uint256(hash(_seed, 10));
startingAnchorRoots.push(
AnchorStateRegistry.StartingAnchorRoot({
gameType: GameTypes.CANNON,
outputRoot: OutputRoot({ root: Hash.wrap(keccak256(abi.encode(_seed, 11))), l2BlockNumber: cannonBlock })
})
);
startingAnchorRoots.push(
AnchorStateRegistry.StartingAnchorRoot({
gameType: GameTypes.PERMISSIONED_CANNON,
outputRoot: OutputRoot({
root: Hash.wrap(keccak256(abi.encode(_seed, 12))),
l2BlockNumber: permissionedBlock
})
);
}
})
);

doi.set(doi.opChainProxyAdminOwner.selector, opChainProxyAdminOwner);
doi.set(doi.systemConfigOwner.selector, systemConfigOwner);
Expand Down

0 comments on commit b40bb4a

Please sign in to comment.