Skip to content

Commit

Permalink
hardcode 0xdead as the starting anchor root
Browse files Browse the repository at this point in the history
  • Loading branch information
mds1 committed Sep 20, 2024
1 parent a5bafe7 commit 59d9337
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 31 deletions.
25 changes: 3 additions & 22 deletions op-chain-ops/deployer/pipeline/opchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,10 @@ import (

// PermissionedGameStartingAnchorRoots is an empty anchor root generated by the
// console.log in DeployOpChain.t.sol
// 0x

var PermissionedGameStartingAnchorRoots = []byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xc3, 0x02, 0x67, 0xa0, 0x00, 0xa3, 0xd0, 0x25, 0x7a, 0x64, 0x83, 0xe4,
0x1d, 0x64, 0x97, 0xa4, 0x80, 0xa7, 0x83, 0x96, 0x35, 0xc8, 0x19, 0x34,
0x00, 0x82, 0xcf, 0xe3, 0xe0, 0xda, 0x6e, 0x64, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x4e, 0x03, 0x3a, 0x37, 0x25, 0xd1, 0x5c, 0x61, 0x74, 0xf8, 0x6f, 0x0c,
0xdd, 0x21, 0x0c, 0x84, 0x9a, 0x3f, 0xbd, 0xcb, 0x88, 0xaa, 0x68, 0x2b,
0xf5, 0x1c, 0x61, 0x4b, 0x1e, 0x89, 0x5c, 0x4f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0xf4,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0xd3, 0x26, 0xa8, 0xef, 0x15, 0x96, 0xf3, 0xd8, 0x73, 0x97, 0xc6, 0xc7, 0xb7, 0xb9, 0xda, 0xca, 0xf8, 0x68, 0x5e, 0xd9, 0x7d, 0xdd, 0x31, 0xf0, 0xaa, 0x04, 0x29, 0x4e, 0xaf, 0x9f, 0xca, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x56, 0xd3, 0x26, 0xa8, 0xef, 0x15, 0x96, 0xf3, 0xd8, 0x73, 0x97, 0xc6, 0xc7, 0xb7, 0xb9, 0xda, 0xca, 0xf8, 0x68, 0x5e, 0xd9, 0x7d, 0xdd, 0x31, 0xf0, 0xaa, 0x04, 0x29, 0x4e, 0xaf, 0x9f, 0xca, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}

