Skip to content

Commit

Permalink
forge fmt (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdehoog authored Oct 23, 2024
1 parent 9fe286e commit 72697dc
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 230 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:
run: |
forge --version
# - name: Run Forge fmt
# run: |
# forge fmt --check
# id: fmt
- name: Run Forge fmt
run: |
forge fmt --check
id: fmt

- name: Run Forge build
run: |
Expand Down
9 changes: 4 additions & 5 deletions script/DeployNitroValidator.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ contract DeployNitroValidator is Script {
console.log("CertManager deployed at:", address(manager));
console.log("NitroValidator deployed at:", address(validator));

string memory deploymentOutfile = string.concat(
vm.projectRoot(), "/deployments/", vm.toString(block.chainid), "-validator.json"
);
vm.writeJson({ json: vm.serializeAddress("", "CertManager", address(manager)), path: deploymentOutfile });
vm.writeJson({ json: vm.serializeAddress("", "NitroValidator", address(validator)), path: deploymentOutfile });
string memory deploymentOutfile =
string.concat(vm.projectRoot(), "/deployments/", vm.toString(block.chainid), "-validator.json");
vm.writeJson({json: vm.serializeAddress("", "CertManager", address(manager)), path: deploymentOutfile});
vm.writeJson({json: vm.serializeAddress("", "NitroValidator", address(validator)), path: deploymentOutfile});

vm.stopBroadcast();
}
Expand Down
103 changes: 44 additions & 59 deletions script/DeploySystem.s.sol
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

import { Deploy } from "@eth-optimism-bedrock/scripts/deploy/Deploy.s.sol";
import { DeployConfig } from "@eth-optimism-bedrock/scripts/deploy/DeployConfig.s.sol";
import { Types } from "@eth-optimism-bedrock/scripts/libraries/Types.sol";
import { ChainAssertions } from "@eth-optimism-bedrock/scripts/deploy/ChainAssertions.sol";
import { SystemConfig } from "@eth-optimism-bedrock/src/L1/SystemConfig.sol";
import { ISystemConfig } from "@eth-optimism-bedrock/src/L1/interfaces/ISystemConfig.sol";
import { ISuperchainConfig } from "@eth-optimism-bedrock/src/L1/interfaces/ISuperchainConfig.sol";
import { SuperchainConfig } from "@eth-optimism-bedrock/src/L1/SuperchainConfig.sol";
import { OptimismPortal } from "@eth-optimism-bedrock/src/L1/OptimismPortal.sol";
import { IL2OutputOracle } from "@eth-optimism-bedrock/src/L1/interfaces/IL2OutputOracle.sol";
import { ProtocolVersions } from "@eth-optimism-bedrock/src/L1/ProtocolVersions.sol";
import { Portal } from "src/Portal.sol";
import { OutputOracle } from "src/OutputOracle.sol";
import { OwnerConfig } from "src/OwnerConfig.sol";
import { SystemConfigOwnable } from "src/SystemConfigOwnable.sol";
import { SystemConfigGlobal } from "src/SystemConfigGlobal.sol";
import { DeployChain } from "src/DeployChain.sol";
import { Constants } from "@eth-optimism-bedrock/src/libraries/Constants.sol";
import { ResourceMetering } from "@eth-optimism-bedrock/src/L1/ResourceMetering.sol";
import { IResourceMetering } from "@eth-optimism-bedrock/src/L1/interfaces/IResourceMetering.sol";
import {Deploy} from "@eth-optimism-bedrock/scripts/deploy/Deploy.s.sol";
import {DeployConfig} from "@eth-optimism-bedrock/scripts/deploy/DeployConfig.s.sol";
import {Types} from "@eth-optimism-bedrock/scripts/libraries/Types.sol";
import {ChainAssertions} from "@eth-optimism-bedrock/scripts/deploy/ChainAssertions.sol";
import {SystemConfig} from "@eth-optimism-bedrock/src/L1/SystemConfig.sol";
import {ISystemConfig} from "@eth-optimism-bedrock/src/L1/interfaces/ISystemConfig.sol";
import {ISuperchainConfig} from "@eth-optimism-bedrock/src/L1/interfaces/ISuperchainConfig.sol";
import {SuperchainConfig} from "@eth-optimism-bedrock/src/L1/SuperchainConfig.sol";
import {OptimismPortal} from "@eth-optimism-bedrock/src/L1/OptimismPortal.sol";
import {IL2OutputOracle} from "@eth-optimism-bedrock/src/L1/interfaces/IL2OutputOracle.sol";
import {ProtocolVersions} from "@eth-optimism-bedrock/src/L1/ProtocolVersions.sol";
import {Portal} from "src/Portal.sol";
import {OutputOracle} from "src/OutputOracle.sol";
import {OwnerConfig} from "src/OwnerConfig.sol";
import {SystemConfigOwnable} from "src/SystemConfigOwnable.sol";
import {SystemConfigGlobal} from "src/SystemConfigGlobal.sol";
import {DeployChain} from "src/DeployChain.sol";
import {Constants} from "@eth-optimism-bedrock/src/libraries/Constants.sol";
import {ResourceMetering} from "@eth-optimism-bedrock/src/L1/ResourceMetering.sol";
import {IResourceMetering} from "@eth-optimism-bedrock/src/L1/interfaces/IResourceMetering.sol";
import "../src/INitroValidator.sol";

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

contract DeploySystem is Deploy {
function deploy() public {
Expand Down Expand Up @@ -121,30 +121,32 @@ contract DeploySystem is Deploy {

function checkNitroValidator() public {
console.log("Retrieving NitroValidator deploy");
string memory deploymentOutfile = string.concat(
vm.projectRoot(), "/deployments/", vm.toString(block.chainid), "-validator.json"
);
string memory deploymentOutfile =
string.concat(vm.projectRoot(), "/deployments/", vm.toString(block.chainid), "-validator.json");
address nitroValidatorAddress = vm.parseJsonAddress(vm.readFile(deploymentOutfile), ".NitroValidator");
save("NitroValidator", nitroValidatorAddress);

INitroValidator validator = INitroValidator(nitroValidatorAddress);
bytes memory attestation = vm.readFileBinary(string.concat(vm.projectRoot(), "/test/nitro-attestation/sample_attestation.bin"));
bytes memory attestation =
vm.readFileBinary(string.concat(vm.projectRoot(), "/test/nitro-attestation/sample_attestation.bin"));

uint256 timestamp = vm.getBlockTimestamp();
vm.warp(1708930774);
(bytes memory enclavePubKey, bytes memory pcr0) = validator.validateAttestation(attestation, 365 days);
vm.warp(timestamp);

vm.assertEq(enclavePubKey, hex"d239fd059dd0e0a01e280bec44903bb8143bae7e578b9844c6df5fd6351eddc0");
vm.assertEq(pcr0, hex"17BF8F048519797BE90497001A7559A3D555395937117D76F8BAAEDF56CA6D97952DE79479BC0C76E5D176D20F663790");
vm.assertEq(
pcr0, hex"17BF8F048519797BE90497001A7559A3D555395937117D76F8BAAEDF56CA6D97952DE79479BC0C76E5D176D20F663790"
);
}

function deploySystemConfigOwnable() public broadcast returns (address addr_) {
console.log("Deploying OwnerConfig");
OwnerConfig ownerConfig = new OwnerConfig{ salt: _implSalt() }(cfg.finalSystemOwner());
OwnerConfig ownerConfig = new OwnerConfig{salt: _implSalt()}(cfg.finalSystemOwner());

console.log("Deploying SystemConfig implementation");
addr_ = address(new SystemConfigOwnable{ salt: _implSalt() }(ownerConfig));
addr_ = address(new SystemConfigOwnable{salt: _implSalt()}(ownerConfig));
save("SystemConfig", addr_);
console.log("SystemConfig deployed at %s", addr_);

Expand All @@ -153,19 +155,19 @@ contract DeploySystem is Deploy {
// are always proxies.
Types.ContractSet memory contracts = _proxiesUnstrict();
contracts.SystemConfig = addr_;
checkSystemConfig({ _contracts: contracts, _cfg: cfg, _isProxy: false });
checkSystemConfig({_contracts: contracts, _cfg: cfg, _isProxy: false});
}

function deploySystemConfigGlobal() public broadcast returns (address addr_) {
console.log("Deploying SystemConfigGlobal implementation");
addr_ = address(new SystemConfigGlobal{ salt: _implSalt() }(INitroValidator(mustGetAddress("NitroValidator"))));
addr_ = address(new SystemConfigGlobal{salt: _implSalt()}(INitroValidator(mustGetAddress("NitroValidator"))));
save("SystemConfigGlobal", addr_);
console.log("SystemConfigGlobal deployed at %s", addr_);
}

function deployPortal() public broadcast returns (address addr_) {
console.log("Deploying OptimismPortal implementation");
addr_ = address(new Portal{ salt: _implSalt() }());
addr_ = address(new Portal{salt: _implSalt()}());
save("OptimismPortal", addr_);
console.log("OptimismPortal deployed at %s", addr_);

Expand All @@ -174,14 +176,14 @@ contract DeploySystem is Deploy {
// are always proxies.
Types.ContractSet memory contracts = _proxiesUnstrict();
contracts.OptimismPortal = addr_;
ChainAssertions.checkOptimismPortal({ _contracts: contracts, _cfg: cfg, _isProxy: false });
ChainAssertions.checkOptimismPortal({_contracts: contracts, _cfg: cfg, _isProxy: false});
}

function deployOutputOracle() public broadcast returns (address addr_) {
SystemConfigGlobal systemConfigGlobal = SystemConfigGlobal(mustGetAddress("SystemConfigGlobalProxy"));

console.log("Deploying L2OutputOracle implementation");
OutputOracle oracle = new OutputOracle{ salt: _implSalt() }(
OutputOracle oracle = new OutputOracle{salt: _implSalt()}(
systemConfigGlobal,
1000 // TODO move to config
);
Expand All @@ -194,18 +196,14 @@ contract DeploySystem is Deploy {
// are always proxies.
Types.ContractSet memory contracts = _proxiesUnstrict();
contracts.L2OutputOracle = address(oracle);
checkL2OutputOracle({
_contracts: contracts,
_cfg: cfg,
_isProxy: false
});
checkL2OutputOracle({_contracts: contracts, _cfg: cfg, _isProxy: false});

addr_ = address(oracle);
}

function deployDeployChain() public broadcast returns (address addr_) {
console.log("Deploying DeployChain implementation");
DeployChain deployChain = new DeployChain{ salt: _implSalt() }({
DeployChain deployChain = new DeployChain{salt: _implSalt()}({
_proxyAdmin: mustGetAddress("ProxyAdmin"),
_optimismPortal: mustGetAddress("OptimismPortalProxy"),
_systemConfig: mustGetAddress("SystemConfigProxy"),
Expand Down Expand Up @@ -262,7 +260,7 @@ contract DeploySystem is Deploy {
string memory version = config.version();
console.log("SystemConfig version: %s", version);

checkSystemConfig({ _contracts: _proxies(), _cfg: cfg, _isProxy: true });
checkSystemConfig({_contracts: _proxies(), _cfg: cfg, _isProxy: true});
}

function initializeSystemConfigGlobal() public broadcast {
Expand Down Expand Up @@ -306,7 +304,7 @@ contract DeploySystem is Deploy {
string memory version = portal.version();
console.log("OptimismPortal version: %s", version);

ChainAssertions.checkOptimismPortal({ _contracts: _proxies(), _cfg: cfg, _isProxy: true });
ChainAssertions.checkOptimismPortal({_contracts: _proxies(), _cfg: cfg, _isProxy: true});
}

function initializeOutputOracle() public broadcast {
Expand All @@ -318,35 +316,22 @@ contract DeploySystem is Deploy {
_upgradeAndCallViaSafe({
_proxy: payable(l2OutputOracleProxy),
_implementation: l2OutputOracle,
_innerCallData: abi.encodeCall(
OutputOracle.initialize, (SystemConfigOwnable(systemConfigProxy), 0, 0)
)
_innerCallData: abi.encodeCall(OutputOracle.initialize, (SystemConfigOwnable(systemConfigProxy), 0, 0))
});

OutputOracle oracle = OutputOracle(l2OutputOracleProxy);
string memory version = oracle.version();
console.log("L2OutputOracle version: %s", version);

checkL2OutputOracle({
_contracts: _proxies(),
_cfg: cfg,
_isProxy: true
});
checkL2OutputOracle({_contracts: _proxies(), _cfg: cfg, _isProxy: true});
}

function checkL2OutputOracle(
Types.ContractSet memory _contracts,
DeployConfig _cfg,
bool _isProxy
)
internal
view
{
function checkL2OutputOracle(Types.ContractSet memory _contracts, DeployConfig _cfg, bool _isProxy) internal view {
console.log("Running chain assertions on the L2OutputOracle");
OutputOracle oracle = OutputOracle(_contracts.L2OutputOracle);

// Check that the contract is initialized
ChainAssertions.assertSlotValueIsOne({ _contractAddress: address(oracle), _slot: 0, _offset: 0 });
ChainAssertions.assertSlotValueIsOne({_contractAddress: address(oracle), _slot: 0, _offset: 0});

if (_isProxy) {
require(oracle.proposer() == _cfg.l2OutputOracleProposer());
Expand All @@ -360,7 +345,7 @@ contract DeploySystem is Deploy {
SystemConfig config = SystemConfig(_contracts.SystemConfig);

// Check that the contract is initialized
ChainAssertions.assertSlotValueIsOne({ _contractAddress: address(config), _slot: 0, _offset: 0 });
ChainAssertions.assertSlotValueIsOne({_contractAddress: address(config), _slot: 0, _offset: 0});

IResourceMetering.ResourceConfig memory resourceConfig = config.resourceConfig();

Expand Down
101 changes: 47 additions & 54 deletions src/DeployChain.sol
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;

import { Portal } from "./Portal.sol";
import { OutputOracle } from "./OutputOracle.sol";
import { SystemConfigOwnable } from "./SystemConfigOwnable.sol";
import { SystemConfig } from "@eth-optimism-bedrock/src/L1/SystemConfig.sol";
import { ISystemConfig } from "@eth-optimism-bedrock/src/L1/interfaces/ISystemConfig.sol";
import { OptimismPortal } from "@eth-optimism-bedrock/src/L1/OptimismPortal.sol";
import { IOptimismPortal } from "@eth-optimism-bedrock/src/L1/interfaces/IOptimismPortal.sol";
import { ISuperchainConfig } from "@eth-optimism-bedrock/src/L1/interfaces/ISuperchainConfig.sol";
import { L2OutputOracle } from "@eth-optimism-bedrock/src/L1/L2OutputOracle.sol";
import { L1StandardBridge } from "@eth-optimism-bedrock/src/L1/L1StandardBridge.sol";
import { L1CrossDomainMessenger } from "@eth-optimism-bedrock/src/L1/L1CrossDomainMessenger.sol";
import { ICrossDomainMessenger } from "@eth-optimism-bedrock/src/universal/interfaces/ICrossDomainMessenger.sol";
import { L1ERC721Bridge } from "@eth-optimism-bedrock/src/L1/L1ERC721Bridge.sol";
import { OptimismMintableERC20Factory } from "@eth-optimism-bedrock/src/universal/OptimismMintableERC20Factory.sol";
import { ResourceMetering } from "@eth-optimism-bedrock/src/L1/ResourceMetering.sol";
import { Hashing } from "@eth-optimism-bedrock/src/libraries/Hashing.sol";
import { Types } from "@eth-optimism-bedrock/src/libraries/Types.sol";
import { Constants } from "@eth-optimism-bedrock/src/libraries/Constants.sol";
import {Portal} from "./Portal.sol";
import {OutputOracle} from "./OutputOracle.sol";
import {SystemConfigOwnable} from "./SystemConfigOwnable.sol";
import {SystemConfig} from "@eth-optimism-bedrock/src/L1/SystemConfig.sol";
import {ISystemConfig} from "@eth-optimism-bedrock/src/L1/interfaces/ISystemConfig.sol";
import {OptimismPortal} from "@eth-optimism-bedrock/src/L1/OptimismPortal.sol";
import {IOptimismPortal} from "@eth-optimism-bedrock/src/L1/interfaces/IOptimismPortal.sol";
import {ISuperchainConfig} from "@eth-optimism-bedrock/src/L1/interfaces/ISuperchainConfig.sol";
import {L2OutputOracle} from "@eth-optimism-bedrock/src/L1/L2OutputOracle.sol";
import {L1StandardBridge} from "@eth-optimism-bedrock/src/L1/L1StandardBridge.sol";
import {L1CrossDomainMessenger} from "@eth-optimism-bedrock/src/L1/L1CrossDomainMessenger.sol";
import {ICrossDomainMessenger} from "@eth-optimism-bedrock/src/universal/interfaces/ICrossDomainMessenger.sol";
import {L1ERC721Bridge} from "@eth-optimism-bedrock/src/L1/L1ERC721Bridge.sol";
import {OptimismMintableERC20Factory} from "@eth-optimism-bedrock/src/universal/OptimismMintableERC20Factory.sol";
import {ResourceMetering} from "@eth-optimism-bedrock/src/L1/ResourceMetering.sol";
import {Hashing} from "@eth-optimism-bedrock/src/libraries/Hashing.sol";
import {Types} from "@eth-optimism-bedrock/src/libraries/Types.sol";
import {Constants} from "@eth-optimism-bedrock/src/libraries/Constants.sol";

contract DeployChain {
struct DeployAddresses {
Expand All @@ -37,14 +37,11 @@ contract DeployChain {
}

event Deploy(
uint256 indexed chainID,
bytes32 configHash,
bytes32 outputRoot,
address batchInbox,
DeployAddresses addresses
uint256 indexed chainID, bytes32 configHash, bytes32 outputRoot, address batchInbox, DeployAddresses addresses
);

bytes32 public constant MESSAGE_PASSER_STORAGE_HASH = 0x8ed4baae3a927be3dea54996b4d5899f8c01e7594bf50b17dc1e741388ce3d12;
bytes32 public constant MESSAGE_PASSER_STORAGE_HASH =
0x8ed4baae3a927be3dea54996b4d5899f8c01e7594bf50b17dc1e741388ce3d12;

address public immutable proxyAdmin;
address public immutable optimismPortal;
Expand Down Expand Up @@ -185,30 +182,31 @@ contract DeployChain {
) internal pure returns (Hashes memory) {
bytes32 scalar = bytes32((uint256(0x01) << 248) | (uint256(blobbasefeeScalar) << 32) | basefeeScalar);

bytes32 configHash = keccak256(abi.encodePacked(
uint64(0), // version
chainID,
genesisL1Hash,
genesisL2Hash,
genesisL2Time,
batcherAddress,
scalar,
gasLimit,
addresses.optimismPortal,
addresses.systemConfig
));
bytes32 configHash = keccak256(
abi.encodePacked(
uint64(0), // version
chainID,
genesisL1Hash,
genesisL2Hash,
genesisL2Time,
batcherAddress,
scalar,
gasLimit,
addresses.optimismPortal,
addresses.systemConfig
)
);

bytes32 genesisOutputRoot = Hashing.hashOutputRootProof(Types.OutputRootProof({
version: 0,
stateRoot: genesisL2StateRoot,
messagePasserStorageRoot: MESSAGE_PASSER_STORAGE_HASH,
latestBlockhash: genesisL2Hash
}));
bytes32 genesisOutputRoot = Hashing.hashOutputRootProof(
Types.OutputRootProof({
version: 0,
stateRoot: genesisL2StateRoot,
messagePasserStorageRoot: MESSAGE_PASSER_STORAGE_HASH,
latestBlockhash: genesisL2Hash
})
);

return Hashes({
configHash: configHash,
genesisOutputRoot: genesisOutputRoot
});
return Hashes({configHash: configHash, genesisOutputRoot: genesisOutputRoot});
}

function initializeProxies(
Expand All @@ -223,9 +221,7 @@ contract DeployChain {
DeployAddresses memory addresses
) internal {
OutputOracle(addresses.l2OutputOracle).initialize(
SystemConfigOwnable(addresses.systemConfig),
hashes.configHash,
hashes.genesisOutputRoot
SystemConfigOwnable(addresses.systemConfig), hashes.configHash, hashes.genesisOutputRoot
);

SystemConfigOwnable(addresses.systemConfig).initialize({
Expand Down Expand Up @@ -267,13 +263,10 @@ contract DeployChain {
);

L1ERC721Bridge(addresses.l1ERC721Bridge).initialize(
ICrossDomainMessenger(addresses.l1CrossDomainMessenger),
ISuperchainConfig(superchainConfig)
ICrossDomainMessenger(addresses.l1CrossDomainMessenger), ISuperchainConfig(superchainConfig)
);

OptimismMintableERC20Factory(addresses.optimismMintableERC20Factory).initialize(
addresses.l1StandardBridge
);
OptimismMintableERC20Factory(addresses.optimismMintableERC20Factory).initialize(addresses.l1StandardBridge);
}

function setupProxy(address proxy, bytes32 salt) internal returns (address instance) {
Expand Down
Loading

0 comments on commit 72697dc

Please sign in to comment.