Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy l2 contracts and use governance for upgrades #441

Merged
merged 14 commits into from
May 14, 2024
19 changes: 9 additions & 10 deletions .github/workflows/l1-contracts-foundry-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,15 @@ jobs:
working-directory: ./l1-contracts-foundry
run: forge script ./script/DeployL1.s.sol --ffi --rpc-url $ANVIL_RPC_URL --broadcast --private-key $ANVIL_PRIVATE_KEY

- name: Run RegisterHyperchain script
working-directory: ./l1-contracts-foundry
run: |
cat ./script-out/output-deploy-l1.toml >> ./script-config/register-hyperchain.toml
forge script ./script/RegisterHyperchain.s.sol --ffi --rpc-url $ANVIL_RPC_URL --broadcast --private-key $ANVIL_PRIVATE_KEY

- name: Run DeployErc20 script
working-directory: ./l1-contracts-foundry
run: forge script ./script/DeployErc20.s.sol --ffi --rpc-url $ANVIL_RPC_URL --broadcast --private-key $ANVIL_PRIVATE_KEY

- name: Run InitializeL2WethToken script
working-directory: ./l1-contracts-foundry
run: forge script ./script/InitializeL2WethToken.s.sol --ffi --rpc-url $ANVIL_RPC_URL --broadcast --private-key $ANVIL_PRIVATE_KEY
# TODO restore scripts verification
# - name: Run RegisterHyperchain script
# working-directory: ./l1-contracts-foundry
# run: |
# cat ./script-out/output-deploy-l1.toml >> ./script-config/register-hyperchain.toml
# forge script ./script/RegisterHyperchain.s.sol --ffi --rpc-url $ANVIL_RPC_URL --broadcast --private-key $ANVIL_PRIVATE_KEY
# - name: Run InitializeL2WethToken script
# working-directory: ./l1-contracts-foundry
# run: forge script ./script/InitializeL2WethToken.s.sol --ffi --rpc-url $ANVIL_RPC_URL --broadcast --private-key $ANVIL_PRIVATE_KEY
7 changes: 4 additions & 3 deletions l1-contracts-foundry/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ remappings = [
]
allow_paths = ["../l1-contracts/contracts", "../l2-contracts/contracts"]
fs_permissions = [
{ access = "read", path = "../system-contracts/bootloader/build/artifacts"},
{ access = "read", path = "../system-contracts/artifacts-zk/contracts-preprocessed"},
{ access = "read", path = "../system-contracts/bootloader/build/artifacts" },
kelemeno marked this conversation as resolved.
Show resolved Hide resolved
{ access = "read", path = "../system-contracts/artifacts-zk/contracts-preprocessed" },
{ access = "read", path = "../l2-contracts/artifacts-zk/" },
{ access = "read", path = "./script-config" },
{ access = "read-write", path = "./script-out" },
{ access = "read", path = "./out" }
]
evm_version="cancun"
evm_version = "cancun"
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
era_chain_id = 9
owner_address = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
testnet_verifier = true

[contracts]
governance_security_council_address = "0x0000000000000000000000000000000000000000"
Expand All @@ -22,6 +23,8 @@ diamond_init_max_pubdata_per_batch = 120000
diamond_init_max_l2_gas_per_batch = 80000000
diamond_init_priority_tx_max_pubdata = 99000
diamond_init_minimal_l2_gas_price = 250000000
bootloader_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
default_aa_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"

[tokens]
token_weth_address = "0x0000000000000000000000000000000000000000"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
chain_id = 215
l1_shared_bridge = "0x2ae37d8130b82c7e79b3863a39027178e073eedb"
bridgehub = "0xea785a9c91a07ed69b83eb165f4ce2c30ecb4c0b"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
chain_id = 215
era_chain_id = 270
l1_shared_bridge = "0x2ae37d8130b82c7e79b3863a39027178e073eedb"
bridgehub = "0xea785a9c91a07ed69b83eb165f4ce2c30ecb4c0b"
governance = "0x6a08d69675af7755569a1a25ef37e795493473a1"
erc20_bridge = "0x84fbda16bd5f2d66d7fbaec5e8d816e7b7014595"
31 changes: 31 additions & 0 deletions l1-contracts-foundry/script/AcceptAdmin.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import {Script} from "forge-std/Script.sol";
import {stdToml} from "forge-std/StdToml.sol";