func DeployOPChain(ctx context.Context, env *Env, intent *state.Intent, st *state.State, chainID common.Hash) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ contract DeployImplementations is Script {
// | Contract | Proxied | Deployment | MCP Ready |
// |-------------------------|---------|-----------------------------------|------------|
// | DisputeGameFactory | Yes | Bespoke | Yes | X
// | AnchorStateRegistry | Yes | Bespoke | No | WIP
// | AnchorStateRegistry | Yes | Bespoke | No | X
// | FaultDisputeGame | No | Bespoke | No | Todo
// | PermissionedDisputeGame | No | Bespoke | No | Todo
// | DelayedWETH | Yes | Two bespoke (one per DisputeGame) | No | Todo: Proxies.
Expand Down
53 changes: 50 additions & 3 deletions packages/contracts-bedrock/scripts/DeployOPChain.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import { Constants } from "src/libraries/Constants.sol";
import { Predeploys } from "src/libraries/Predeploys.sol";

import { ProxyAdmin } from "src/universal/ProxyAdmin.sol";
import { Proxy } from "src/universal/Proxy.sol";

import { AddressManager } from "src/legacy/AddressManager.sol";
import { DelayedWETH } from "src/dispute/DelayedWETH.sol";
import { DisputeGameFactory } from "src/dispute/DisputeGameFactory.sol";
import { AnchorStateRegistry } from "src/dispute/AnchorStateRegistry.sol";
import { FaultDisputeGame } from "src/dispute/FaultDisputeGame.sol";
import { PermissionedDisputeGame } from "src/dispute/PermissionedDisputeGame.sol";
import { GameType, GameTypes, Hash, OutputRoot } from "src/dispute/lib/Types.sol";

import { OPStackManager } from "src/L1/OPStackManager.sol";
import { OptimismPortal2 } from "src/L1/OptimismPortal2.sol";
Expand Down Expand Up @@ -186,7 +188,7 @@ contract DeployOPChainOutput is BaseDeployIO {
require(false, "DeployOPChainOutput: not implemented");
}

function checkOutput(DeployOPChainInput _doi) public view {
function checkOutput(DeployOPChainInput _doi) public {
// With 16 addresses, we'd get a stack too deep error if we tried to do this inline as a
// single call to `Solarray.addresses`. So we split it into two calls.
address[] memory addrs1 = Solarray.addresses(
Expand Down Expand Up @@ -290,7 +292,9 @@ contract DeployOPChainOutput is BaseDeployIO {

// -------- Deployment Assertions --------

function assertValidDeploy(DeployOPChainInput _doi) internal view {
function assertValidDeploy(DeployOPChainInput _doi) internal {
assertValidAnchorStateRegistryProxy(_doi);
assertValidAnchorStateRegistryImpl(_doi);
assertValidDelayedWETHs(_doi);
assertValidDisputeGameFactory(_doi);
assertValidL1CrossDomainMessenger(_doi);
Expand All @@ -303,6 +307,32 @@ contract DeployOPChainOutput is BaseDeployIO {
// TODO add initialization assertions
}

function assertValidAnchorStateRegistryProxy(DeployOPChainInput) internal {
// First we check the proxy as itself.
Proxy proxy = Proxy(payable(address(anchorStateRegistryProxy())));
vm.prank(address(0));
address admin = proxy.admin();
require(admin == address(opChainProxyAdmin()), "ANCHORP-10");

// Then we check the proxy as ASR.
DeployUtils.assertInitialized({ _contractAddress: address(anchorStateRegistryProxy()), _slot: 0, _offset: 0 });

vm.prank(address(0));
address impl = proxy.implementation();
require(impl == address(anchorStateRegistryImpl()), "ANCHORP-20");
require(
address(anchorStateRegistryProxy().disputeGameFactory()) == address(disputeGameFactoryProxy()), "ANCHORP-30"
);
}

function assertValidAnchorStateRegistryImpl(DeployOPChainInput) internal view {
AnchorStateRegistry registry = anchorStateRegistryImpl();

DeployUtils.assertInitialized({ _contractAddress: address(registry), _slot: 0, _offset: 0 });

require(address(registry.disputeGameFactory()) == address(disputeGameFactoryProxy()), "ANCHORI-10");
}

function assertValidSystemConfig(DeployOPChainInput _doi) internal view {
SystemConfig systemConfig = systemConfigProxy();

Expand Down Expand Up @@ -432,6 +462,23 @@ contract DeployOPChain is Script {
function run(DeployOPChainInput _doi, DeployOPChainOutput _doo) public {
OPStackManager opsmProxy = _doi.opsmProxy();

// WARNING: For now always hardcode the starting anchor roots to 0xdead. This is because we
// currently only support deploying straight to permissioned games, and the roots do not
// matter for that, as long as they are non-zero. To update to a permissioned game, we
// will need to update the starting anchor roots. You can
// `console.logBytes(abi.encode(defaultStartingAnchorRoots))` to get the bytes that are hardcoded
// into `op-chain-ops/deployer/pipeline/opchain.go`
AnchorStateRegistry.StartingAnchorRoot[] memory defaultStartingAnchorRoots =
new AnchorStateRegistry.StartingAnchorRoot[](2);
defaultStartingAnchorRoots[0] = AnchorStateRegistry.StartingAnchorRoot({
gameType: GameTypes.CANNON,
outputRoot: OutputRoot({ root: Hash.wrap(keccak256("0xdead")), l2BlockNumber: 0 })
});
defaultStartingAnchorRoots[1] = AnchorStateRegistry.StartingAnchorRoot({
gameType: GameTypes.PERMISSIONED_CANNON,
outputRoot: OutputRoot({ root: Hash.wrap(keccak256("0xdead")), l2BlockNumber: 0 })
});

OPStackManager.Roles memory roles = OPStackManager.Roles({
opChainProxyAdminOwner: _doi.opChainProxyAdminOwner(),
systemConfigOwner: _doi.systemConfigOwner(),
Expand All @@ -445,7 +492,7 @@ contract DeployOPChain is Script {
basefeeScalar: _doi.basefeeScalar(),
blobBasefeeScalar: _doi.blobBaseFeeScalar(),
l2ChainId: _doi.l2ChainId(),
startingAnchorRoots: _doi.startingAnchorRoots()
startingAnchorRoots: abi.encode(defaultStartingAnchorRoots)
});

vm.broadcast(msg.sender);
Expand Down
5 changes: 0 additions & 5 deletions packages/contracts-bedrock/test/DeployOPChain.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import { OptimismMintableERC20Factory } from "src/universal/OptimismMintableERC2

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

import { console2 as console } from "forge-std/console2.sol";

contract DeployOPChainInput_Test is Test {
DeployOPChainInput doi;

Expand Down Expand Up @@ -363,9 +361,6 @@ contract DeployOPChain_TestBase is Test {
})
);

// The output of this line was used to generate the bytes string that I have hardcoded into apply_test.go
console.logBytes(abi.encode(startingAnchorRoots));

// Initialize deploy scripts.
DeploySuperchain deploySuperchain = new DeploySuperchain();
(DeploySuperchainInput dsi, DeploySuperchainOutput dso) = deploySuperchain.etchIOContracts();
Expand Down

0 comments on commit 59d9337

Please sign in to comment.