diff --git a/ethereum/.env b/ethereum/.env index f3599b2c5..05632684c 100644 --- a/ethereum/.env +++ b/ethereum/.env @@ -2,15 +2,15 @@ CHAIN_ETH_NETWORK=localhost CONTRACTS_PRIORITY_TX_MAX_GAS_LIMIT=72000000 CONTRACTS_DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT=10000000 ETH_CLIENT_WEB3_URL=http://127.0.0.1:8545 -CONTRACTS_BRIDGEHEAD_DIAMOND_PROXY_ADDR=0x0000000000000000000000000000000000000000 -CONTRACTS_BRIDGEHEAD_DIAMOND_INIT_ADDR=0x0000000000000000000000000000000000000000 -CONTRACTS_BRIDGEHEAD_MAILBOX_FACET_ADDR=0x0000000000000000000000000000000000000000 -CONTRACTS_BRIDGEHEAD_REGISTRY_FACET_ADDR=0x0000000000000000000000000000000000000000 -CONTRACTS_BRIDGEHEAD_ADMIN_FACET_ADDR=0x0000000000000000000000000000000000000000 -CONTRACTS_BRIDGEHEAD_GETTERS_FACET_ADDR=0x0000000000000000000000000000000000000000 -CONTRACTS_BRIDGEHEAD_CHAIN_IMPL_ADDR=0x0000000000000000000000000000000000000000 -CONTRACTS_BRIDGEHEAD_CHAIN_PROXY_ADMIN_ADDR=0x0000000000000000000000000000000000000000 -CONTRACTS_BRIDGEHEAD_CHAIN_PROXY_ADDR=0x0000000000000000000000000000000000000000 +CONTRACTS_BRIDGEHUB_DIAMOND_PROXY_ADDR=0x0000000000000000000000000000000000000000 +CONTRACTS_BRIDGEHUB_DIAMOND_INIT_ADDR=0x0000000000000000000000000000000000000000 +CONTRACTS_BRIDGEHUB_MAILBOX_FACET_ADDR=0x0000000000000000000000000000000000000000 +CONTRACTS_BRIDGEHUB_REGISTRY_FACET_ADDR=0x0000000000000000000000000000000000000000 +CONTRACTS_BRIDGEHUB_ADMIN_FACET_ADDR=0x0000000000000000000000000000000000000000 +CONTRACTS_BRIDGEHUB_GETTERS_FACET_ADDR=0x0000000000000000000000000000000000000000 +CONTRACTS_BRIDGEHUB_CHAIN_IMPL_ADDR=0x0000000000000000000000000000000000000000 +CONTRACTS_BRIDGEHUB_CHAIN_PROXY_ADMIN_ADDR=0x0000000000000000000000000000000000000000 +CONTRACTS_BRIDGEHUB_CHAIN_PROXY_ADDR=0x0000000000000000000000000000000000000000 CONTRACTS_PROOF_SYSTEM_PROXY_ADDR=0x0000000000000000000000000000000000000000 CONTRACTS_PROOF_SYSTEM_IMPL_ADDR=0x0000000000000000000000000000000000000000 CONTRACTS_PROOF_SYSTEM_PROXY_ADMIN_ADDR=0x0000000000000000000000000000000000000000 diff --git a/ethereum/contracts/state-transition/StateTransition.sol b/ethereum/contracts/state-transition/StateTransition.sol index 19111de41..2c2e16a91 100644 --- a/ethereum/contracts/state-transition/StateTransition.sol +++ b/ethereum/contracts/state-transition/StateTransition.sol @@ -52,7 +52,6 @@ contract StateTransition is IStateTransition, StateTransitionBase { return proofStorage.governor; } - function getBridgehub() external view returns (address) { return proofStorage.bridgehub; } @@ -106,10 +105,7 @@ contract StateTransition is IStateTransition, StateTransitionBase { cutData.initCalldata = initData; // deploy proofChainContract - DiamondProxy proofChainContract = new DiamondProxy( - block.chainid, - cutData - ); + DiamondProxy proofChainContract = new DiamondProxy(block.chainid, cutData); // save data address proofChainAddress = address(proofChainContract); @@ -123,10 +119,10 @@ contract StateTransition is IStateTransition, StateTransitionBase { // set chainId in VM _specialSetChainIdInVMTx(_chainId, proofChainAddress); - emit NewStateTransitionChain(_chainId, proofChainAddress); + emit StateTransitionNewChain(_chainId, proofChainAddress); } - function setUpgradeDiamondCutWithProposedUpgrade(Diamond.DiamondCutData calldata _cutData) external onlyGovernor { + function setUpgradeDiamondCut(Diamond.DiamondCutData calldata _cutData) external onlyGovernor { proofStorage.upgradeCutHash = keccak256(abi.encode(_cutData)); } diff --git a/ethereum/contracts/state-transition/state-transition-interfaces/IStateTransitionRegistry.sol b/ethereum/contracts/state-transition/state-transition-interfaces/IStateTransitionRegistry.sol index a0781dbd0..2480e099f 100644 --- a/ethereum/contracts/state-transition/state-transition-interfaces/IStateTransitionRegistry.sol +++ b/ethereum/contracts/state-transition/state-transition-interfaces/IStateTransitionRegistry.sol @@ -14,5 +14,5 @@ interface IStateTransitionRegistry { ) external; // when a new Chain is added - event NewStateTransitionChain(uint256 indexed _chainId, address indexed _proofChainContract); + event StateTransitionNewChain(uint256 indexed _chainId, address indexed _proofChainContract); } diff --git a/ethereum/package.json b/ethereum/package.json index a756174f6..8a4208c59 100644 --- a/ethereum/package.json +++ b/ethereum/package.json @@ -85,7 +85,6 @@ "initialize-bridges": "ts-node scripts/initialize-bridges.ts", "initialize-allow-list": "ts-node scripts/initialize-l1-allow-list.ts", "initialize-validator": "ts-node scripts/initialize-validator.ts", - "initialize-verifier-params": "ts-node scripts/initialize-verifier-params.ts", "initialize-governance": "ts-node scripts/initialize-governance.ts", "upgrade-1": "ts-node scripts/upgrades/upgrade-1.ts", "upgrade-2": "ts-node scripts/upgrades/upgrade-2.ts", diff --git a/ethereum/scripts/initialize-bridges.ts b/ethereum/scripts/initialize-bridges.ts index e7a0ae54a..a79d75964 100644 --- a/ethereum/scripts/initialize-bridges.ts +++ b/ethereum/scripts/initialize-bridges.ts @@ -32,7 +32,7 @@ async function initializeBridges( gasPrice: ethers.BigNumber, cmdErc20Bridge: string ) { - const bridgehub = IBridgehubFactory.connect(process.env.CONTRACTS_BRIDGEHEAD_DIAMOND_PROXY_ADDR, deployWallet); + const bridgehub = IBridgehubFactory.connect(process.env.CONTRACTS_BRIDGEHUB_DIAMOND_PROXY_ADDR, deployWallet); const nonce = await deployWallet.getTransactionCount(); const erc20Bridge = cmdErc20Bridge diff --git a/ethereum/scripts/initialize-verifier-params.ts b/ethereum/scripts/initialize-verifier-params.ts deleted file mode 100644 index fb942c080..000000000 --- a/ethereum/scripts/initialize-verifier-params.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { Command } from 'commander'; -import { Wallet } from 'ethers'; -import { Deployer } from '../src.ts/deploy'; -import { formatUnits, parseUnits } from 'ethers/lib/utils'; -import { web3Provider, getHashFromEnv } from './utils'; - -import * as fs from 'fs'; -import * as path from 'path'; - -const provider = web3Provider(); -const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, `etc/test_config/constant`); -const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, { encoding: 'utf-8' })); - -async function main() { - const program = new Command(); - - program - .option('--private-key ') - .option('--chain-id ') - .option('--gas-price ') - .option('--nonce ') - .action(async (cmd) => { - const deployWallet = cmd.privateKey - ? new Wallet(cmd.privateKey, provider) - : Wallet.fromMnemonic( - process.env.MNEMONIC ? process.env.MNEMONIC : ethTestConfig.mnemonic, - "m/44'/60'/0'/0/1" - ).connect(provider); - console.log(`Using deployer wallet: ${deployWallet.address}`); - - const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, 'gwei') : await provider.getGasPrice(); - console.log(`Using gas price: ${formatUnits(gasPrice, 'gwei')} gwei`); - - const nonce = cmd.nonce ? parseInt(cmd.nonce) : await deployWallet.getTransactionCount(); - console.log(`Using nonce: ${nonce}`); - - const deployer = new Deployer({ - deployWallet, - ownerAddress: deployWallet.address, - verbose: true - }); - - const zkSync = deployer.proofSystemContract(deployWallet); - const verifierParams = { - recursionNodeLevelVkHash: getHashFromEnv('CONTRACTS_RECURSION_NODE_LEVEL_VK_HASH'), - recursionLeafLevelVkHash: getHashFromEnv('CONTRACTS_RECURSION_LEAF_LEVEL_VK_HASH'), - recursionCircuitsSetVksHash: getHashFromEnv('CONTRACTS_RECURSION_CIRCUITS_SET_VKS_HASH') - }; - const initialDiamondCut = await deployer.initialStateTransitionProxyDiamondCut(); - - const tx = await zkSync.setParams(verifierParams, initialDiamondCut); - console.log(`Transaction sent with hash ${tx.hash} and nonce ${tx.nonce}`); - const receipt = await tx.wait(); - - console.log(`Verifier Params are set, gasUsed: ${receipt.gasUsed.toString()}`); - }); - - await program.parseAsync(process.argv); -} - -main() - .then(() => process.exit(0)) - .catch((err) => { - console.error('Error:', err); - process.exit(1); - }); diff --git a/ethereum/scripts/upgrades/upgrade-4.ts b/ethereum/scripts/upgrades/upgrade-4.ts index dee7d528e..75252d749 100644 --- a/ethereum/scripts/upgrades/upgrade-4.ts +++ b/ethereum/scripts/upgrades/upgrade-4.ts @@ -115,7 +115,7 @@ async function main() { ownerAddress: ZERO_ADDRESS, verbose: true }); - const zkSyncContract = deployer.proofSystemContract(deployWallet); + const zkSyncContract = deployer.stateTransitionContract(deployWallet); // Get address of the diamond init contract const diamondUpgradeAddress = cmd.diamondUpgradeAddress; diff --git a/ethereum/src.ts/deploy.ts b/ethereum/src.ts/deploy.ts index 9cdac25d6..5cbd267db 100644 --- a/ethereum/src.ts/deploy.ts +++ b/ethereum/src.ts/deploy.ts @@ -82,15 +82,15 @@ export interface DeployerConfig { export function deployedAddressesFromEnv(): DeployedAddresses { return { Bridgehub: { - BridgehubAdminFacet: getAddressFromEnv('CONTRACTS_BRIDGEHEAD_ADMIN_FACET_ADDR'), - BridgehubGettersFacet: getAddressFromEnv('CONTRACTS_BRIDGEHEAD_GETTERS_FACET_ADDR'), - BridgehubMailboxFacet: getAddressFromEnv('CONTRACTS_BRIDGEHEAD_MAILBOX_FACET_ADDR'), - BridgehubRegistryFacet: getAddressFromEnv('CONTRACTS_BRIDGEHEAD_REGISTRY_FACET_ADDR'), - BridgehubDiamondInit: getAddressFromEnv('CONTRACTS_BRIDGEHEAD_DIAMOND_INIT_ADDR'), - BridgehubDiamondProxy: getAddressFromEnv('CONTRACTS_BRIDGEHEAD_DIAMOND_PROXY_ADDR'), - ChainImplementation: getAddressFromEnv('CONTRACTS_BRIDGEHEAD_CHAIN_IMPL_ADDR'), - ChainProxy: getAddressFromEnv('CONTRACTS_BRIDGEHEAD_CHAIN_PROXY_ADDR'), - ChainProxyAdmin: getAddressFromEnv('CONTRACTS_BRIDGEHEAD_CHAIN_PROXY_ADMIN_ADDR') + BridgehubAdminFacet: getAddressFromEnv('CONTRACTS_BRIDGEHUB_ADMIN_FACET_ADDR'), + BridgehubGettersFacet: getAddressFromEnv('CONTRACTS_BRIDGEHUB_GETTERS_FACET_ADDR'), + BridgehubMailboxFacet: getAddressFromEnv('CONTRACTS_BRIDGEHUB_MAILBOX_FACET_ADDR'), + BridgehubRegistryFacet: getAddressFromEnv('CONTRACTS_BRIDGEHUB_REGISTRY_FACET_ADDR'), + BridgehubDiamondInit: getAddressFromEnv('CONTRACTS_BRIDGEHUB_DIAMOND_INIT_ADDR'), + BridgehubDiamondProxy: getAddressFromEnv('CONTRACTS_BRIDGEHUB_DIAMOND_PROXY_ADDR'), + ChainImplementation: getAddressFromEnv('CONTRACTS_BRIDGEHUB_CHAIN_IMPL_ADDR'), + ChainProxy: getAddressFromEnv('CONTRACTS_BRIDGEHUB_CHAIN_PROXY_ADDR'), + ChainProxyAdmin: getAddressFromEnv('CONTRACTS_BRIDGEHUB_CHAIN_PROXY_ADMIN_ADDR') }, StateTransition: { StateTransitionProxy: getAddressFromEnv('CONTRACTS_PROOF_SYSTEM_PROXY_ADDR'), @@ -139,7 +139,7 @@ export class Deployer { this.ownerAddress = config.ownerAddress != null ? config.ownerAddress : this.deployWallet.address; } - public async initialProofChainDiamondCut(extraFacets?: FacetCut[]) { + public async initialStateTransitionChainDiamondCut(extraFacets?: FacetCut[]) { let facetCuts: FacetCut[] = Object.values( await getCurrentFacetCutsForAdd( this.addresses.StateTransition.AdminFacet, @@ -163,7 +163,7 @@ export class Deployer { { chainId: '0x0000000000000000000000000000000000000000000000000000000000000000', bridgehub: '0x0000000000000000000000000000000000001234', - proofSystem: '0x0000000000000000000000000000000000002234', + stateTransition: '0x0000000000000000000000000000000000002234', governor: '0x0000000000000000000000000000000000003234', storedBatchZero: '0x0000000000000000000000000000000000000000000000000000000000000000', allowList: this.addresses.AllowList, @@ -291,13 +291,13 @@ export class Deployer { const implAddress = await hardhat.upgrades.erc1967.getImplementationAddress(instance.address); if (this.verbose) { - console.log(`CONTRACTS_BRIDGEHEAD_CHAIN_IMPL_ADDR=${implAddress}`); + console.log(`CONTRACTS_BRIDGEHUB_CHAIN_IMPL_ADDR=${implAddress}`); } this.addresses.Bridgehub.ChainImplementation = implAddress; if (this.verbose) { - console.log(`CONTRACTS_BRIDGEHEAD_CHAIN_PROXY_ADMIN_ADDR=${adminAddress}`); + console.log(`CONTRACTS_BRIDGEHUB_CHAIN_PROXY_ADMIN_ADDR=${adminAddress}`); } if (this.verbose) { @@ -315,7 +315,7 @@ export class Deployer { const contractAddress = await this.deployViaCreate2('BridgehubAdminFacet', [], create2Salt, ethTxOptions); if (this.verbose) { - console.log(`CONTRACTS_BRIDGEHEAD_ADMIN_FACET_ADDR=${contractAddress}`); + console.log(`CONTRACTS_BRIDGEHUB_ADMIN_FACET_ADDR=${contractAddress}`); } this.addresses.Bridgehub.BridgehubAdminFacet = contractAddress; @@ -326,7 +326,7 @@ export class Deployer { const contractAddress = await this.deployViaCreate2('BridgehubGettersFacet', [], create2Salt, ethTxOptions); if (this.verbose) { - console.log(`CONTRACTS_BRIDGEHEAD_GETTERS_FACET_ADDR=${contractAddress}`); + console.log(`CONTRACTS_BRIDGEHUB_GETTERS_FACET_ADDR=${contractAddress}`); } this.addresses.Bridgehub.BridgehubGettersFacet = contractAddress; @@ -337,7 +337,7 @@ export class Deployer { const contractAddress = await this.deployViaCreate2('BridgehubMailboxFacet', [], create2Salt, ethTxOptions); if (this.verbose) { - console.log(`CONTRACTS_BRIDGEHEAD_MAILBOX_FACET_ADDR=${contractAddress}`); + console.log(`CONTRACTS_BRIDGEHUB_MAILBOX_FACET_ADDR=${contractAddress}`); } this.addresses.Bridgehub.BridgehubMailboxFacet = contractAddress; @@ -348,7 +348,7 @@ export class Deployer { const contractAddress = await this.deployViaCreate2('BridgehubRegistryFacet', [], create2Salt, ethTxOptions); if (this.verbose) { - console.log(`CONTRACTS_BRIDGEHEAD_REGISTRY_FACET_ADDR=${contractAddress}`); + console.log(`CONTRACTS_BRIDGEHUB_REGISTRY_FACET_ADDR=${contractAddress}`); } this.addresses.Bridgehub.BridgehubRegistryFacet = contractAddress; @@ -358,7 +358,7 @@ export class Deployer { const contractAddress = await this.deployViaCreate2('BridgehubDiamondInit', [], create2Salt, ethTxOptions); if (this.verbose) { - console.log(`CONTRACTS_BRIDGEHEAD_DIAMOND_INIT_ADDR=${contractAddress}`); + console.log(`CONTRACTS_BRIDGEHUB_DIAMOND_INIT_ADDR=${contractAddress}`); } this.addresses.Bridgehub.BridgehubDiamondInit = contractAddress; @@ -373,7 +373,7 @@ export class Deployer { const genesisRollupLeafIndex = getNumberFromEnv('CONTRACTS_GENESIS_ROLLUP_LEAF_INDEX'); const genesisBlockCommitment = getHashFromEnv('CONTRACTS_GENESIS_BLOCK_COMMITMENT'); const priorityTxMaxGasLimit = getNumberFromEnv('CONTRACTS_PRIORITY_TX_MAX_GAS_LIMIT'); - const diamondCut = (await this.initialProofChainDiamondCut(extraFacets)) + const diamondCut = (await this.initialStateTransitionChainDiamondCut(extraFacets)) const instance = await hardhat.upgrades.deployProxy(StateTransition, [ { @@ -608,19 +608,19 @@ export class Deployer { // const adminAddress = await hardhat.upgrades.erc1967.getAdminAddress(instance.address); // if (this.verbose) { - // console.log(`CONTRACTS_BRIDGEHEAD_IMPL_ADDR=${implAddress}`); + // console.log(`CONTRACTS_BRIDGEHUB_IMPL_ADDR=${implAddress}`); // } // this.addresses.Bridgehub.BridgehubImplementation = implAddress; // if (this.verbose) { - // console.log(`CONTRACTS_BRIDGEHEAD_PROXY_ADDR=${instance.address}`); + // console.log(`CONTRACTS_BRIDGEHUB_PROXY_ADDR=${instance.address}`); // } // this.addresses.Bridgehub.BridgehubDiamondProxy = instance.address; // if (this.verbose) { - // console.log(`CONTRACTS_BRIDGEHEAD_PROXY_ADMIN_ADDR=${adminAddress}`); + // console.log(`CONTRACTS_BRIDGEHUB_PROXY_ADMIN_ADDR=${adminAddress}`); // } // if (this.verbose) { @@ -644,7 +644,7 @@ export class Deployer { ); if (this.verbose) { - console.log(`CONTRACTS_BRIDGEHEAD_DIAMOND_PROXY_ADDR=${contractAddress}`); + console.log(`CONTRACTS_BRIDGEHUB_DIAMOND_PROXY_ADDR=${contractAddress}`); } this.addresses.Bridgehub.BridgehubDiamondProxy = contractAddress; @@ -706,12 +706,12 @@ export class Deployer { nonce = nonce ? parseInt(nonce) : await this.deployWallet.getTransactionCount(); const bridgehub = this.bridgehubContract(this.deployWallet); - const proofSystem = this.proofSystemContract(this.deployWallet); + const stateTransition = this.stateTransitionContract(this.deployWallet); // const inputChainId = getNumberFromEnv("CHAIN_ETH_ZKSYNC_NETWORK_ID"); const inputChainId = 0; const governor = this.ownerAddress; - const initialDiamondCut = await this.initialProofChainDiamondCut(extraFacets); + const initialDiamondCut = await this.initialStateTransitionChainDiamondCut(extraFacets); const tx = await bridgehub.newChain( inputChainId, @@ -723,7 +723,7 @@ export class Deployer { .topics[1]; nonce ++; - const tx2 = await proofSystem.newChain( + const tx2 = await stateTransition.newChain( chainId, governor, initialDiamondCut, @@ -733,7 +733,7 @@ export class Deployer { const proofContractAddress = '0x' + receipt2.logs - .find((log) => log.topics[0] == proofSystem.interface.getEventTopic('NewProofChain')) + .find((log) => log.topics[0] == stateTransition.interface.getEventTopic('StateTransitionNewChain')) .topics[2].slice(26); this.addresses.StateTransition.DiamondProxy = proofContractAddress; @@ -800,7 +800,7 @@ export class Deployer { return IBridgehubFactory.connect(this.addresses.Bridgehub.BridgehubDiamondProxy, signerOrProvider); } - public proofSystemContract(signerOrProvider: Signer | providers.Provider) { + public stateTransitionContract(signerOrProvider: Signer | providers.Provider) { return IStateTransitionFactory.connect(this.addresses.StateTransition.StateTransitionProxy, signerOrProvider); } diff --git a/ethereum/test/foundry/unit/concrete/Bridgehead/Registry/NewChain.t.sol b/ethereum/test/foundry/unit/concrete/Bridgehead/Registry/NewChain.t.sol index 5a369c27f..975967bcb 100644 --- a/ethereum/test/foundry/unit/concrete/Bridgehead/Registry/NewChain.t.sol +++ b/ethereum/test/foundry/unit/concrete/Bridgehead/Registry/NewChain.t.sol @@ -154,7 +154,11 @@ contract NewChainTest is RegistryTest { assertEq(eventStateTransition, stateTransitionAddress, "NewChain.stateTransition is wrong"); // === Storage checks === - assertEq(bridgehub.getChainStateTransition(chainId), stateTransitionAddress, "saved chainStateTransition is wrong"); + assertEq( + bridgehub.getChainStateTransition(chainId), + stateTransitionAddress, + "saved chainStateTransition is wrong" + ); assertEq(bridgehub.getTotalChains(), 1, "saved totalChains is wrong"); assertEq(bridgehub.getChainContract(chainId), chainContractAddress, "saved chainContract address is wrong"); assertEq(resChainId, chainId, "returned chainId is wrong"); @@ -242,7 +246,11 @@ contract NewChainTest is RegistryTest { assertEq(eventStateTransition, stateTransitionAddress, "NewChain.stateTransition is wrong"); // === Storage checks === - assertEq(bridgehub.getChainStateTransition(chainId), stateTransitionAddress, "saved chainStateTransition is wrong"); + assertEq( + bridgehub.getChainStateTransition(chainId), + stateTransitionAddress, + "saved chainStateTransition is wrong" + ); assertEq(bridgehub.getTotalChains(), 1, "saved totalChains is wrong"); assertEq(bridgehub.getChainContract(chainId), chainContractAddress, "saved chainContract address is wrong"); assertEq(resChainId, chainId, "returned chainId is wrong"); diff --git a/ethereum/test/unit_tests/diamond_proxy_test.spec.ts b/ethereum/test/unit_tests/diamond_proxy_test.spec.ts index 302bd367e..cfdeac804 100644 --- a/ethereum/test/unit_tests/diamond_proxy_test.spec.ts +++ b/ethereum/test/unit_tests/diamond_proxy_test.spec.ts @@ -1,14 +1,17 @@ import { expect } from 'chai'; import * as ethers from 'ethers'; +import { Wallet } from 'ethers'; import * as hardhat from 'hardhat'; import { Action, facetCut, diamondCut, getAllSelectors } from '../../src.ts/diamondCut'; import { - DiamondProxy as DiamondProxy, - DiamondProxyFactory as DiamondProxyFactory, + DiamondProxy, + DiamondProxyFactory, DiamondProxyTest, DiamondProxyTestFactory, AdminFacet, AdminFacetFactory, + AllowList, + GettersFacet, GettersFacetFactory, ExecutorFacet, @@ -17,21 +20,25 @@ import { DiamondInitFactory, TestnetERC20TokenFactory } from '../../typechain'; -import { getCallRevertReason } from './utils'; +import { getCallRevertReason, + ethTestConfig, + initialDeployment } from './utils'; describe('Diamond proxy tests', function () { let proxy: DiamondProxy; let diamondInit: DiamondInit; + let allowList: AllowList; let adminFacet: AdminFacet; let gettersFacet: GettersFacet; let executorFacet: ExecutorFacet; let diamondProxyTest: DiamondProxyTest; let governor: ethers.Signer; + let owner: ethers.Signer; let governorAddress: string; let chainId = process.env.CHAIN_ETH_ZKSYNC_NETWORK_ID || 270; before(async () => { - [governor] = await hardhat.ethers.getSigners(); + [owner, governor] = await hardhat.ethers.getSigners(); governorAddress = await governor.getAddress(); const diamondInitFactory = await hardhat.ethers.getContractFactory('DiamondInit'); @@ -74,7 +81,7 @@ describe('Diamond proxy tests', function () { const diamondInitCalldata = diamondInit.interface.encodeFunctionData('initialize', [{ chainId, bridgehub: '0x0000000000000000000000000000000000000000', - proofSystem: '0x0000000000000000000000000000000000000000', + stateTransition: await owner.getAddress(), governor: governorAddress, storedBatchZero: '0x02c775f0a90abf7a0e8043f2fdc38f0580ca9f9996a895d05a501bfeaa3b2e21', allowList: '0x0000000000000000000000000000000000000000', diff --git a/ethereum/test/unit_tests/governance_test.spec.ts b/ethereum/test/unit_tests/governance_test.spec.ts index f8e5d6441..ceb51060a 100644 --- a/ethereum/test/unit_tests/governance_test.spec.ts +++ b/ethereum/test/unit_tests/governance_test.spec.ts @@ -52,7 +52,7 @@ describe('Admin facet tests', function () { const revertReason = await getCallRevertReason( adminFacetTest.connect(randomSigner).setPorterAvailability(false) ); - expect(revertReason).equal('1g1'); + expect(revertReason).equal('PCBase 1'); }); it('governor successfully set priority transaction max gas limit', async () => { @@ -68,7 +68,7 @@ describe('Admin facet tests', function () { const revertReason = await getCallRevertReason( adminFacetTest.connect(randomSigner).setPriorityTxMaxGasLimit(gasLimit) ); - expect(revertReason).equal('1g1'); + expect(revertReason).equal('PCBase 1'); }); describe('change governor', function () { diff --git a/ethereum/test/unit_tests/l1_erc20_bridge_test.spec.ts b/ethereum/test/unit_tests/l1_erc20_bridge_test.spec.ts index bee88cd40..d2569034a 100644 --- a/ethereum/test/unit_tests/l1_erc20_bridge_test.spec.ts +++ b/ethereum/test/unit_tests/l1_erc20_bridge_test.spec.ts @@ -14,7 +14,7 @@ import { } from '../../typechain'; import { IL1Bridge } from '../../typechain/IL1Bridge'; import { IL1BridgeFactory } from '../../typechain/IL1BridgeFactory'; -import { AccessMode, getCallRevertReason } from './utils'; +import { AccessMode, getCallRevertReason, initialDeployment } from './utils'; import { Deployer } from '../../src.ts/deploy'; @@ -61,78 +61,11 @@ describe(`L1ERC20Bridge tests`, function () { await owner.sendTransaction(tx); - const deployer = new Deployer({ - deployWallet, - ownerAddress, - verbose: false, - addresses: addressConfig, - bootloaderBytecodeHash: L2_BOOTLOADER_BYTECODE_HASH, - defaultAccountBytecodeHash: L2_DEFAULT_ACCOUNT_BYTECODE_HASH - }); + let deployer = await initialDeployment(deployWallet, ownerAddress, gasPrice, []); - const create2Salt = ethers.utils.hexlify(ethers.utils.randomBytes(32)); - - let nonce = await deployWallet.getTransactionCount(); - - await deployer.deployCreate2Factory({ gasPrice, nonce }); - nonce++; - - // await deployer.deployMulticall3(create2Salt, {gasPrice, nonce}); - // nonce++; - - process.env.CONTRACTS_GENESIS_ROOT = zeroHash; - process.env.CONTRACTS_GENESIS_ROLLUP_LEAF_INDEX = '0'; - process.env.CONTRACTS_GENESIS_BLOCK_COMMITMENT = zeroHash; - process.env.CONTRACTS_PRIORITY_TX_MAX_GAS_LIMIT = '72000000'; - process.env.CONTRACTS_RECURSION_NODE_LEVEL_VK_HASH = zeroHash; - process.env.CONTRACTS_RECURSION_LEAF_LEVEL_VK_HASH = zeroHash; - process.env.CONTRACTS_RECURSION_CIRCUITS_SET_VKS_HASH = zeroHash; - - await deployer.deployAllowList(create2Salt, { gasPrice, nonce }); - await deployer.deployBridgehubContract(create2Salt, gasPrice); - await deployer.deployStateTransitionContract(create2Salt,null, gasPrice); - await deployer.deployBridgeContracts(create2Salt, gasPrice); - await deployer.deployWethBridgeContracts(create2Salt, gasPrice); - - const verifierParams = { - recursionNodeLevelVkHash: zeroHash, - recursionLeafLevelVkHash: zeroHash, - recursionCircuitsSetVksHash: zeroHash - }; - // const initialDiamondCut = await deployer.initialStateTransitionProxyDiamondCut(); - - // const proofSystem = deployer.proofSystemContract(deployWallet); - - // await (await proofSystem.setParams(verifierParams, initialDiamondCut)).wait(); - - await deployer.registerHyperchain(create2Salt, null, gasPrice); chainId = deployer.chainId; - - // const validatorTx = await deployer.proofChainContract(deployWallet).setValidator(await validator.getAddress(), true); - // await validatorTx.wait(); - allowList = deployer.l1AllowList(deployWallet); - const allowTx = await allowList.setBatchAccessMode( - [ - deployer.addresses.Bridgehub.BridgehubDiamondProxy, - deployer.addresses.Bridgehub.ChainProxy, - deployer.addresses.StateTransition.StateTransitionProxy, - deployer.addresses.StateTransition.DiamondProxy, - deployer.addresses.Bridges.ERC20BridgeProxy, - deployer.addresses.Bridges.WethBridgeProxy - ], - [ - AccessMode.Public, - AccessMode.Public, - AccessMode.Public, - AccessMode.Public, - AccessMode.Public, - AccessMode.Public - ] - ); - await allowTx.wait(); - bridgehubMailboxFacet = BridgehubMailboxFacetFactory.connect( deployer.addresses.Bridgehub.BridgehubDiamondProxy, deployWallet diff --git a/ethereum/test/unit_tests/l1_weth_bridge_test.spec.ts b/ethereum/test/unit_tests/l1_weth_bridge_test.spec.ts index 7e5733090..077242580 100644 --- a/ethereum/test/unit_tests/l1_weth_bridge_test.spec.ts +++ b/ethereum/test/unit_tests/l1_weth_bridge_test.spec.ts @@ -6,7 +6,7 @@ import * as fs from 'fs'; import { IBridgehub } from '../../typechain/IBridgehub'; import { AllowList, L1WethBridge, L1WethBridgeFactory, WETH9, WETH9Factory } from '../../typechain'; -import { AccessMode, getCallRevertReason } from './utils'; +import { AccessMode, getCallRevertReason, initialDeployment } from './utils'; import { hashL2Bytecode } from '../../scripts/utils'; import { Interface } from 'ethers/lib/utils'; @@ -89,79 +89,11 @@ describe('WETH Bridge tests', () => { await owner.sendTransaction(tx); - const deployer = new Deployer({ - deployWallet, - ownerAddress, - verbose: false, - addresses: addressConfig, - bootloaderBytecodeHash: L2_BOOTLOADER_BYTECODE_HASH, - defaultAccountBytecodeHash: L2_DEFAULT_ACCOUNT_BYTECODE_HASH - }); - - const create2Salt = ethers.utils.hexlify(ethers.utils.randomBytes(32)); - - let nonce = await deployWallet.getTransactionCount(); - - await deployer.deployCreate2Factory({ gasPrice, nonce }); - nonce++; - - // await deployer.deployMulticall3(create2Salt, {gasPrice, nonce}); - // nonce++; - - process.env.CONTRACTS_GENESIS_ROOT = zeroHash; - process.env.CONTRACTS_GENESIS_ROLLUP_LEAF_INDEX = '0'; - process.env.CONTRACTS_GENESIS_BLOCK_COMMITMENT = zeroHash; - process.env.CONTRACTS_PRIORITY_TX_MAX_GAS_LIMIT = '72000000'; - process.env.CONTRACTS_RECURSION_NODE_LEVEL_VK_HASH = zeroHash; - process.env.CONTRACTS_RECURSION_LEAF_LEVEL_VK_HASH = zeroHash; - process.env.CONTRACTS_RECURSION_CIRCUITS_SET_VKS_HASH = zeroHash; - - await deployer.deployAllowList(create2Salt, { gasPrice, nonce }); - await deployer.deployBridgehubContract(create2Salt, gasPrice); - await deployer.deployStateTransitionContract(create2Salt,null, gasPrice); - await deployer.deployBridgeContracts(create2Salt, gasPrice); - await deployer.deployWethBridgeContracts(create2Salt, gasPrice); - - const verifierParams = { - recursionNodeLevelVkHash: zeroHash, - recursionLeafLevelVkHash: zeroHash, - recursionCircuitsSetVksHash: zeroHash - }; - // const initialDiamondCut = await deployer.initialStateTransitionProxyDiamondCut(); - - // const proofSystem = deployer.proofSystemContract(deployWallet); + let deployer = await initialDeployment(deployWallet, ownerAddress, gasPrice, []); - // await (await proofSystem.setParams(verifierParams, initialDiamondCut)).wait(); - - await deployer.registerHyperchain(create2Salt, null, gasPrice); chainId = deployer.chainId; - - // const validatorTx = await deployer.proofChainContract(deployWallet).setValidator(await validator.getAddress(), true); - // await validatorTx.wait(); - allowList = deployer.l1AllowList(deployWallet); - const allowTx = await allowList.setBatchAccessMode( - [ - deployer.addresses.Bridgehub.BridgehubDiamondProxy, - deployer.addresses.Bridgehub.ChainProxy, - deployer.addresses.StateTransition.StateTransitionProxy, - deployer.addresses.StateTransition.DiamondProxy, - deployer.addresses.Bridges.ERC20BridgeProxy, - deployer.addresses.Bridges.WethBridgeProxy - ], - [ - AccessMode.Public, - AccessMode.Public, - AccessMode.Public, - AccessMode.Public, - AccessMode.Public, - AccessMode.Public - ] - ); - await allowTx.wait(); - - // bridgehubContract = BridgehubFactory.connect(deployer.addresses.Bridgehub.BridgehubDiamondProxy, deployWallet); l1Weth = WETH9Factory.connect( (await (await hardhat.ethers.getContractFactory('WETH9')).deploy()).address, diff --git a/ethereum/test/unit_tests/l2-upgrade.test.spec.ts b/ethereum/test/unit_tests/l2-upgrade.test.spec.ts index aba9abfdb..23286fc20 100644 --- a/ethereum/test/unit_tests/l2-upgrade.test.spec.ts +++ b/ethereum/test/unit_tests/l2-upgrade.test.spec.ts @@ -13,7 +13,9 @@ import { DefaultUpgradeFactory, CustomUpgradeTestFactory, MailboxFacet, - MailboxFacetFactory + MailboxFacetFactory, + StateTransition, + StateTransitionFactory } from '../../typechain'; import { getCallRevertReason, @@ -28,7 +30,8 @@ import { SYSTEM_LOG_KEYS, constructL2Log, L2_TO_L1_MESSENGER, - packBatchTimestampAndBatchTimestamp + packBatchTimestampAndBatchTimestamp, + initialDeployment } from './utils'; import { keccak256 } from 'ethers/lib/utils'; import * as ethers from 'ethers'; @@ -51,8 +54,11 @@ const SYSTEM_UPGRADE_TX_TYPE = 254; describe('L2 upgrade test', function () { let proxyExecutor: ExecutorFacet; let proxyAdmin: AdminFacet; + let proxyMailbox: MailboxFacet; let proxyGetters: GettersFacet; + let stateTransition: StateTransition; + let allowList: AllowList; let owner: ethers.Signer; @@ -72,7 +78,6 @@ describe('L2 upgrade test', function () { owner.provider ); const ownerAddress = await deployWallet.getAddress(); - process.env.ETH_CLIENT_CHAIN_ID = (await deployWallet.getChainId()).toString(); const gasPrice = await owner.provider.getGasPrice(); @@ -87,90 +92,23 @@ describe('L2 upgrade test', function () { await owner.sendTransaction(tx); - const deployer = new Deployer({ - deployWallet, - ownerAddress, - verbose: false, - addresses: addressConfig, - bootloaderBytecodeHash: L2_BOOTLOADER_BYTECODE_HASH, - defaultAccountBytecodeHash: L2_DEFAULT_ACCOUNT_BYTECODE_HASH - }); - - const create2Salt = ethers.utils.hexlify(ethers.utils.randomBytes(32)); - - let nonce = await deployWallet.getTransactionCount(); - - await deployer.deployCreate2Factory({ gasPrice, nonce }); - nonce++; - - // await deployer.deployMulticall3(create2Salt, {gasPrice, nonce}); - // nonce++; - - process.env.CONTRACTS_GENESIS_ROOT = zeroHash; - process.env.CONTRACTS_GENESIS_ROLLUP_LEAF_INDEX = '0'; - process.env.CONTRACTS_GENESIS_BLOCK_COMMITMENT = zeroHash; - process.env.CONTRACTS_PRIORITY_TX_MAX_GAS_LIMIT = '72000000'; - process.env.CONTRACTS_RECURSION_NODE_LEVEL_VK_HASH = zeroHash; - process.env.CONTRACTS_RECURSION_LEAF_LEVEL_VK_HASH = zeroHash; - process.env.CONTRACTS_RECURSION_CIRCUITS_SET_VKS_HASH = zeroHash; - - await deployer.deployAllowList(create2Salt, { gasPrice, nonce }); - await deployer.deployBridgehubContract(create2Salt, gasPrice); - await deployer.deployStateTransitionContract(create2Salt, null,gasPrice); - await deployer.deployBridgeContracts(create2Salt, gasPrice); - await deployer.deployWethBridgeContracts(create2Salt, gasPrice); - - const verifierParams = { - recursionNodeLevelVkHash: zeroHash, - recursionLeafLevelVkHash: zeroHash, - recursionCircuitsSetVksHash: zeroHash - }; - verifier = deployer.addresses.StateTransition.Verifier; - // const initialDiamondCut = await deployer.initialStateTransitionProxyDiamondCut(); - - // const proofSystem = deployer.proofSystemContract(deployWallet); + let deployer = await initialDeployment(deployWallet, ownerAddress, gasPrice, []); - // await (await proofSystem.setParams(verifierParams, initialDiamondCut)).wait(); - - await deployer.registerHyperchain(create2Salt, null, gasPrice); chainId = deployer.chainId; - - // const validatorTx = await deployer.proofChainContract(deployWallet).setValidator(await validator.getAddress(), true); - // await validatorTx.wait(); - allowList = deployer.l1AllowList(deployWallet); + verifier = deployer.addresses.StateTransition.Verifier; - const allowTx = await allowList.setBatchAccessMode( - [ - deployer.addresses.Bridgehub.BridgehubDiamondProxy, - deployer.addresses.Bridgehub.ChainProxy, - deployer.addresses.StateTransition.StateTransitionProxy, - deployer.addresses.StateTransition.DiamondProxy, - deployer.addresses.Bridges.ERC20BridgeProxy, - deployer.addresses.Bridges.WethBridgeProxy - ], - [ - AccessMode.Public, - AccessMode.Public, - AccessMode.Public, - AccessMode.Public, - AccessMode.Public, - AccessMode.Public - ] - ); - await allowTx.wait(); proxyExecutor = ExecutorFacetFactory.connect(deployer.addresses.StateTransition.DiamondProxy, deployWallet); proxyGetters = GettersFacetFactory.connect(deployer.addresses.StateTransition.DiamondProxy, deployWallet); proxyAdmin = AdminFacetFactory.connect(deployer.addresses.StateTransition.DiamondProxy, deployWallet); + proxyMailbox = MailboxFacetFactory.connect(deployer.addresses.StateTransition.DiamondProxy, deployWallet); + + stateTransition = StateTransitionFactory.connect(deployer.addresses.StateTransition.StateTransitionProxy, deployWallet); await (await proxyAdmin.setValidator(await deployWallet.getAddress(), true)).wait(); - // bridgehubContract = BridgehubFactory.connect(deployer.addresses.Bridgehub.BridgehubDiamondProxy, deployWallet); - // let bridgehubChainContract = BridgehubChainFactory.connect( - // deployer.addresses.Bridgehub.ChainProxy, - // deployWallet - // ); + let priorityOp = await proxyGetters.priorityQueueFrontOperation(); priorityOpTxHash = priorityOp[0]; @@ -201,7 +139,7 @@ describe('L2 upgrade test', function () { expect(await proxyGetters.getL2SystemContractsUpgradeTxHash()).to.equal(ethers.constants.HashZero); await ( - await executeUpgrade(chainId, proxyGetters, proxyAdmin, { + await executeUpgrade(chainId, proxyGetters, stateTransition, { newProtocolVersion: 1, l2ProtocolUpgradeTx: noopUpgradeTransaction }) @@ -217,14 +155,14 @@ describe('L2 upgrade test', function () { it('Timestamp should behave correctly', async () => { // Upgrade was scheduled for now should work fine const timeNow = (await hardhat.ethers.provider.getBlock('latest')).timestamp; - await executeUpgrade(chainId, proxyGetters, proxyAdmin, { + await executeUpgrade(chainId, proxyGetters, stateTransition, { upgradeTimestamp: ethers.BigNumber.from(timeNow), l2ProtocolUpgradeTx: noopUpgradeTransaction }); // Upgrade that was scheduled for the future should not work now const revertReason = await getCallRevertReason( - executeUpgrade(chainId, proxyGetters, proxyAdmin, { + executeUpgrade(chainId, proxyGetters, stateTransition, { upgradeTimestamp: ethers.BigNumber.from(timeNow).mul(2), l2ProtocolUpgradeTx: noopUpgradeTransaction }) @@ -237,7 +175,7 @@ describe('L2 upgrade test', function () { txType: 255 }); const revertReason = await getCallRevertReason( - executeUpgrade(chainId, proxyGetters, proxyAdmin, { + executeUpgrade(chainId, proxyGetters, stateTransition, { l2ProtocolUpgradeTx: wrongTx }) ); @@ -252,7 +190,7 @@ describe('L2 upgrade test', function () { }); const revertReason = await getCallRevertReason( - executeUpgrade(chainId, proxyGetters, proxyAdmin, { + executeUpgrade(chainId, proxyGetters, stateTransition, { l2ProtocolUpgradeTx: wrongTx, newProtocolVersion: 3 }) @@ -268,7 +206,7 @@ describe('L2 upgrade test', function () { }); const revertReason = await getCallRevertReason( - executeUpgrade(chainId, proxyGetters, proxyAdmin, { + executeUpgrade(chainId, proxyGetters, stateTransition, { l2ProtocolUpgradeTx: wrongTx, newProtocolVersion: 0 }) @@ -284,7 +222,7 @@ describe('L2 upgrade test', function () { }); const revertReason = await getCallRevertReason( - executeUpgrade(chainId, proxyGetters, proxyAdmin, { + executeUpgrade(chainId, proxyGetters, stateTransition, { l2ProtocolUpgradeTx: wrongTx, newProtocolVersion: 3 }) @@ -300,7 +238,7 @@ describe('L2 upgrade test', function () { }); const revertReason = await getCallRevertReason( - executeUpgrade(chainId, proxyGetters, proxyAdmin, { + executeUpgrade(chainId, proxyGetters, stateTransition, { l2ProtocolUpgradeTx: wrongTx, newProtocolVersion: 3 }) @@ -317,7 +255,7 @@ describe('L2 upgrade test', function () { }); const revertReason = await getCallRevertReason( - executeUpgrade(chainId, proxyGetters, proxyAdmin, { + executeUpgrade(chainId, proxyGetters, stateTransition, { l2ProtocolUpgradeTx: wrongTx, newProtocolVersion: 3 }) @@ -335,7 +273,7 @@ describe('L2 upgrade test', function () { }); const revertReason = await getCallRevertReason( - executeUpgrade(chainId, proxyGetters, proxyAdmin, { + executeUpgrade(chainId, proxyGetters, stateTransition, { l2ProtocolUpgradeTx: wrongTx, factoryDeps: [myFactoryDep], newProtocolVersion: 3 @@ -353,7 +291,7 @@ describe('L2 upgrade test', function () { }); const revertReason = await getCallRevertReason( - executeUpgrade(chainId, proxyGetters, proxyAdmin, { + executeUpgrade(chainId, proxyGetters, stateTransition, { l2ProtocolUpgradeTx: wrongTx, factoryDeps: [myFactoryDep], newProtocolVersion: 3 @@ -373,7 +311,7 @@ describe('L2 upgrade test', function () { }); const revertReason = await getCallRevertReason( - executeUpgrade(chainId, proxyGetters, proxyAdmin, { + executeUpgrade(chainId, proxyGetters, stateTransition, { l2ProtocolUpgradeTx: wrongTx, factoryDeps: Array(33).fill(myFactoryDep), newProtocolVersion: 3 @@ -412,7 +350,7 @@ describe('L2 upgrade test', function () { newProtocolVersion: 4 }; - const upgradeReceipt = await (await executeUpgrade(chainId, proxyGetters, proxyAdmin, upgrade)).wait(); + const upgradeReceipt = await (await executeUpgrade(chainId, proxyGetters, stateTransition, upgrade)).wait(); const defaultUpgradeFactory = await hardhat.ethers.getContractFactory('DefaultUpgrade'); const upgradeEvents = upgradeReceipt.logs.map((log) => { @@ -491,7 +429,7 @@ describe('L2 upgrade test', function () { factoryDeps: [myFactoryDep], newProtocolVersion: 5 }; - const revertReason = await getCallRevertReason(executeUpgrade(chainId, proxyGetters, proxyAdmin, upgrade)); + const revertReason = await getCallRevertReason(executeUpgrade(chainId, proxyGetters, stateTransition, upgrade)); expect(revertReason).to.equal('Previous upgrade has not been finalized'); }); @@ -660,7 +598,7 @@ describe('L2 upgrade test', function () { it('Should successfully commit a sequential upgrade', async () => { expect(await proxyGetters.getL2SystemContractsUpgradeBatchNumber()).to.equal(0); await ( - await executeUpgrade(chainId, proxyGetters, proxyAdmin, { + await executeUpgrade(chainId, proxyGetters, stateTransition, { newProtocolVersion: 5, l2ProtocolUpgradeTx: noopUpgradeTransaction }) @@ -701,7 +639,7 @@ describe('L2 upgrade test', function () { it('Should successfully commit custom upgrade', async () => { const upgradeReceipt = await ( - await executeCustomUpgrade(chainId, proxyGetters, proxyAdmin, { + await executeCustomUpgrade(chainId, proxyGetters, stateTransition, { newProtocolVersion: 6, l2ProtocolUpgradeTx: noopUpgradeTransaction }) @@ -979,7 +917,7 @@ function buildProposeUpgrade(proposedUpgrade: PartialProposedUpgrade): ProposedU async function executeUpgrade( chainId: BigNumberish, proxyGetters: GettersFacet, - proxyAdmin: AdminFacet, + stateTransition: StateTransition, partialUpgrade: Partial, contractFactory?: ethers.ethers.ContractFactory ) { @@ -996,18 +934,19 @@ async function executeUpgrade( const defaultUpgrade = await defaultUpgradeFactory.deploy(); const diamondUpgradeInit = DefaultUpgradeFactory.connect(defaultUpgrade.address, defaultUpgrade.signer); - const upgradeCalldata = diamondUpgradeInit.interface.encodeFunctionData('upgrade', [ upgrade]); + const upgradeCalldata = diamondUpgradeInit.interface.encodeFunctionData('upgrade', [upgrade]); const diamondCutData = diamondCut([], diamondUpgradeInit.address, upgradeCalldata); // This promise will be handled in the tests - return proxyAdmin.executeUpgrade(diamondCutData); + (await stateTransition.setUpgradeDiamondCut(diamondCutData)).wait(); + return stateTransition.upgradeChain(chainId, diamondCutData); } async function executeCustomUpgrade( chainId: BigNumberish, proxyGetters: GettersFacet, - proxyAdmin: AdminFacet, + stateTransition: StateTransition, partialUpgrade: Partial, contractFactory?: ethers.ethers.ContractFactory ) { @@ -1024,12 +963,13 @@ async function executeCustomUpgrade( const customUpgrade = await upgradeFactory.deploy(); const diamondUpgradeInit = CustomUpgradeTestFactory.connect(customUpgrade.address, customUpgrade.signer); - const upgradeCalldata = diamondUpgradeInit.interface.encodeFunctionData('upgrade', [ upgrade]); + const upgradeCalldata = diamondUpgradeInit.interface.encodeFunctionData('upgrade', [upgrade]); const diamondCutData = diamondCut([], diamondUpgradeInit.address, upgradeCalldata); // This promise will be handled in the tests - return proxyAdmin.executeUpgrade(diamondCutData); + (await stateTransition.setUpgradeDiamondCut(diamondCutData)).wait(); + return stateTransition.upgradeChain(chainId, diamondCutData); } async function makeExecutedEqualCommitted( diff --git a/ethereum/test/unit_tests/mailbox_test.spec.ts b/ethereum/test/unit_tests/mailbox_test.spec.ts index ed9d0e7db..e6f0ad0bf 100644 --- a/ethereum/test/unit_tests/mailbox_test.spec.ts +++ b/ethereum/test/unit_tests/mailbox_test.spec.ts @@ -11,10 +11,6 @@ import { MockExecutorFacetFactory } from '../../typechain'; -// import { StandardMerkleTree } from "@openzeppelin/merkle-tree"; - -import * as fs from 'fs'; - import { DEFAULT_REVERT_REASON, getCallRevertReason, @@ -23,23 +19,18 @@ import { requestExecute, requestExecuteDirect, L2_TO_L1_MESSENGER, - L2_ETH_TOKEN_SYSTEM_CONTRACT_ADDR + L2_ETH_TOKEN_SYSTEM_CONTRACT_ADDR, + ethTestConfig, + initialDeployment } from './utils'; -import { Wallet } from 'ethers'; import * as ethers from 'ethers'; +import { Wallet } from 'ethers'; -import { Deployer } from '../../src.ts/deploy'; -import { facetCut, Action } from '../../src.ts/diamondCut'; +import { Action, facetCut, } from '../../src.ts/diamondCut'; -const zeroHash = '0x0000000000000000000000000000000000000000000000000000000000000000'; -const L2_BOOTLOADER_BYTECODE_HASH = '0x1000100000000000000000000000000000000000000000000000000000000000'; -const L2_DEFAULT_ACCOUNT_BYTECODE_HASH = '0x1001000000000000000000000000000000000000000000000000000000000000'; -const testConfigPath = './test/test_config/constant'; -const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, { encoding: 'utf-8' })); -const addressConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/addresses.json`, { encoding: 'utf-8' })); describe('Mailbox tests', function () { let allowList: AllowList; @@ -60,12 +51,11 @@ describe('Mailbox tests', function () { owner.provider ); const ownerAddress = await deployWallet.getAddress(); - process.env.ETH_CLIENT_CHAIN_ID = (await deployWallet.getChainId()).toString(); const gasPrice = await owner.provider.getGasPrice(); const tx = { - from: owner.getAddress(), + from: await owner.getAddress(), to: deployWallet.address, value: ethers.utils.parseEther('1000'), nonce: owner.getTransactionCount(), @@ -75,82 +65,15 @@ describe('Mailbox tests', function () { await owner.sendTransaction(tx); - const deployer = new Deployer({ - deployWallet, - ownerAddress, - verbose: false , - addresses: addressConfig, - bootloaderBytecodeHash: L2_BOOTLOADER_BYTECODE_HASH, - defaultAccountBytecodeHash: L2_DEFAULT_ACCOUNT_BYTECODE_HASH - }); - - const create2Salt = ethers.utils.hexlify(ethers.utils.randomBytes(32)); - - let nonce = await deployWallet.getTransactionCount(); - - await deployer.deployCreate2Factory({ gasPrice, nonce }); - nonce++; - - // await deployer.deployMulticall3(create2Salt, {gasPrice, nonce}); - // nonce++; - - process.env.CONTRACTS_GENESIS_ROOT = zeroHash; - process.env.CONTRACTS_GENESIS_ROLLUP_LEAF_INDEX = '0'; - process.env.CONTRACTS_GENESIS_BLOCK_COMMITMENT = zeroHash; - process.env.CONTRACTS_PRIORITY_TX_MAX_GAS_LIMIT = '72000000'; - process.env.CONTRACTS_RECURSION_NODE_LEVEL_VK_HASH = zeroHash; - process.env.CONTRACTS_RECURSION_LEAF_LEVEL_VK_HASH = zeroHash; - process.env.CONTRACTS_RECURSION_CIRCUITS_SET_VKS_HASH = zeroHash; - const mockExecutorFactory = await hardhat.ethers.getContractFactory('MockExecutorFacet'); const mockExecutorContract = await mockExecutorFactory.deploy(); const extraFacet = facetCut(mockExecutorContract.address, mockExecutorContract.interface, Action.Add, true); - await deployer.deployAllowList(create2Salt, { gasPrice, nonce }); - await deployer.deployBridgehubContract(create2Salt, gasPrice); - await deployer.deployStateTransitionContract(create2Salt, [extraFacet], gasPrice); - await deployer.deployBridgeContracts(create2Salt, gasPrice); - await deployer.deployWethBridgeContracts(create2Salt, gasPrice); - - // const verifierParams = { - // recursionNodeLevelVkHash: zeroHash, - // recursionLeafLevelVkHash: zeroHash, - // recursionCircuitsSetVksHash: zeroHash - // }; - - - - const proofSystem = deployer.proofSystemContract(deployWallet); - // await (await proofSystem.setParams(verifierParams, initialDiamondCut)).wait(); + let deployer = await initialDeployment(deployWallet, ownerAddress, gasPrice, [extraFacet]); - await deployer.registerHyperchain(create2Salt, [extraFacet], gasPrice); chainId = deployer.chainId; - - // const validatorTx = await deployer.proofChainContract(deployWallet).setValidator(await validator.getAddress(), true); - // await validatorTx.wait(); - allowList = deployer.l1AllowList(deployWallet); - const allowTx = await allowList.setBatchAccessMode( - [ - deployer.addresses.Bridgehub.BridgehubDiamondProxy, - deployer.addresses.Bridgehub.ChainProxy, - deployer.addresses.StateTransition.StateTransitionProxy, - deployer.addresses.StateTransition.DiamondProxy, - deployer.addresses.Bridges.ERC20BridgeProxy, - deployer.addresses.Bridges.WethBridgeProxy - ], - [ - AccessMode.Public, - AccessMode.Public, - AccessMode.Public, - AccessMode.Public, - AccessMode.Public, - AccessMode.Public - ] - ); - await allowTx.wait(); - bridgehubMailboxFacet = BridgehubMailboxFacetFactory.connect( deployer.addresses.Bridgehub.BridgehubDiamondProxy, deployWallet diff --git a/ethereum/test/unit_tests/utils.ts b/ethereum/test/unit_tests/utils.ts index 2d8c4a76c..58b986c4f 100644 --- a/ethereum/test/unit_tests/utils.ts +++ b/ethereum/test/unit_tests/utils.ts @@ -1,9 +1,17 @@ -import { BigNumber, BigNumberish, BytesLike, ethers } from 'ethers'; +import { BigNumber, BigNumberish, BytesLike, ethers, Wallet } from 'ethers'; import { Address } from 'zksync-web3/build/src/types'; -import { Action, diamondCut, facetCut, getAllSelectors } from '../../src.ts/diamondCut'; +import { Action, FacetCut, diamondCut, facetCut, getAllSelectors } from '../../src.ts/diamondCut'; import { expect } from 'chai'; import * as hardhat from 'hardhat'; +import { Deployer } from '../../src.ts/deploy'; + +import * as fs from 'fs'; + +const testConfigPath = './test/test_config/constant'; +export const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, { encoding: 'utf-8' })); +const addressConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/addresses.json`, { encoding: 'utf-8' })); + export const IERC20_INTERFACE = require('@openzeppelin/contracts/build/contracts/IERC20'); export const DEFAULT_REVERT_REASON = 'VM did not revert'; @@ -16,6 +24,12 @@ export const L2_TO_L1_MESSENGER = `0x0000000000000000000000000000000000008008`; export const L2_ETH_TOKEN_SYSTEM_CONTRACT_ADDR = '0x000000000000000000000000000000000000800a'; export const L2_BYTECODE_COMPRESSOR_ADDRESS = `0x000000000000000000000000000000000000800e`; + +const zeroHash = '0x0000000000000000000000000000000000000000000000000000000000000000'; + +const L2_BOOTLOADER_BYTECODE_HASH = '0x1000100000000000000000000000000000000000000000000000000000000000'; +const L2_DEFAULT_ACCOUNT_BYTECODE_HASH = '0x1001000000000000000000000000000000000000000000000000000000000000'; + export enum SYSTEM_LOG_KEYS { L2_TO_L1_LOGS_TREE_ROOT_KEY, TOTAL_L2_TO_L1_PUBDATA_KEY, @@ -219,6 +233,70 @@ export function packBatchTimestampAndBatchTimestamp( return ethers.utils.hexZeroPad(ethers.utils.hexlify(packedNum), 32); } +export async function initialDeployment(deployWallet: Wallet,ownerAddress:string, gasPrice: BigNumberish, extraFacets: FacetCut[]) : Promise{ + process.env.ETH_CLIENT_CHAIN_ID = (await deployWallet.getChainId()).toString(); + + const deployer = new Deployer({ + deployWallet, + ownerAddress, + verbose: false , + addresses: addressConfig, + bootloaderBytecodeHash: L2_BOOTLOADER_BYTECODE_HASH, + defaultAccountBytecodeHash: L2_DEFAULT_ACCOUNT_BYTECODE_HASH + }); + + const create2Salt = ethers.utils.hexlify(ethers.utils.randomBytes(32)); + + let nonce = await deployWallet.getTransactionCount(); + + await deployer.deployCreate2Factory({ gasPrice, nonce }); + nonce++; + + // await deployer.deployMulticall3(create2Salt, {gasPrice, nonce}); + // nonce++; + + process.env.CONTRACTS_GENESIS_ROOT = zeroHash; + process.env.CONTRACTS_GENESIS_ROLLUP_LEAF_INDEX = '0'; + process.env.CONTRACTS_GENESIS_BLOCK_COMMITMENT = zeroHash; + process.env.CONTRACTS_PRIORITY_TX_MAX_GAS_LIMIT = '72000000'; + process.env.CONTRACTS_RECURSION_NODE_LEVEL_VK_HASH = zeroHash; + process.env.CONTRACTS_RECURSION_LEAF_LEVEL_VK_HASH = zeroHash; + process.env.CONTRACTS_RECURSION_CIRCUITS_SET_VKS_HASH = zeroHash; + + await deployer.deployAllowList(create2Salt, { gasPrice, nonce }); + await deployer.deployBridgehubContract(create2Salt, gasPrice); + await deployer.deployStateTransitionContract(create2Salt, extraFacets, gasPrice); + await deployer.deployBridgeContracts(create2Salt, gasPrice); + await deployer.deployWethBridgeContracts(create2Salt, gasPrice); + + const stateTransition = deployer.stateTransitionContract(deployWallet); + + await deployer.registerHyperchain(create2Salt, extraFacets, gasPrice); + + const allowList = deployer.l1AllowList(deployWallet); + + const allowTx = await allowList.setBatchAccessMode( + [ + deployer.addresses.Bridgehub.BridgehubDiamondProxy, + deployer.addresses.Bridgehub.ChainProxy, + deployer.addresses.StateTransition.StateTransitionProxy, + deployer.addresses.StateTransition.DiamondProxy, + deployer.addresses.Bridges.ERC20BridgeProxy, + deployer.addresses.Bridges.WethBridgeProxy + ], + [ + AccessMode.Public, + AccessMode.Public, + AccessMode.Public, + AccessMode.Public, + AccessMode.Public, + AccessMode.Public + ] + ); + await allowTx.wait(); + return deployer; +} + export interface StoredBatchInfo { batchNumber: BigNumberish; batchHash: BytesLike;