import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {Utils} from "./Utils.sol";

contract AcceptAdmin is Script {
using stdToml for string;

// This function should be called by the owner to accept the admin role
function run() public {
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script-config/config-accept-admin.toml");
string memory toml = vm.readFile(path);
address admin = toml.readAddress("$.target_addr");
address governor = toml.readAddress("$.governor");
Ownable2Step adminContract = Ownable2Step(admin);

Utils.executeUpgrade({
_governor: governor,
_salt: bytes32(0),
_target: admin,
_data: abi.encodeCall(adminContract.acceptOwnership, ()),
_value: 0,
_delay: 0
});
}
}
23 changes: 18 additions & 5 deletions l1-contracts-foundry/script/DeployL1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transpa
import {Utils} from "./Utils.sol";
import {Multicall3} from "contracts/dev-contracts/Multicall3.sol";
import {Verifier} from "contracts/state-transition/Verifier.sol";
import {TestnetVerifier} from "contracts/state-transition/TestnetVerifier.sol";
import {VerifierParams, IVerifier} from "contracts/state-transition/chain-interfaces/IVerifier.sol";
import {DefaultUpgrade} from "contracts/upgrades/DefaultUpgrade.sol";
import {Governance} from "contracts/governance/Governance.sol";
Expand Down Expand Up @@ -80,6 +81,7 @@ contract DeployL1Script is Script {
uint256 eraChainId;
address deployerAddress;
address ownerAddress;
bool testnetVerifier;
ContractsConfig contracts;
TokensConfig tokens;
}
Expand Down Expand Up @@ -107,6 +109,8 @@ contract DeployL1Script is Script {
uint256 governanceMinDelay;
uint256 maxNumberOfHyperchains;
bytes diamondCutData;
bytes32 bootloaderHash;
bytes32 defaultAAHash;
}

