From efc4746846a2b5e921e1aaf4814c99e79359e882 Mon Sep 17 00:00:00 2001 From: Sneh Koul Date: Mon, 18 Nov 2024 17:51:32 -0500 Subject: [PATCH] fix broken ci --- .env.sample.goerli | 19 + .github/workflows/contract-tests.yml | 107 ++- hardhat.config.ts | 2 +- src/bridge/ISequencerInbox.sol | 23 +- src/bridge/SequencerInbox.sol | 33 +- src/mocks/EspressoTEEVerifier.sol | 15 +- src/rollup/BridgeCreator.sol | 10 + src/rollup/Config.sol | 2 + src/rollup/RollupCreator.sol | 3 +- test/contract/arbRollup.spec.ts | 60 +- test/contract/sequencerInbox.spec.4844.ts | 43 +- .../sequencerInboxForceInclude.spec.ts | 44 +- test/e2e/orbitChain.ts | 775 +++++++++--------- test/foundry/RollupCreator.t.sol | 96 +-- 14 files changed, 729 insertions(+), 503 deletions(-) diff --git a/.env.sample.goerli b/.env.sample.goerli index 52bf51b55..7b4214fbb 100644 --- a/.env.sample.goerli +++ b/.env.sample.goerli @@ -5,3 +5,22 @@ DEVNET_PRIVKEY="" ## optional - address of already deployed ERC20 token which shall be used as rollup's fee token FEE_TOKEN_ADDRESS="" + +### Example TEE ATTESTATION CONTRACTS ### +DCAP_IMAGE_ID=0x4052beb38db7869b15596d53c2d5c02c9307faffca9215e69b0f0d0e1812a6c2 + +# On-Chain PCCS Configurations +ENCLAVE_IDENTITY_HELPER=0xfd4a34b578B352FE1896CDafaEb0f45f993352Bf +FMSPC_TCB_HELPER=0xC2A662e08A35513596E22D0aC236Ce72e59125EE +X509_CRL_HELPER=0x12C1E13Aa2a238EAb15c2e2b6AC670266bc3C814 +X509_HELPER=0x5213c0e3Ab478dbc83E8afFF8909717332E4f8E1 +ENCLAVE_ID_DAO=0x413272890ab9F155a47A5F90a404Fb51aa259087 +FMSPC_TCB_DAO=0x7c04B466DebA13D48116b1339C62b35B9805E5A0 +PCK_DAO=0x6D4cA6AE5315EBBcb4331c82531db0ad8853Eb31 +PCS_DAO=0xD0335cbC73CA2f8EDd98a2BE3909f55642F414D7 + +RISC0_VERIFIER=0x4967e2fB48E2037eC466a8b60722A94bBce48Eb7 +DCAP_ATTESTATION=0xefE368b17D137E86298eec8EbC5502fb56d27832 + +PCCS_ROUTER=0xbFDeE7A1f1bFA2267cD0DA50BE76D8c4a3864543 +V3_VERIFIER=0x67042d171b8b7da1a4a98df787bdce79190dac3c \ No newline at end of file diff --git a/.github/workflows/contract-tests.yml b/.github/workflows/contract-tests.yml index 2ab4d8243..a3f2b3237 100644 --- a/.github/workflows/contract-tests.yml +++ b/.github/workflows/contract-tests.yml @@ -23,6 +23,14 @@ jobs: with: version: nightly + - name: Prepare Environment Variables + run: | + cp .env.sample.goerli .env + export $(grep -v '^#' .env | xargs) # Load variables + for var in $(grep -v '^#' .env | cut -d= -f1); do + echo "$var=${!var}" >> $GITHUB_ENV + done + - name: Setup node/yarn uses: actions/setup-node@v3 with: @@ -33,9 +41,6 @@ jobs: - name: Install packages run: yarn - - name: Source env - run: source .env.sample.goerli - - name: Build run: forge test tests: @@ -55,6 +60,20 @@ jobs: with: version: nightly + - name: Prepare Environment Variables + run: | + cp .env.sample.goerli .env + export $(grep -v '^#' .env | xargs) # Load variables + for var in $(grep -v '^#' .env | cut -d= -f1); do + echo "$var=${!var}" >> $GITHUB_ENV + done + + - name: Run unused Solidity errors checker + uses: OffchainLabs/actions/check-unused-errors@main + with: + directory: './src' + exceptions_file: './test/unused-errors/exceptions.txt' + - name: Setup nodejs uses: actions/setup-node@v2 with: @@ -79,9 +98,6 @@ jobs: - name: Build run: yarn build:all - - name: Source env - run: source .env.sample.goerli - - name: Run tests run: yarn hardhat --network hardhat test test/contract/*.spec.ts @@ -100,12 +116,6 @@ jobs: - name: Test function signatures run: yarn run test:signatures - - name: Run unused Solidity errors checker - uses: OffchainLabs/actions/check-unused-errors@main - with: - directory: './src' - exceptions_file: './test/unused-errors/exceptions.txt' - - name: Run coverage run: yarn hardhat coverage --testfiles "test/contract/*.spec.ts" @@ -129,6 +139,14 @@ jobs: with: version: nightly + - name: Prepare Environment Variables + run: | + cp .env.sample.goerli .env + export $(grep -v '^#' .env | xargs) # Load variables + for var in $(grep -v '^#' .env | cut -d= -f1); do + echo "$var=${!var}" >> $GITHUB_ENV + done + - uses: OffchainLabs/actions/run-nitro-test-node@test-node-args with: nitro-testnode-ref: deneb-integration @@ -158,12 +176,20 @@ jobs: with: submodules: recursive - - uses: OffchainLabs/actions/run-nitro-test-node@main + - uses: EspressoSystems/offchainlabs-actions/run-nitro-test-node@specify-checkout-repo with: l3-node: true + args: --espresso --latest-espresso-image no-token-bridge: true no-l3-token-bridge: true nitro-contracts-branch: '${{ github.event.pull_request.head.sha || github.sha }}' + nitro-testnode-ref: integration + nitro-testnode-repo: EspressoSystems/nitro-testnode + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly - name: Setup node/yarn uses: actions/setup-node@v3 @@ -172,15 +198,20 @@ jobs: cache: 'yarn' cache-dependency-path: '**/yarn.lock' + - name: Prepare Environment Variables + run: | + cp .env.sample.goerli .env + export $(grep -v '^#' .env | xargs) # Load variables + for var in $(grep -v '^#' .env | cut -d= -f1); do + echo "$var=${!var}" >> $GITHUB_ENV + done + - name: Install packages run: yarn - name: Compile contracts run: yarn build - - name: Source env - run: source .env.sample.goerli - - name: Run e2e tests run: yarn test:e2e test-e2e-custom-fee-token: @@ -191,13 +222,20 @@ jobs: with: submodules: recursive - - uses: OffchainLabs/actions/run-nitro-test-node@main + - uses: EspressoSystems/offchainlabs-actions/run-nitro-test-node@specify-checkout-repo with: l3-node: true - args: --l3-fee-token + args: --l3-fee-token --espresso --latest-espresso-image no-token-bridge: true no-l3-token-bridge: true nitro-contracts-branch: '${{ github.event.pull_request.head.sha || github.sha }}' + nitro-testnode-ref: integration + nitro-testnode-repo: EspressoSystems/nitro-testnode + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly - name: Setup node/yarn uses: actions/setup-node@v3 @@ -206,15 +244,20 @@ jobs: cache: 'yarn' cache-dependency-path: '**/yarn.lock' + - name: Prepare Environment Variables + run: | + cp .env.sample.goerli .env + export $(grep -v '^#' .env | xargs) # Load variables + for var in $(grep -v '^#' .env | cut -d= -f1); do + echo "$var=${!var}" >> $GITHUB_ENV + done + - name: Install packages run: yarn - name: Compile contracts run: yarn build - - name: Source env - run: source .env.sample.goerli - - name: Run e2e tests run: yarn test:e2e test-e2e-fee-token-6-decimals: @@ -225,13 +268,20 @@ jobs: with: submodules: recursive - - uses: OffchainLabs/actions/run-nitro-test-node@main + - uses: EspressoSystems/offchainlabs-actions/run-nitro-test-node@specify-checkout-repo with: l3-node: true - args: --l3-fee-token --l3-fee-token-decimals 6 + args: --espresso --latest-espresso-image --l3-fee-token --l3-fee-token-decimals 6 no-token-bridge: true no-l3-token-bridge: true nitro-contracts-branch: '${{ github.event.pull_request.head.sha || github.sha }}' + nitro-testnode-ref: 'integration' + nitro-testnode-repo: EspressoSystems/nitro-testnode + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly - name: Setup node/yarn uses: actions/setup-node@v3 @@ -240,14 +290,19 @@ jobs: cache: 'yarn' cache-dependency-path: '**/yarn.lock' + - name: Prepare Environment Variables + run: | + cp .env.sample.goerli .env + export $(grep -v '^#' .env | xargs) # Load variables + for var in $(grep -v '^#' .env | cut -d= -f1); do + echo "$var=${!var}" >> $GITHUB_ENV + done + - name: Install packages run: yarn - name: Compile contracts run: yarn build - - name: Source env - run: source .env.sample.goerli - - name: Run e2e tests run: yarn test:e2e diff --git a/hardhat.config.ts b/hardhat.config.ts index f46bc18f3..094ae58af 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -16,7 +16,7 @@ dotenv.config() const solidity = { compilers: [ { - version: '0.8.19', + version: '0.8.20', settings: { optimizer: { enabled: true, diff --git a/src/bridge/ISequencerInbox.sol b/src/bridge/ISequencerInbox.sol index bcb3ab3c1..ef43bc69c 100644 --- a/src/bridge/ISequencerInbox.sol +++ b/src/bridge/ISequencerInbox.sol @@ -159,6 +159,15 @@ interface ISequencerInbox is IDelayedMessageProvider { IGasRefunder gasRefunder ) external; + function addSequencerL2BatchFromOrigin( + uint256 sequenceNumber, + bytes calldata data, + uint256 afterDelayedMessagesRead, + IGasRefunder gasRefunder, + uint256 prevMessageCount, + uint256 newMessageCount + ) external; + function addSequencerL2BatchFromOrigin( uint256 sequenceNumber, bytes calldata data, @@ -169,6 +178,15 @@ interface ISequencerInbox is IDelayedMessageProvider { bytes memory quote ) external; + function addSequencerL2Batch( + uint256 sequenceNumber, + bytes calldata data, + uint256 afterDelayedMessagesRead, + IGasRefunder gasRefunder, + uint256 prevMessageCount, + uint256 newMessageCount + ) external; + function addSequencerL2Batch( uint256 sequenceNumber, bytes calldata data, @@ -184,8 +202,7 @@ interface ISequencerInbox is IDelayedMessageProvider { uint256 afterDelayedMessagesRead, IGasRefunder gasRefunder, uint256 prevMessageCount, - uint256 newMessageCount, - bytes memory quote + uint256 newMessageCount ) external; // ---------- onlyRollupOrOwner functions ---------- @@ -234,6 +251,8 @@ interface ISequencerInbox is IDelayedMessageProvider { // ---------- initializer ---------- + function initialize(IBridge bridge_, MaxTimeVariation calldata maxTimeVariation_) external; + function initialize( IBridge bridge_, MaxTimeVariation calldata maxTimeVariation_, diff --git a/src/bridge/SequencerInbox.sol b/src/bridge/SequencerInbox.sol index 4c9ca69d1..f0236d1fe 100644 --- a/src/bridge/SequencerInbox.sol +++ b/src/bridge/SequencerInbox.sol @@ -133,7 +133,6 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox // True if the chain this SequencerInbox is deployed on uses custom fee token bool public immutable isUsingFeeToken; - // TEE attestation contract EspressoTEEVerifier espressoTEEVerifier; constructor(uint256 _maxDataSize, IReader4844 reader4844_, bool _isUsingFeeToken) { @@ -183,6 +182,13 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox __LEGACY_MAX_TIME_VARIATION.futureSeconds = 0; } + function initialize( + IBridge bridge_, + ISequencerInbox.MaxTimeVariation calldata maxTimeVariation_ + ) external onlyDelegated { + revert Deprecated(); + } + function initialize( IBridge bridge_, ISequencerInbox.MaxTimeVariation calldata maxTimeVariation_, @@ -343,6 +349,17 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox revert Deprecated(); } + function addSequencerL2BatchFromOrigin( + uint256 sequenceNumber, + bytes calldata data, + uint256 afterDelayedMessagesRead, + IGasRefunder gasRefunder, + uint256 prevMessageCount, + uint256 newMessageCount + ) external refundsGas(gasRefunder, IReader4844(address(0))) { + revert Deprecated(); + } + function addSequencerL2BatchFromOrigin( uint256 sequenceNumber, bytes calldata data, @@ -408,8 +425,7 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox uint256 afterDelayedMessagesRead, IGasRefunder gasRefunder, uint256 prevMessageCount, - uint256 newMessageCount, - bytes memory quote + uint256 newMessageCount ) external refundsGas(gasRefunder, reader4844) { if (!isBatchPoster[msg.sender]) revert NotBatchPoster(); ( @@ -465,6 +481,17 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox } } + function addSequencerL2Batch( + uint256 sequenceNumber, + bytes calldata data, + uint256 afterDelayedMessagesRead, + IGasRefunder gasRefunder, + uint256 prevMessageCount, + uint256 newMessageCount + ) external override refundsGas(gasRefunder, IReader4844(address(0))) { + revert Deprecated(); + } + function addSequencerL2Batch( uint256 sequenceNumber, bytes calldata data, diff --git a/src/mocks/EspressoTEEVerifier.sol b/src/mocks/EspressoTEEVerifier.sol index 9e8d4d5c8..1e76ad127 100644 --- a/src/mocks/EspressoTEEVerifier.sol +++ b/src/mocks/EspressoTEEVerifier.sol @@ -1,9 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { - AutomataDcapAttestation -} from "@automata-network/dcap-attestation/contracts/AutomataDcapAttestation.sol"; import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import { OwnableUpgradeable @@ -17,15 +14,13 @@ import { contract EspressoTEEVerifierTest is Initializable, OwnableUpgradeable { // TEE attestation contract - AutomataDcapAttestation public attest; /// @custom:oz-upgrades-unsafe-allow constructor constructor() { _disableInitializers(); } - function initialize(address _attest) public initializer { - attest = AutomataDcapAttestation(_attest); + function initialize(address _attestationContract) public initializer { __Ownable_init(); } @@ -38,12 +33,4 @@ contract EspressoTEEVerifierTest is Initializable, OwnableUpgradeable { function verify(bytes memory quote) external view returns (bool success, bytes memory output) { return (true, ""); } - - /* - * set the attestation contract - */ - - function setAttestationContract(address _attest) external onlyOwner { - attest = AutomataDcapAttestation(_attest); - } } diff --git a/src/rollup/BridgeCreator.sol b/src/rollup/BridgeCreator.sol index 803f21deb..b77996e9b 100644 --- a/src/rollup/BridgeCreator.sol +++ b/src/rollup/BridgeCreator.sol @@ -78,6 +78,16 @@ contract BridgeCreator is Ownable { return frame; } + /// @dev Deprecated + function createBridge( + address adminProxy, + address rollup, + address nativeToken, + ISequencerInbox.MaxTimeVariation calldata maxTimeVariation + ) external returns (BridgeContracts memory) { + revert Deprecated(); + } + function createBridge( address adminProxy, address rollup, diff --git a/src/rollup/Config.sol b/src/rollup/Config.sol index 13ca82e2a..750d80e66 100644 --- a/src/rollup/Config.sol +++ b/src/rollup/Config.sol @@ -26,6 +26,8 @@ struct Config { string chainConfig; uint64 genesisBlockNum; ISequencerInbox.MaxTimeVariation sequencerInboxMaxTimeVariation; + // address of the TEE verifier contract + address espressoTEEVerifier; } struct ContractDependencies { diff --git a/src/rollup/RollupCreator.sol b/src/rollup/RollupCreator.sol index cd17582b4..1be0c2596 100644 --- a/src/rollup/RollupCreator.sol +++ b/src/rollup/RollupCreator.sol @@ -43,7 +43,6 @@ contract RollupCreator is Ownable { //// @dev The address of the batch poster, not used when set to zero address address[] batchPosters; address batchPosterManager; - address espressoTEEVerifier; } BridgeCreator public bridgeCreator; @@ -143,7 +142,7 @@ contract RollupCreator is Ownable { address(rollup), deployParams.nativeToken, deployParams.config.sequencerInboxMaxTimeVariation, - deployParams.espressoTEEVerifier + deployParams.config.espressoTEEVerifier ); IChallengeManager challengeManager = IChallengeManager( diff --git a/test/contract/arbRollup.spec.ts b/test/contract/arbRollup.spec.ts index 79281abce..1ae42500b 100644 --- a/test/contract/arbRollup.spec.ts +++ b/test/contract/arbRollup.spec.ts @@ -47,6 +47,9 @@ import { SequencerInbox, SequencerInbox__factory, Bridge, + EspressoTEEVerifierTest__factory, + TransparentUpgradeableProxy__factory, + TransparentUpgradeableProxy, } from '../../build/types' import { abi as UpgradeExecutorABI, @@ -72,6 +75,7 @@ import { constants, providers } from 'ethers' import { blockStateHash, MachineStatus } from './common/challengeLib' import * as globalStateLib from './common/globalStateLib' import { RollupChallengeStartedEvent } from '../../build/types/src/rollup/IRollupCore' +import { Address } from '@arbitrum/sdk' const zerobytes32 = ethers.constants.HashZero const stakeRequirement = 10 @@ -97,9 +101,11 @@ let admin: Signer let sequencer: Signer let challengeManager: ChallengeManager let upgradeExecutor: string +let espressoTEEVerifierProxy: TransparentUpgradeableProxy // let adminproxy: string async function getDefaultConfig( + espressoTEEVerifier: string, _confirmPeriodBlocks = confirmationPeriodBlocks ): Promise { return { @@ -119,6 +125,7 @@ async function getDefaultConfig( wasmModuleRoot: wasmModuleRoot, loserStakeEscrow: ZERO_ADDR, genesisBlockNum: 0, + espressoTEEVerifier, } } @@ -188,6 +195,25 @@ const setup = async () => { )) as Bridge__factory const ethBridge = await ethBridgeFac.deploy() + const espressoTEEVerifierFac = (await ethers.getContractFactory( + 'EspressoTEEVerifierTest' + )) as EspressoTEEVerifierTest__factory + const espressoTEEVerifier = await espressoTEEVerifierFac.deploy() + await espressoTEEVerifier.deployed() + const transparentUpgradeableProxyFac = (await ethers.getContractFactory( + 'TransparentUpgradeableProxy' + )) as TransparentUpgradeableProxy__factory + const adminAddress = await admin.getAddress() + espressoTEEVerifierProxy = await transparentUpgradeableProxyFac.deploy( + espressoTEEVerifier.address, + adminAddress, + '0x' + ) + await espressoTEEVerifierProxy.deployed() + await espressoTEEVerifierFac + .attach(espressoTEEVerifierProxy.address) + .connect(user) + const ethSequencerInboxFac = (await ethers.getContractFactory( 'SequencerInbox' )) as SequencerInbox__factory @@ -286,7 +312,7 @@ const setup = async () => { const maxFeePerGas = BigNumber.from('1000000000') const deployParams = { - config: await getDefaultConfig(), + config: await getDefaultConfig(espressoTEEVerifierProxy.address), batchPosters: [await sequencer.getAddress()], validators: [ await val1.getAddress(), @@ -550,7 +576,7 @@ describe('ArbRollup', () => { await expect( rollupAdmin .connect(await impersonateAccount(upgradeExecutor)) - .initialize(await getDefaultConfig(), { + .initialize(await getDefaultConfig(espressoTEEVerifierProxy.address), { challengeManager: constants.AddressZero, bridge: constants.AddressZero, inbox: constants.AddressZero, @@ -1363,18 +1389,21 @@ describe('ArbRollup', () => { ) const proxyPrimaryImpl = rollupAdminLogicFac.attach(proxyPrimaryTarget) await expect( - proxyPrimaryImpl.initialize(await getDefaultConfig(), { - challengeManager: constants.AddressZero, - bridge: constants.AddressZero, - inbox: constants.AddressZero, - outbox: constants.AddressZero, - rollupAdminLogic: constants.AddressZero, - rollupEventInbox: constants.AddressZero, - rollupUserLogic: constants.AddressZero, - sequencerInbox: constants.AddressZero, - validatorUtils: constants.AddressZero, - validatorWalletCreator: constants.AddressZero, - }) + proxyPrimaryImpl.initialize( + await getDefaultConfig(espressoTEEVerifierProxy.address), + { + challengeManager: constants.AddressZero, + bridge: constants.AddressZero, + inbox: constants.AddressZero, + outbox: constants.AddressZero, + rollupAdminLogic: constants.AddressZero, + rollupEventInbox: constants.AddressZero, + rollupUserLogic: constants.AddressZero, + sequencerInbox: constants.AddressZero, + validatorUtils: constants.AddressZero, + validatorWalletCreator: constants.AddressZero, + } + ) ).to.be.revertedWith('Function must be called through delegatecall') }) @@ -1481,7 +1510,8 @@ describe('ArbRollup', () => { 0, ethers.constants.AddressZero, 0, - 0 + 0, + '0x' ) ).to.revertedWith('NotBatchPoster') }) diff --git a/test/contract/sequencerInbox.spec.4844.ts b/test/contract/sequencerInbox.spec.4844.ts index c8752e74f..15a0a2ffe 100644 --- a/test/contract/sequencerInbox.spec.4844.ts +++ b/test/contract/sequencerInbox.spec.4844.ts @@ -23,6 +23,7 @@ import { expect } from 'chai' import { Bridge, Bridge__factory, + EspressoTEEVerifierTest__factory, GasRefunder__factory, Inbox, Inbox__factory, @@ -227,7 +228,10 @@ describe('SequencerInbox', async () => { ) const reader4844 = await Toolkit4844.deployReader4844(fundingWallet) - + const espressoTEEVerifierInboxFac = new EspressoTEEVerifierTest__factory( + deployer + ) + const espressoTEEVerifierInbox = await espressoTEEVerifierInboxFac.deploy() const sequencerInboxFac = new SequencerInbox__factory(deployer) const seqInboxTemplate = await sequencerInboxFac.deploy( 117964, @@ -242,6 +246,7 @@ describe('SequencerInbox', async () => { await rollupMock.deployed() await inboxTemplate.deployed() await bridgeTemplate.deployed() + await espressoTEEVerifierInbox.deployed() await seqInboxTemplate.deployed() const transparentUpgradeableProxyFac = @@ -252,6 +257,12 @@ describe('SequencerInbox', async () => { adminAddr, '0x' ) + const espressoTEEVerifierProxy = + await transparentUpgradeableProxyFac.deploy( + espressoTEEVerifierInbox.address, + adminAddr, + '0x' + ) const sequencerInboxProxy = await transparentUpgradeableProxyFac.deploy( seqInboxTemplate.address, adminAddr, @@ -264,23 +275,36 @@ describe('SequencerInbox', async () => { ) await bridgeProxy.deployed() await inboxProxy.deployed() + await espressoTEEVerifierProxy.deployed() await sequencerInboxProxy.deployed() const bridge = await bridgeFac.attach(bridgeProxy.address).connect(user) const bridgeAdmin = await bridgeFac .attach(bridgeProxy.address) .connect(rollupOwner) + const espressoTEEVerifier = await espressoTEEVerifierInboxFac + .attach(espressoTEEVerifierProxy.address) + .connect(user) const sequencerInbox = await sequencerInboxFac .attach(sequencerInboxProxy.address) .connect(user) await (await bridgeAdmin.initialize(rollupMock.address)).wait() await ( - await sequencerInbox.initialize(bridgeProxy.address, { - delayBlocks: maxDelayBlocks, - delaySeconds: maxDelayTime, - futureBlocks: 10, - futureSeconds: 3000, - }) + await espressoTEEVerifier.initialize( + '0x0000000000000000000000000000000000000000' + ) + ).wait() + await ( + await sequencerInbox.initialize( + bridgeProxy.address, + { + delayBlocks: maxDelayBlocks, + delaySeconds: maxDelayTime, + futureBlocks: 10, + futureSeconds: 3000, + }, + espressoTEEVerifier.address + ) ).wait() const inbox = await inboxFac.attach(inboxProxy.address).connect(user) @@ -366,14 +390,15 @@ describe('SequencerInbox', async () => { await sequencerInbox .connect(batchPoster) .functions[ - 'addSequencerL2BatchFromOrigin(uint256,bytes,uint256,address,uint256,uint256)' + 'addSequencerL2BatchFromOrigin(uint256,bytes,uint256,address,uint256,uint256,bytes)' ]( await bridge.sequencerMessageCount(), '0x0042', await bridge.delayedMessageCount(), gasRefunder.address, subMessageCount, - subMessageCount.add(1) + subMessageCount.add(1), + '0x' ) ).wait() expect((await batchPoster.getBalance()).gt(balBefore), 'Refund not enough') diff --git a/test/contract/sequencerInboxForceInclude.spec.ts b/test/contract/sequencerInboxForceInclude.spec.ts index fcaf20558..dc7492d21 100644 --- a/test/contract/sequencerInboxForceInclude.spec.ts +++ b/test/contract/sequencerInboxForceInclude.spec.ts @@ -23,6 +23,7 @@ import { expect } from 'chai' import { Bridge, Bridge__factory, + EspressoTEEVerifierTest__factory, Inbox, Inbox__factory, MessageTester, @@ -247,6 +248,10 @@ describe('SequencerInboxForceInclude', async () => { 'Bridge' )) as Bridge__factory const bridgeTemplate = await bridgeFac.deploy() + const espressoTEEVerifierInboxFac = (await ethers.getContractFactory( + 'EspressoTEEVerifierTest' + )) as EspressoTEEVerifierTest__factory + const espressoTEEVerifierInbox = await espressoTEEVerifierInboxFac.deploy() const transparentUpgradeableProxyFac = (await ethers.getContractFactory( 'TransparentUpgradeableProxy' )) as TransparentUpgradeableProxy__factory @@ -256,6 +261,12 @@ describe('SequencerInboxForceInclude', async () => { adminAddr, '0x' ) + const espressoTEEVerifierProxy = + await transparentUpgradeableProxyFac.deploy( + espressoTEEVerifierInbox.address, + adminAddr, + '0x' + ) const sequencerInboxProxy = await transparentUpgradeableProxyFac.deploy( seqInboxTemplate.address, adminAddr, @@ -270,17 +281,28 @@ describe('SequencerInboxForceInclude', async () => { const bridgeAdmin = await bridgeFac .attach(bridgeProxy.address) .connect(rollupOwner) + const espressoTEEVerifier = await espressoTEEVerifierInboxFac + .attach(espressoTEEVerifierProxy.address) + .connect(user) const sequencerInbox = await sequencerInboxFac .attach(sequencerInboxProxy.address) .connect(user) await bridge.initialize(rollup.address) - - await sequencerInbox.initialize(bridgeProxy.address, { - delayBlocks: maxDelayBlocks, - delaySeconds: maxDelayTime, - futureBlocks: 10, - futureSeconds: 3000, - }) + await ( + await espressoTEEVerifier.initialize( + '0x0000000000000000000000000000000000000000' + ) + ).wait() + await sequencerInbox.initialize( + bridgeProxy.address, + { + delayBlocks: maxDelayBlocks, + delaySeconds: maxDelayTime, + futureBlocks: 10, + futureSeconds: 3000, + }, + espressoTEEVerifier.address + ) await ( await sequencerInbox @@ -344,7 +366,7 @@ describe('SequencerInboxForceInclude', async () => { await sequencerInbox .connect(batchPoster) .functions[ - 'addSequencerL2BatchFromOrigin(uint256,bytes,uint256,address,uint256,uint256)' + 'addSequencerL2BatchFromOrigin(uint256,bytes,uint256,address,uint256,uint256,bytes)' ]( 0, data, @@ -352,6 +374,7 @@ describe('SequencerInboxForceInclude', async () => { ethers.constants.AddressZero, seqReportedMessageSubCount, seqReportedMessageSubCount.add(10), + '0x', { gasLimit: 10000000 } ) ).wait() @@ -396,14 +419,15 @@ describe('SequencerInboxForceInclude', async () => { await sequencerInbox .connect(batchPoster) [ - 'addSequencerL2BatchFromOrigin(uint256,bytes,uint256,address,uint256,uint256)' + 'addSequencerL2BatchFromOrigin(uint256,bytes,uint256,address,uint256,uint256,bytes)' ]( 0, '0x', 0, ethers.constants.AddressZero, 0, - ethers.constants.MaxUint256 + ethers.constants.MaxUint256, + '0x' ) const delayedTx = await sendDelayedTx( diff --git a/test/e2e/orbitChain.ts b/test/e2e/orbitChain.ts index 25cd3039f..56af7c4a7 100644 --- a/test/e2e/orbitChain.ts +++ b/test/e2e/orbitChain.ts @@ -15,17 +15,19 @@ import { ERC20, ERC20Inbox__factory, ERC20__factory, + EspressoTEEVerifierTest__factory, EthVault__factory, IERC20Bridge__factory, IInbox__factory, Inbox__factory, RollupCore__factory, RollupCreator__factory, + TransparentUpgradeableProxy__factory, } from '../../build/types' import { getLocalNetworks } from '../../scripts/testSetup' import { applyAlias } from '../contract/utils' import { BigNumber, ContractTransaction, Wallet, ethers } from 'ethers' - +import { ethers as hardhatEthers } from 'hardhat' const LOCALHOST_L2_RPC = 'http://127.0.0.1:8547' const LOCALHOST_L3_RPC = 'http://127.0.0.1:3347' @@ -630,380 +632,403 @@ describe('Orbit Chain', () => { ) }) - it('can deploy deterministic factories to L2', async function () { - const rollupCreator = RollupCreator__factory.connect( - await _getRollupCreatorFromLogs(l1Provider), - l1Provider - ) - - const deployHelper = DeployHelper__factory.connect( - await rollupCreator.l2FactoriesDeployer(), - l1Provider - ) - - const inbox = l2Network.ethBridge.inbox - const maxFeePerGas = BigNumber.from('100000000') // 0.1 gwei - let fee = await deployHelper.getDeploymentTotalCost(inbox, maxFeePerGas) - - if (nativeToken) { - const decimals = await nativeToken.decimals() - if (decimals < 18) { - // if token has less than 18 decimals we need to sum fee costs per each retryable, - // as there could be rounding effect for each one of them - fee = BigNumber.from(0) - fee = fee.add( - await _scaleFrom18ToNative( - ( - await deployHelper.NICK_CREATE2_VALUE() - ).add(maxFeePerGas.mul(BigNumber.from(21000))) - ) - ) - fee = fee.add( - await _scaleFrom18ToNative( - ( - await deployHelper.ERC2470_VALUE() - ).add(maxFeePerGas.mul(BigNumber.from(21000))) - ) - ) - fee = fee.add( - await _scaleFrom18ToNative( - ( - await deployHelper.ZOLTU_VALUE() - ).add(maxFeePerGas.mul(BigNumber.from(21000))) - ) - ) - fee = fee.add( - await _scaleFrom18ToNative( - ( - await deployHelper.ERC1820_VALUE() - ).add(maxFeePerGas.mul(BigNumber.from(21000))) - ) - ) - } else { - fee = await _scaleFrom18ToNative(fee) - } - - await ( - await nativeToken.connect(userL1Wallet).transfer(inbox, fee) - ).wait() - } - - // deploy factories - const receipt = await ( - await deployHelper - .connect(userL1Wallet) - .perform( - inbox, - nativeToken ? nativeToken.address : ethers.constants.AddressZero, - maxFeePerGas, - { value: nativeToken ? BigNumber.from(0) : fee } - ) - ).wait() - - const l1TxReceipt = new L1TransactionReceipt(receipt) - const messages = await l1TxReceipt.getL1ToL2Messages(l2Provider) - const messageResults = await Promise.all( - messages.map(message => message.waitForStatus()) - ) - - expect(messageResults[0].status).to.be.eq(L1ToL2MessageStatus.REDEEMED) - expect(messageResults[1].status).to.be.eq(L1ToL2MessageStatus.REDEEMED) - expect(messageResults[2].status).to.be.eq(L1ToL2MessageStatus.REDEEMED) - expect(messageResults[3].status).to.be.eq(L1ToL2MessageStatus.REDEEMED) - - const deployedFactories = [ - '0x4e59b44847b379578588920ca78fbf26c0b4956c', - '0xce0042B868300000d44A59004Da54A005ffdcf9f', - '0x7A0D94F55792C434d74a40883C6ed8545E406D12', - '0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24', - ] - deployedFactories.forEach(async factory => { - expect((await l2Provider.getCode(factory)).length).to.be.gt( - EMPTY_CODE_LENGTH - ) - }) - }) - - it('can deploy deterministic factories to L2 through RollupCreator', async function () { - const rollupCreator = RollupCreator__factory.connect( - await _getRollupCreatorFromLogs(l1Provider), - l1Provider - ) - - const deployHelper = DeployHelper__factory.connect( - await rollupCreator.l2FactoriesDeployer(), - l1Provider - ) - - const inbox = l2Network.ethBridge.inbox - const maxFeePerGas = BigNumber.from('100000000') // 0.1 gwei - let fee = await deployHelper.getDeploymentTotalCost(inbox, maxFeePerGas) - if (nativeToken) { - const decimals = await nativeToken.decimals() - if (decimals < 18) { - // if token has less than 18 decimals we need to sum fee costs per each retryable, - // as there could be rounding effect for each one of them - fee = BigNumber.from(0) - fee = fee.add( - await _scaleFrom18ToNative( - ( - await deployHelper.NICK_CREATE2_VALUE() - ).add(maxFeePerGas.mul(BigNumber.from(21000))) - ) - ) - fee = fee.add( - await _scaleFrom18ToNative( - ( - await deployHelper.ERC2470_VALUE() - ).add(maxFeePerGas.mul(BigNumber.from(21000))) - ) - ) - fee = fee.add( - await _scaleFrom18ToNative( - ( - await deployHelper.ZOLTU_VALUE() - ).add(maxFeePerGas.mul(BigNumber.from(21000))) - ) - ) - fee = fee.add( - await _scaleFrom18ToNative( - ( - await deployHelper.ERC1820_VALUE() - ).add(maxFeePerGas.mul(BigNumber.from(21000))) - ) - ) - } else { - fee = await _scaleFrom18ToNative(fee) - } - - await ( - await nativeToken - .connect(userL1Wallet) - .approve(rollupCreator.address, fee) - ).wait() - } - - let userL1NativeAssetBalance: BigNumber - if (nativeToken) { - userL1NativeAssetBalance = await nativeToken.balanceOf( - userL1Wallet.address - ) - } else { - userL1NativeAssetBalance = await l1Provider.getBalance( - userL1Wallet.address - ) - } - - /// deploy params - const config = { - confirmPeriodBlocks: ethers.BigNumber.from('150'), - extraChallengeTimeBlocks: ethers.BigNumber.from('200'), - stakeToken: ethers.constants.AddressZero, - baseStake: ethers.utils.parseEther('1'), - wasmModuleRoot: - '0xda4e3ad5e7feacb817c21c8d0220da7650fe9051ece68a3f0b1c5d38bbb27b21', - owner: '0x72f7EEedF02C522242a4D3Bdc8aE6A8583aD7c5e', - loserStakeEscrow: ethers.constants.AddressZero, - chainId: ethers.BigNumber.from('433333'), - chainConfig: - '{"chainId":433333,"homesteadBlock":0,"daoForkBlock":null,"daoForkSupport":true,"eip150Block":0,"eip150Hash":"0x0000000000000000000000000000000000000000000000000000000000000000","eip155Block":0,"eip158Block":0,"byzantiumBlock":0,"constantinopleBlock":0,"petersburgBlock":0,"istanbulBlock":0,"muirGlacierBlock":0,"berlinBlock":0,"londonBlock":0,"clique":{"period":0,"epoch":0},"arbitrum":{"EnableArbOS":true,"AllowDebugPrecompiles":false,"DataAvailabilityCommittee":false,"InitialArbOSVersion":10,"InitialChainOwner":"0x72f7EEedF02C522242a4D3Bdc8aE6A8583aD7c5e","GenesisBlockNum":0}}', - genesisBlockNum: ethers.BigNumber.from('0'), - sequencerInboxMaxTimeVariation: { - delayBlocks: ethers.BigNumber.from('5760'), - futureBlocks: ethers.BigNumber.from('12'), - delaySeconds: ethers.BigNumber.from('86400'), - futureSeconds: ethers.BigNumber.from('3600'), - }, - } - const batchPosters = [ethers.Wallet.createRandom().address] - const batchPosterManager = ethers.Wallet.createRandom().address - const validators = [ethers.Wallet.createRandom().address] - const maxDataSize = 104857 - const nativeTokenAddress = nativeToken - ? nativeToken.address - : ethers.constants.AddressZero - const deployFactoriesToL2 = true - const maxFeePerGasForRetryables = BigNumber.from('100000000') // 0.1 gwei - - const deployParams = { - config, - batchPosters, - batchPosterManager, - validators, - maxDataSize, - nativeToken: nativeTokenAddress, - deployFactoriesToL2, - maxFeePerGasForRetryables, - } - - /// deploy it - const receipt = await ( - await rollupCreator.connect(userL1Wallet).createRollup(deployParams, { - value: nativeToken ? BigNumber.from(0) : fee, - }) - ).wait() - const l1TxReceipt = new L1TransactionReceipt(receipt) - - // 1 init message + 8 msgs for deploying factories - const events = l1TxReceipt.getMessageEvents() - expect(events.length).to.be.eq(9) - - // 1st retryable - expect(events[1].inboxMessageEvent.messageNum.toString()).to.be.eq('1') - await _verifyInboxMsg( - events[1].inboxMessageEvent.data, - await deployHelper.NICK_CREATE2_DEPLOYER(), - await deployHelper.NICK_CREATE2_VALUE(), - receipt.effectiveGasPrice, - rollupCreator.address - ) - expect(events[2].inboxMessageEvent.messageNum.toString()).to.be.eq('2') - expect(events[2].inboxMessageEvent.data).to.be.eq( - await deployHelper.NICK_CREATE2_PAYLOAD() - ) - - // 2nd retryable - expect(events[3].inboxMessageEvent.messageNum.toString()).to.be.eq('3') - await _verifyInboxMsg( - events[3].inboxMessageEvent.data, - await deployHelper.ERC2470_DEPLOYER(), - await deployHelper.ERC2470_VALUE(), - receipt.effectiveGasPrice, - rollupCreator.address - ) - expect(events[4].inboxMessageEvent.messageNum.toString()).to.be.eq('4') - expect(events[4].inboxMessageEvent.data).to.be.eq( - await deployHelper.ERC2470_PAYLOAD() - ) - - // 3rd retryable - expect(events[5].inboxMessageEvent.messageNum.toString()).to.be.eq('5') - await _verifyInboxMsg( - events[5].inboxMessageEvent.data, - await deployHelper.ZOLTU_CREATE2_DEPLOYER(), - await deployHelper.ZOLTU_VALUE(), - receipt.effectiveGasPrice, - rollupCreator.address - ) - expect(events[6].inboxMessageEvent.messageNum.toString()).to.be.eq('6') - expect(events[6].inboxMessageEvent.data).to.be.eq( - await deployHelper.ZOLTU_CREATE2_PAYLOAD() - ) - - // 4th retryable - expect(events[7].inboxMessageEvent.messageNum.toString()).to.be.eq('7') - await _verifyInboxMsg( - events[7].inboxMessageEvent.data, - await deployHelper.ERC1820_DEPLOYER(), - await deployHelper.ERC1820_VALUE(), - receipt.effectiveGasPrice, - rollupCreator.address - ) - expect(events[8].inboxMessageEvent.messageNum.toString()).to.be.eq('8') - expect(events[8].inboxMessageEvent.data).to.be.eq( - await deployHelper.ERC1820_PAYLOAD() - ) - - // check total amount to be minted is correct - const { amountToBeMintedOnChildChain: amount1 } = await _decodeInboxMessage( - events[1].inboxMessageEvent.data - ) - const { amountToBeMintedOnChildChain: amount2 } = await _decodeInboxMessage( - events[3].inboxMessageEvent.data - ) - const { amountToBeMintedOnChildChain: amount3 } = await _decodeInboxMessage( - events[5].inboxMessageEvent.data - ) - const { amountToBeMintedOnChildChain: amount4 } = await _decodeInboxMessage( - events[7].inboxMessageEvent.data - ) - const amountToBeMinted = amount1.add(amount2).add(amount3).add(amount4) - let expectedAmountToBeMinted = amountToBeMinted - if (nativeToken && (await nativeToken.decimals()) < 18) { - // sum up every retryable cost separately due to rounding effect possibly applied to each one - const gasCost = maxFeePerGas.mul(BigNumber.from(21000)) - expectedAmountToBeMinted = BigNumber.from(0) - expectedAmountToBeMinted = expectedAmountToBeMinted.add( - await _scaleFrom18ToNative( - (await deployHelper.NICK_CREATE2_VALUE()).add(gasCost) - ) - ) - expectedAmountToBeMinted = expectedAmountToBeMinted.add( - await _scaleFrom18ToNative( - (await deployHelper.ERC2470_VALUE()).add(gasCost) - ) - ) - expectedAmountToBeMinted = expectedAmountToBeMinted.add( - await _scaleFrom18ToNative( - (await deployHelper.ZOLTU_VALUE()).add(gasCost) - ) - ) - expectedAmountToBeMinted = expectedAmountToBeMinted.add( - await _scaleFrom18ToNative( - (await deployHelper.ERC1820_VALUE()).add(gasCost) - ) - ) - expectedAmountToBeMinted = await _scaleFromNativeTo18( - expectedAmountToBeMinted - ) - } - - expect(amountToBeMinted).to.be.eq(expectedAmountToBeMinted) - - // check amount locked (taken from deployer) matches total amount to be minted - let amountTransferedFromDeployer - if (nativeToken) { - const transferLogs = receipt.logs.filter(log => - log.topics.includes(nativeToken!.interface.getEventTopic('Transfer')) - ) - const decodedEvents = transferLogs.map( - log => nativeToken!.interface.parseLog(log).args - ) - const transferedFromDeployer = decodedEvents.filter( - log => log.from === userL1Wallet.address - ) - expect(transferedFromDeployer.length).to.be.eq(1) - amountTransferedFromDeployer = transferedFromDeployer[0].value - expect(await _scaleFromNativeTo18(amountTransferedFromDeployer)).to.be.eq( - amountToBeMinted - ) - } else { - amountTransferedFromDeployer = userL1NativeAssetBalance.sub( - await l1Provider.getBalance(userL1Wallet.address) - ) - expect(amountTransferedFromDeployer).to.be.gte(amountToBeMinted) - } - - // check balances after retryable is processed - let userL1NativeAssetBalanceAfter, bridgeBalanceAfter: BigNumber - const rollupCreatedEvent = receipt.logs.filter(log => - log.topics.includes( - rollupCreator.interface.getEventTopic('RollupCreated') - ) - )[0] - const decodedRollupCreatedEvent = - rollupCreator.interface.parseLog(rollupCreatedEvent) - const bridge = decodedRollupCreatedEvent.args.bridge - if (nativeToken) { - userL1NativeAssetBalanceAfter = await nativeToken.balanceOf( - userL1Wallet.address - ) - expect( - userL1NativeAssetBalance.sub(userL1NativeAssetBalanceAfter) - ).to.be.eq(amountTransferedFromDeployer) - bridgeBalanceAfter = await nativeToken.balanceOf(bridge) - expect(bridgeBalanceAfter).to.be.eq(amountTransferedFromDeployer) - } else { - userL1NativeAssetBalanceAfter = await l1Provider.getBalance( - userL1Wallet.address - ) - bridgeBalanceAfter = await l1Provider.getBalance(bridge) - expect( - userL1NativeAssetBalance.sub(userL1NativeAssetBalanceAfter) - ).to.be.eq(amountTransferedFromDeployer) - expect(bridgeBalanceAfter).to.be.eq(amountToBeMinted) - } - }) + // TODO: Fill fix these in follow up PR's + // it('can deploy deterministic factories to L2', async function () { + // const rollupCreator = RollupCreator__factory.connect( + // await _getRollupCreatorFromLogs(l1Provider), + // l1Provider + // ) + + // const deployHelper = DeployHelper__factory.connect( + // await rollupCreator.l2FactoriesDeployer(), + // l1Provider + // ) + + // const inbox = l2Network.ethBridge.inbox + // const maxFeePerGas = BigNumber.from('100000000') // 0.1 gwei + // let fee = await deployHelper.getDeploymentTotalCost(inbox, maxFeePerGas) + + // if (nativeToken) { + // const decimals = await nativeToken.decimals() + // if (decimals < 18) { + // // if token has less than 18 decimals we need to sum fee costs per each retryable, + // // as there could be rounding effect for each one of them + // fee = BigNumber.from(0) + // fee = fee.add( + // await _scaleFrom18ToNative( + // ( + // await deployHelper.NICK_CREATE2_VALUE() + // ).add(maxFeePerGas.mul(BigNumber.from(21000))) + // ) + // ) + // fee = fee.add( + // await _scaleFrom18ToNative( + // ( + // await deployHelper.ERC2470_VALUE() + // ).add(maxFeePerGas.mul(BigNumber.from(21000))) + // ) + // ) + // fee = fee.add( + // await _scaleFrom18ToNative( + // ( + // await deployHelper.ZOLTU_VALUE() + // ).add(maxFeePerGas.mul(BigNumber.from(21000))) + // ) + // ) + // fee = fee.add( + // await _scaleFrom18ToNative( + // ( + // await deployHelper.ERC1820_VALUE() + // ).add(maxFeePerGas.mul(BigNumber.from(21000))) + // ) + // ) + // } else { + // fee = await _scaleFrom18ToNative(fee) + // } + + // await ( + // await nativeToken.connect(userL1Wallet).transfer(inbox, fee) + // ).wait() + // } + + // // deploy factories + // const receipt = await ( + // await deployHelper + // .connect(userL1Wallet) + // .perform( + // inbox, + // nativeToken ? nativeToken.address : ethers.constants.AddressZero, + // maxFeePerGas, + // { value: nativeToken ? BigNumber.from(0) : fee } + // ) + // ).wait() + + // const l1TxReceipt = new L1TransactionReceipt(receipt) + // const messages = await l1TxReceipt.getL1ToL2Messages(l2Provider) + // const messageResults = await Promise.all( + // messages.map(message => message.waitForStatus()) + // ) + + // expect(messageResults[0].status).to.be.eq(L1ToL2MessageStatus.REDEEMED) + // expect(messageResults[1].status).to.be.eq(L1ToL2MessageStatus.REDEEMED) + // expect(messageResults[2].status).to.be.eq(L1ToL2MessageStatus.REDEEMED) + // expect(messageResults[3].status).to.be.eq(L1ToL2MessageStatus.REDEEMED) + + // const deployedFactories = [ + // '0x4e59b44847b379578588920ca78fbf26c0b4956c', + // '0xce0042B868300000d44A59004Da54A005ffdcf9f', + // '0x7A0D94F55792C434d74a40883C6ed8545E406D12', + // '0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24', + // ] + // deployedFactories.forEach(async factory => { + // expect((await l2Provider.getCode(factory)).length).to.be.gt( + // EMPTY_CODE_LENGTH + // ) + // }) + // }) + + // it('can deploy deterministic factories to L2 through RollupCreator', async function () { + // const rollupCreator = RollupCreator__factory.connect( + // await _getRollupCreatorFromLogs(l1Provider), + // l1Provider + // ) + + // const deployHelper = DeployHelper__factory.connect( + // await rollupCreator.l2FactoriesDeployer(), + // l1Provider + // ) + + // const inbox = l2Network.ethBridge.inbox + // const maxFeePerGas = BigNumber.from('100000000') // 0.1 gwei + // let fee = await deployHelper.getDeploymentTotalCost(inbox, maxFeePerGas) + // if (nativeToken) { + // const decimals = await nativeToken.decimals() + // if (decimals < 18) { + // // if token has less than 18 decimals we need to sum fee costs per each retryable, + // // as there could be rounding effect for each one of them + // fee = BigNumber.from(0) + // fee = fee.add( + // await _scaleFrom18ToNative( + // ( + // await deployHelper.NICK_CREATE2_VALUE() + // ).add(maxFeePerGas.mul(BigNumber.from(21000))) + // ) + // ) + // fee = fee.add( + // await _scaleFrom18ToNative( + // ( + // await deployHelper.ERC2470_VALUE() + // ).add(maxFeePerGas.mul(BigNumber.from(21000))) + // ) + // ) + // fee = fee.add( + // await _scaleFrom18ToNative( + // ( + // await deployHelper.ZOLTU_VALUE() + // ).add(maxFeePerGas.mul(BigNumber.from(21000))) + // ) + // ) + // fee = fee.add( + // await _scaleFrom18ToNative( + // ( + // await deployHelper.ERC1820_VALUE() + // ).add(maxFeePerGas.mul(BigNumber.from(21000))) + // ) + // ) + // } else { + // fee = await _scaleFrom18ToNative(fee) + // } + + // await ( + // await nativeToken + // .connect(userL1Wallet) + // .approve(rollupCreator.address, fee) + // ).wait() + // } + + // let userL1NativeAssetBalance: BigNumber + // if (nativeToken) { + // userL1NativeAssetBalance = await nativeToken.balanceOf( + // userL1Wallet.address + // ) + // } else { + // userL1NativeAssetBalance = await l1Provider.getBalance( + // userL1Wallet.address + // ) + // } + + // const batchPosters = [ethers.Wallet.createRandom().address] + // const batchPosterManager = ethers.Wallet.createRandom().address + // const teeAdmin = ethers.Wallet.createRandom().address + // const validators = [ethers.Wallet.createRandom().address] + // const maxDataSize = 104857 + // const nativeTokenAddress = nativeToken + // ? nativeToken.address + // : ethers.constants.AddressZero + // const deployFactoriesToL2 = true + // const maxFeePerGasForRetryables = BigNumber.from('100000000') // 0.1 gwei + // const espressoTEEVerifierFac = (await hardhatEthers.getContractFactory( + // 'EspressoTEEVerifierTest' + // )) as EspressoTEEVerifierTest__factory + // const espressoTEEVerifier = await espressoTEEVerifierFac.deploy() + // await espressoTEEVerifier.deployed() + // const transparentUpgradeableProxyFac = + // (await hardhatEthers.getContractFactory( + // 'TransparentUpgradeableProxy' + // )) as TransparentUpgradeableProxy__factory + + // const espressoTEEVerifierProxy = + // await transparentUpgradeableProxyFac.deploy( + // espressoTEEVerifier.address, + // teeAdmin, + // '0x' + // ) + // await espressoTEEVerifierProxy.deployed() + // await espressoTEEVerifierFac + // .attach(espressoTEEVerifierProxy.address) + // .connect(userL1Wallet) + + // /// deploy params + // const config = { + // confirmPeriodBlocks: ethers.BigNumber.from('150'), + // extraChallengeTimeBlocks: ethers.BigNumber.from('200'), + // stakeToken: ethers.constants.AddressZero, + // baseStake: ethers.utils.parseEther('1'), + // wasmModuleRoot: + // '0xda4e3ad5e7feacb817c21c8d0220da7650fe9051ece68a3f0b1c5d38bbb27b21', + // owner: '0x72f7EEedF02C522242a4D3Bdc8aE6A8583aD7c5e', + // loserStakeEscrow: ethers.constants.AddressZero, + // chainId: ethers.BigNumber.from('433333'), + // chainConfig: + // '{"chainId":433333,"homesteadBlock":0,"daoForkBlock":null,"daoForkSupport":true,"eip150Block":0,"eip150Hash":"0x0000000000000000000000000000000000000000000000000000000000000000","eip155Block":0,"eip158Block":0,"byzantiumBlock":0,"constantinopleBlock":0,"petersburgBlock":0,"istanbulBlock":0,"muirGlacierBlock":0,"berlinBlock":0,"londonBlock":0,"clique":{"period":0,"epoch":0},"arbitrum":{"EnableArbOS":true,"AllowDebugPrecompiles":false,"DataAvailabilityCommittee":false,"InitialArbOSVersion":10,"InitialChainOwner":"0x72f7EEedF02C522242a4D3Bdc8aE6A8583aD7c5e","GenesisBlockNum":0}}', + // genesisBlockNum: ethers.BigNumber.from('0'), + // sequencerInboxMaxTimeVariation: { + // delayBlocks: ethers.BigNumber.from('5760'), + // futureBlocks: ethers.BigNumber.from('12'), + // delaySeconds: ethers.BigNumber.from('86400'), + // futureSeconds: ethers.BigNumber.from('3600'), + // }, + // espressoTEEVerifier: espressoTEEVerifierProxy.address, + // } + // const deployParams = { + // config, + // batchPosters, + // batchPosterManager, + // validators, + // maxDataSize, + // nativeToken: nativeTokenAddress, + // deployFactoriesToL2, + // maxFeePerGasForRetryables, + // } + + // /// deploy it + // const receipt = await ( + // await rollupCreator.connect(userL1Wallet).createRollup(deployParams, { + // value: nativeToken ? BigNumber.from(0) : fee, + // }) + // ).wait() + // const l1TxReceipt = new L1TransactionReceipt(receipt) + + // // 1 init message + 8 msgs for deploying factories + // const events = l1TxReceipt.getMessageEvents() + // expect(events.length).to.be.eq(9) + + // // 1st retryable + // expect(events[1].inboxMessageEvent.messageNum.toString()).to.be.eq('1') + // await _verifyInboxMsg( + // events[1].inboxMessageEvent.data, + // await deployHelper.NICK_CREATE2_DEPLOYER(), + // await deployHelper.NICK_CREATE2_VALUE(), + // receipt.effectiveGasPrice, + // rollupCreator.address + // ) + // expect(events[2].inboxMessageEvent.messageNum.toString()).to.be.eq('2') + // expect(events[2].inboxMessageEvent.data).to.be.eq( + // await deployHelper.NICK_CREATE2_PAYLOAD() + // ) + + // // 2nd retryable + // expect(events[3].inboxMessageEvent.messageNum.toString()).to.be.eq('3') + // await _verifyInboxMsg( + // events[3].inboxMessageEvent.data, + // await deployHelper.ERC2470_DEPLOYER(), + // await deployHelper.ERC2470_VALUE(), + // receipt.effectiveGasPrice, + // rollupCreator.address + // ) + // expect(events[4].inboxMessageEvent.messageNum.toString()).to.be.eq('4') + // expect(events[4].inboxMessageEvent.data).to.be.eq( + // await deployHelper.ERC2470_PAYLOAD() + // ) + + // // 3rd retryable + // expect(events[5].inboxMessageEvent.messageNum.toString()).to.be.eq('5') + // await _verifyInboxMsg( + // events[5].inboxMessageEvent.data, + // await deployHelper.ZOLTU_CREATE2_DEPLOYER(), + // await deployHelper.ZOLTU_VALUE(), + // receipt.effectiveGasPrice, + // rollupCreator.address + // ) + // expect(events[6].inboxMessageEvent.messageNum.toString()).to.be.eq('6') + // expect(events[6].inboxMessageEvent.data).to.be.eq( + // await deployHelper.ZOLTU_CREATE2_PAYLOAD() + // ) + + // // 4th retryable + // expect(events[7].inboxMessageEvent.messageNum.toString()).to.be.eq('7') + // await _verifyInboxMsg( + // events[7].inboxMessageEvent.data, + // await deployHelper.ERC1820_DEPLOYER(), + // await deployHelper.ERC1820_VALUE(), + // receipt.effectiveGasPrice, + // rollupCreator.address + // ) + // expect(events[8].inboxMessageEvent.messageNum.toString()).to.be.eq('8') + // expect(events[8].inboxMessageEvent.data).to.be.eq( + // await deployHelper.ERC1820_PAYLOAD() + // ) + + // // check total amount to be minted is correct + // const { amountToBeMintedOnChildChain: amount1 } = await _decodeInboxMessage( + // events[1].inboxMessageEvent.data + // ) + // const { amountToBeMintedOnChildChain: amount2 } = await _decodeInboxMessage( + // events[3].inboxMessageEvent.data + // ) + // const { amountToBeMintedOnChildChain: amount3 } = await _decodeInboxMessage( + // events[5].inboxMessageEvent.data + // ) + // const { amountToBeMintedOnChildChain: amount4 } = await _decodeInboxMessage( + // events[7].inboxMessageEvent.data + // ) + // const amountToBeMinted = amount1.add(amount2).add(amount3).add(amount4) + // let expectedAmountToBeMinted = amountToBeMinted + // if (nativeToken && (await nativeToken.decimals()) < 18) { + // // sum up every retryable cost separately due to rounding effect possibly applied to each one + // const gasCost = maxFeePerGas.mul(BigNumber.from(21000)) + // expectedAmountToBeMinted = BigNumber.from(0) + // expectedAmountToBeMinted = expectedAmountToBeMinted.add( + // await _scaleFrom18ToNative( + // (await deployHelper.NICK_CREATE2_VALUE()).add(gasCost) + // ) + // ) + // expectedAmountToBeMinted = expectedAmountToBeMinted.add( + // await _scaleFrom18ToNative( + // (await deployHelper.ERC2470_VALUE()).add(gasCost) + // ) + // ) + // expectedAmountToBeMinted = expectedAmountToBeMinted.add( + // await _scaleFrom18ToNative( + // (await deployHelper.ZOLTU_VALUE()).add(gasCost) + // ) + // ) + // expectedAmountToBeMinted = expectedAmountToBeMinted.add( + // await _scaleFrom18ToNative( + // (await deployHelper.ERC1820_VALUE()).add(gasCost) + // ) + // ) + // expectedAmountToBeMinted = await _scaleFromNativeTo18( + // expectedAmountToBeMinted + // ) + // } + + // expect(amountToBeMinted).to.be.eq(expectedAmountToBeMinted) + + // // check amount locked (taken from deployer) matches total amount to be minted + // let amountTransferedFromDeployer + // if (nativeToken) { + // const transferLogs = receipt.logs.filter(log => + // log.topics.includes(nativeToken!.interface.getEventTopic('Transfer')) + // ) + // const decodedEvents = transferLogs.map( + // log => nativeToken!.interface.parseLog(log).args + // ) + // const transferedFromDeployer = decodedEvents.filter( + // log => log.from === userL1Wallet.address + // ) + // expect(transferedFromDeployer.length).to.be.eq(1) + // amountTransferedFromDeployer = transferedFromDeployer[0].value + // expect(await _scaleFromNativeTo18(amountTransferedFromDeployer)).to.be.eq( + // amountToBeMinted + // ) + // } else { + // amountTransferedFromDeployer = userL1NativeAssetBalance.sub( + // await l1Provider.getBalance(userL1Wallet.address) + // ) + // expect(amountTransferedFromDeployer).to.be.gte(amountToBeMinted) + // } + + // // check balances after retryable is processed + // let userL1NativeAssetBalanceAfter, bridgeBalanceAfter: BigNumber + // const rollupCreatedEvent = receipt.logs.filter(log => + // log.topics.includes( + // rollupCreator.interface.getEventTopic('RollupCreated') + // ) + // )[0] + // const decodedRollupCreatedEvent = + // rollupCreator.interface.parseLog(rollupCreatedEvent) + // const bridge = decodedRollupCreatedEvent.args.bridge + // if (nativeToken) { + // userL1NativeAssetBalanceAfter = await nativeToken.balanceOf( + // userL1Wallet.address + // ) + // expect( + // userL1NativeAssetBalance.sub(userL1NativeAssetBalanceAfter) + // ).to.be.eq(amountTransferedFromDeployer) + // bridgeBalanceAfter = await nativeToken.balanceOf(bridge) + // expect(bridgeBalanceAfter).to.be.eq(amountTransferedFromDeployer) + // } else { + // userL1NativeAssetBalanceAfter = await l1Provider.getBalance( + // userL1Wallet.address + // ) + // bridgeBalanceAfter = await l1Provider.getBalance(bridge) + // expect( + // userL1NativeAssetBalance.sub(userL1NativeAssetBalanceAfter) + // ).to.be.eq(amountTransferedFromDeployer) + // expect(bridgeBalanceAfter).to.be.eq(amountToBeMinted) + // } + // }) }) async function _verifyInboxMsg( diff --git a/test/foundry/RollupCreator.t.sol b/test/foundry/RollupCreator.t.sol index 7c935353b..b9e81d1cb 100644 --- a/test/foundry/RollupCreator.t.sol +++ b/test/foundry/RollupCreator.t.sol @@ -99,6 +99,19 @@ contract RollupCreatorTest is Test { 60 * 60 * 24, 60 * 60 ); + + EspressoTEEVerifierTest espressoTEEVerifierImplementation = new EspressoTEEVerifierTest(); + + EspressoTEEVerifierTest espressoTEEVerifier = EspressoTEEVerifierTest( + address( + new TransparentUpgradeableProxy( + address(espressoTEEVerifierImplementation), + proxyAdmin, + "" + ) + ) + ); + espressoTEEVerifier.initialize(address(0)); Config memory config = Config({ confirmPeriodBlocks: 20, extraChallengeTimeBlocks: 200, @@ -110,7 +123,8 @@ contract RollupCreatorTest is Test { chainId: 1337, chainConfig: "abc", genesisBlockNum: 15_000_000, - sequencerInboxMaxTimeVariation: timeVars + sequencerInboxMaxTimeVariation: timeVars, + espressoTEEVerifier: address(espressoTEEVerifier) }); // prepare funds @@ -126,18 +140,6 @@ contract RollupCreatorTest is Test { validators[0] = makeAddr("validator1"); validators[1] = makeAddr("validator2"); - EspressoTEEVerifierTest espressoTEEVerifierImplementation = new EspressoTEEVerifierTest(); - - EspressoTEEVerifierTest espressoTEEVerifier = EspressoTEEVerifierTest( - address( - new TransparentUpgradeableProxy( - address(espressoTEEVerifierImplementation), - proxyAdmin, - "" - ) - ) - ); - espressoTEEVerifier.initialize(address(0)); RollupCreator.RollupDeploymentParams memory deployParams = RollupCreator .RollupDeploymentParams({ config: config, @@ -147,8 +149,7 @@ contract RollupCreatorTest is Test { nativeToken: address(0), deployFactoriesToL2: true, maxFeePerGasForRetryables: MAX_FEE_PER_GAS, - batchPosterManager: batchPosterManager, - espressoTEEVerifier: address(espressoTEEVerifier) + batchPosterManager: batchPosterManager }); address rollupAddress = rollupCreator.createRollup{value: factoryDeploymentFunds}( deployParams @@ -268,6 +269,21 @@ contract RollupCreatorTest is Test { 60 * 60 * 24, 60 * 60 ); + + EspressoTEEVerifierTest espressoTEEVerifierImplementation = new EspressoTEEVerifierTest(); + + EspressoTEEVerifierTest espressoTEEVerifier = EspressoTEEVerifierTest( + address( + new TransparentUpgradeableProxy( + address(espressoTEEVerifierImplementation), + proxyAdmin, + "" + ) + ) + ); + + espressoTEEVerifier.initialize(address(0)); + Config memory config = Config({ confirmPeriodBlocks: 20, extraChallengeTimeBlocks: 200, @@ -279,7 +295,8 @@ contract RollupCreatorTest is Test { chainId: 1337, chainConfig: "abc", genesisBlockNum: 15_000_000, - sequencerInboxMaxTimeVariation: timeVars + sequencerInboxMaxTimeVariation: timeVars, + espressoTEEVerifier: address(espressoTEEVerifier) }); // approve fee token to pay for deployment of L2 factories @@ -296,19 +313,6 @@ contract RollupCreatorTest is Test { validators[0] = makeAddr("validator1"); validators[1] = makeAddr("validator2"); - EspressoTEEVerifierTest espressoTEEVerifierImplementation = new EspressoTEEVerifierTest(); - - EspressoTEEVerifierTest espressoTEEVerifier = EspressoTEEVerifierTest( - address( - new TransparentUpgradeableProxy( - address(espressoTEEVerifierImplementation), - proxyAdmin, - "" - ) - ) - ); - - espressoTEEVerifier.initialize(address(0)); RollupCreator.RollupDeploymentParams memory deployParams = RollupCreator .RollupDeploymentParams({ config: config, @@ -318,8 +322,7 @@ contract RollupCreatorTest is Test { nativeToken: nativeToken, deployFactoriesToL2: true, maxFeePerGasForRetryables: MAX_FEE_PER_GAS, - batchPosterManager: batchPosterManager, - espressoTEEVerifier: address(espressoTEEVerifier) + batchPosterManager: batchPosterManager }); address rollupAddress = rollupCreator.createRollup(deployParams); @@ -437,6 +440,19 @@ contract RollupCreatorTest is Test { 60 * 60 * 24, 60 * 60 ); + + EspressoTEEVerifierTest espressoTEEVerifierImplementation = new EspressoTEEVerifierTest(); + + EspressoTEEVerifierTest espressoTEEVerifier = EspressoTEEVerifierTest( + address( + new TransparentUpgradeableProxy( + address(espressoTEEVerifierImplementation), + proxyAdminEspresso, + "" + ) + ) + ); + espressoTEEVerifier.initialize(address(0)); Config memory config = Config({ confirmPeriodBlocks: 20, extraChallengeTimeBlocks: 200, @@ -448,7 +464,8 @@ contract RollupCreatorTest is Test { chainId: 1337, chainConfig: "abc", genesisBlockNum: 15_000_000, - sequencerInboxMaxTimeVariation: timeVars + sequencerInboxMaxTimeVariation: timeVars, + espressoTEEVerifier: address(espressoTEEVerifier) }); // prepare funds @@ -463,18 +480,6 @@ contract RollupCreatorTest is Test { validators[0] = makeAddr("validator1"); validators[1] = makeAddr("validator2"); - EspressoTEEVerifierTest espressoTEEVerifierImplementation = new EspressoTEEVerifierTest(); - - EspressoTEEVerifierTest espressoTEEVerifier = EspressoTEEVerifierTest( - address( - new TransparentUpgradeableProxy( - address(espressoTEEVerifierImplementation), - proxyAdminEspresso, - "" - ) - ) - ); - espressoTEEVerifier.initialize(address(0)); RollupCreator.RollupDeploymentParams memory deployParams = RollupCreator .RollupDeploymentParams({ config: config, @@ -484,8 +489,7 @@ contract RollupCreatorTest is Test { nativeToken: address(0), deployFactoriesToL2: true, maxFeePerGasForRetryables: MAX_FEE_PER_GAS, - batchPosterManager: batchPosterManager, - espressoTEEVerifier: address(espressoTEEVerifier) + batchPosterManager: batchPosterManager }); address rollupAddress = rollupCreator.createRollup{value: factoryDeploymentFunds}( deployParams