struct TokensConfig {
Expand Down Expand Up @@ -162,6 +166,7 @@ contract DeployL1Script is Script {
// https://book.getfoundry.sh/cheatcodes/parse-toml
config.eraChainId = toml.readUint("$.era_chain_id");
config.ownerAddress = toml.readAddress("$.owner_address");
config.testnetVerifier = toml.readBool("$.testnet_verifier");

config.contracts.governanceSecurityCouncilAddress = toml.readAddress(
"$.contracts.governance_security_council_address"
Expand Down Expand Up @@ -197,6 +202,8 @@ contract DeployL1Script is Script {
"$.contracts.diamond_init_priority_tx_max_pubdata"
);
config.contracts.diamondInitMinimalL2GasPrice = toml.readUint("$.contracts.diamond_init_minimal_l2_gas_price");
config.contracts.defaultAAHash = toml.readBytes32("$.contracts.default_aa_hash");
config.contracts.bootloaderHash = toml.readBytes32("$.contracts.bootloader_hash");

config.tokens.tokenWethAddress = toml.readAddress("$.tokens.token_weth_address");
}
Expand Down Expand Up @@ -236,7 +243,13 @@ contract DeployL1Script is Script {
}

function deployVerifier() internal {
address contractAddress = deployViaCreate2(type(Verifier).creationCode);
bytes memory code;
if (config.testnetVerifier) {
code = type(TestnetVerifier).creationCode;
} else {
code = type(Verifier).creationCode;
}
address contractAddress = deployViaCreate2(code);
console.log("Verifier deployed at:", contractAddress);
addresses.stateTransition.verifier = contractAddress;
}
Expand Down Expand Up @@ -400,8 +413,8 @@ contract DeployL1Script is Script {
DiamondInitializeDataNewChain memory initializeData = DiamondInitializeDataNewChain({
verifier: IVerifier(addresses.stateTransition.verifier),
verifierParams: verifierParams,
l2BootloaderBytecodeHash: bytes32(Utils.getBatchBootloaderBytecodeHash()),
l2DefaultAccountBytecodeHash: bytes32(Utils.readSystemContractsBytecode("DefaultAccount")),
l2BootloaderBytecodeHash: config.contracts.bootloaderHash,
l2DefaultAccountBytecodeHash: config.contracts.defaultAAHash,
priorityTxMaxGasLimit: config.contracts.priorityTxMaxGasLimit,
feeParams: feeParams,
blobVersionedHashRetriever: addresses.blobVersionedHashRetriever
Expand Down Expand Up @@ -467,7 +480,7 @@ contract DeployL1Script is Script {
Diamond.DiamondCutData memory diamondCut = Diamond.DiamondCutData({
facetCuts: facetCuts,
initAddress: address(0),
initCalldata: hex""
initCalldata: ""
});
bytes memory bytecode = abi.encodePacked(
type(DiamondProxy).creationCode,
Expand Down Expand Up @@ -555,7 +568,7 @@ contract DeployL1Script is Script {
validatorTimelock.transferOwnership(config.ownerAddress);

Bridgehub bridgehub = Bridgehub(addresses.bridgehub.bridgehubProxy);
bridgehub.transferOwnership(config.ownerAddress);
bridgehub.transferOwnership(addresses.governance);

L1SharedBridge sharedBridge = L1SharedBridge(addresses.bridges.sharedBridgeProxy);
sharedBridge.transferOwnership(addresses.governance);
Expand Down
60 changes: 60 additions & 0 deletions l1-contracts-foundry/script/DeployPaymaster.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;

import {Script} from "forge-std/Script.sol";
import {stdToml} from "forge-std/StdToml.sol";

import {Utils} from "./Utils.sol";

contract DeployPaymaster is Script {
using stdToml for string;
Config config;

struct Config {
address bridgehubAddress;
address l1SharedBridgeProxy;
uint256 chainId;
address paymaster;
}

function initializeConfig() internal {
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script-config/config-deploy-paymaster.toml");
string memory toml = vm.readFile(path);
config.bridgehubAddress = toml.readAddress("$.bridgehub");
config.l1SharedBridgeProxy = toml.readAddress("$.l1_shared_bridge");
config.chainId = toml.readUint("$.chain_id");
}

function saveOutput() internal {
string memory toml = vm.serializeAddress("root", "paymaster", config.paymaster);
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script-out/output-deploy-paymaster.toml");
vm.writeToml(toml, path);
}

function run() external {
initializeConfig();

deploy();

saveOutput();
}

function deploy() internal {
bytes memory testnetPaymasterBytecode = Utils.readHardhatBytecode(
"/../l2-contracts/artifacts-zk/contracts/TestnetPaymaster.sol/TestnetPaymaster.json"
);

config.paymaster = Utils.deployThroughL1({
bytecode: testnetPaymasterBytecode,
constructorargs: "",
create2salt: "",
l2GasLimit: Utils.MAX_PRIORITY_TX_GAS,
factoryDeps: new bytes[](0),
bridgehubAddress: config.bridgehubAddress,
l1SharedBridgeProxy: config.l1SharedBridgeProxy,
chainId: config.chainId
});
}
}
2 changes: 1 addition & 1 deletion l1-contracts-foundry/script/InitializeL2WethToken.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ contract InitializeL2WethTokenScript is Script {
console.log("L2 WETH token initialized");
}

function getL2Calldata() internal returns (bytes memory) {
function getL2Calldata() internal view returns (bytes memory) {
// Low-level call is performed due to different solidity
// compiler versions between L1 and L2
// solhint-disable-next-line func-named-parameters
Expand Down
Loading
Loading