From 3478fa971d49949d7bdab336d7d96d8ff643ad5d Mon Sep 17 00:00:00 2001 From: Bence Haromi Date: Mon, 2 Oct 2023 13:12:43 +0100 Subject: [PATCH] test: temporarily removing DiamondCut and Executor foundry tests --- .../unit/concrete/DiamondCut/FacetCut.t.sol | 379 ----------- .../concrete/DiamondCut/Initialization.t.sol | 77 --- .../concrete/DiamondCut/UpgradeLogic.t.sol | 422 ------------ .../DiamondCut/_DiamondCut_Shared.t.sol | 52 -- .../concrete/Executor/Authorization.t.sol | 69 -- .../unit/concrete/Executor/Committing.t.sol | 618 ------------------ .../unit/concrete/Executor/Executing.t.sol | 247 ------- .../unit/concrete/Executor/Proving.t.sol | 96 --- .../unit/concrete/Executor/Reverting.t.sol | 75 --- .../concrete/Executor/_Executor_Shared.t.sol | 220 ------- 10 files changed, 2255 deletions(-) delete mode 100644 ethereum/test/foundry/unit/concrete/DiamondCut/FacetCut.t.sol delete mode 100644 ethereum/test/foundry/unit/concrete/DiamondCut/Initialization.t.sol delete mode 100644 ethereum/test/foundry/unit/concrete/DiamondCut/UpgradeLogic.t.sol delete mode 100644 ethereum/test/foundry/unit/concrete/DiamondCut/_DiamondCut_Shared.t.sol delete mode 100644 ethereum/test/foundry/unit/concrete/Executor/Authorization.t.sol delete mode 100644 ethereum/test/foundry/unit/concrete/Executor/Committing.t.sol delete mode 100644 ethereum/test/foundry/unit/concrete/Executor/Executing.t.sol delete mode 100644 ethereum/test/foundry/unit/concrete/Executor/Proving.t.sol delete mode 100644 ethereum/test/foundry/unit/concrete/Executor/Reverting.t.sol delete mode 100644 ethereum/test/foundry/unit/concrete/Executor/_Executor_Shared.t.sol diff --git a/ethereum/test/foundry/unit/concrete/DiamondCut/FacetCut.t.sol b/ethereum/test/foundry/unit/concrete/DiamondCut/FacetCut.t.sol deleted file mode 100644 index 6e1eb435ca..0000000000 --- a/ethereum/test/foundry/unit/concrete/DiamondCut/FacetCut.t.sol +++ /dev/null @@ -1,379 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.17; - -// solhint-disable max-line-length - -import {DiamondCutTest} from "./_DiamondCut_Shared.t.sol"; -import {DiamondCutTestContract} from "../../../../../cache/solpp-generated-contracts/dev-contracts/test/DiamondCutTestContract.sol"; -import {ExecutorFacet} from "../../../../../cache/solpp-generated-contracts/zksync/facets/Executor.sol"; -import {GettersFacet} from "../../../../../cache/solpp-generated-contracts/zksync/facets/Getters.sol"; -import {MailboxFacet} from "../../../../../cache/solpp-generated-contracts/zksync/facets/Mailbox.sol"; -import {Diamond} from "../../../../../cache/solpp-generated-contracts/zksync/libraries/Diamond.sol"; - -// solhint-enable max-line-length - -contract FacetCutTest is DiamondCutTest { - MailboxFacet private mailboxFacet; - ExecutorFacet private executorFacet1; - ExecutorFacet private executorFacet2; - - function getMailboxSelectors() private view returns (bytes4[] memory) { - bytes4[] memory selectors = new bytes4[](6); - selectors[0] = mailboxFacet.proveL2MessageInclusion.selector; - selectors[1] = mailboxFacet.proveL2LogInclusion.selector; - selectors[2] = mailboxFacet.proveL1ToL2TransactionStatus.selector; - selectors[3] = mailboxFacet.finalizeEthWithdrawal.selector; - selectors[4] = mailboxFacet.requestL2Transaction.selector; - selectors[5] = mailboxFacet.l2TransactionBaseCost.selector; - return selectors; - } - - function getExecutorSelectors() private view returns (bytes4[] memory) { - bytes4[] memory selectors = new bytes4[](4); - selectors[0] = executorFacet1.commitBlocks.selector; - selectors[1] = executorFacet1.proveBlocks.selector; - selectors[2] = executorFacet1.executeBlocks.selector; - selectors[3] = executorFacet1.revertBlocks.selector; - return selectors; - } - - function setUp() public { - diamondCutTestContract = new DiamondCutTestContract(); - mailboxFacet = new MailboxFacet(); - gettersFacet = new GettersFacet(); - executorFacet1 = new ExecutorFacet(); - executorFacet2 = new ExecutorFacet(); - } - - function test_AddingFacetsToFreeSelectors() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](3); - facetCuts[0] = Diamond.FacetCut({ - facet: address(mailboxFacet), - action: Diamond.Action.Add, - isFreezable: false, - selectors: getMailboxSelectors() - }); - facetCuts[1] = Diamond.FacetCut({ - facet: address(gettersFacet), - action: Diamond.Action.Add, - isFreezable: false, - selectors: getGettersSelectors() - }); - facetCuts[2] = Diamond.FacetCut({ - facet: address(executorFacet1), - action: Diamond.Action.Add, - isFreezable: false, - selectors: getExecutorSelectors() - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: 0x0000000000000000000000000000000000000000, - initCalldata: bytes("") - }); - - uint256 numOfFacetsBefore = diamondCutTestContract.facetAddresses().length; - - diamondCutTestContract.diamondCut(diamondCutData); - - uint256 numOfFacetsAfter = diamondCutTestContract.facetAddresses().length; - - assertEq(numOfFacetsBefore + facetCuts.length, numOfFacetsAfter, "wrong number of facets added"); - } - - function test_RevertWhen_AddingFacetToOccupiedSelector() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](1); - facetCuts[0] = Diamond.FacetCut({ - facet: address(mailboxFacet), - action: Diamond.Action.Add, - isFreezable: false, - selectors: getMailboxSelectors() - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - diamondCutTestContract.diamondCut(diamondCutData); - - vm.expectRevert(abi.encodePacked("J")); - diamondCutTestContract.diamondCut(diamondCutData); - } - - function test_RevertWhen_AddingFacetWithZeroAddress() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](1); - facetCuts[0] = Diamond.FacetCut({ - facet: address(0), - action: Diamond.Action.Add, - isFreezable: false, - selectors: getMailboxSelectors() - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - vm.expectRevert(abi.encodePacked("G")); - diamondCutTestContract.diamondCut(diamondCutData); - } - - function test_RevertWhen_ReplacingFacetFromFreeSelector() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](1); - facetCuts[0] = Diamond.FacetCut({ - facet: address(mailboxFacet), - action: Diamond.Action.Replace, - isFreezable: false, - selectors: getMailboxSelectors() - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - vm.expectRevert(abi.encodePacked("L")); - diamondCutTestContract.diamondCut(diamondCutData); - } - - function test_RevertWhen_RemovingFacetFromFreeSelector() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](1); - facetCuts[0] = Diamond.FacetCut({ - facet: address(mailboxFacet), - action: Diamond.Action.Remove, - isFreezable: false, - selectors: getMailboxSelectors() - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - vm.expectRevert(abi.encodePacked("a1")); - diamondCutTestContract.diamondCut(diamondCutData); - } - - function test_ReplaceFacetForOccupiedSelector() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](2); - facetCuts[0] = Diamond.FacetCut({ - facet: address(executorFacet1), - action: Diamond.Action.Add, - isFreezable: false, - selectors: getExecutorSelectors() - }); - facetCuts[1] = Diamond.FacetCut({ - facet: address(executorFacet2), - action: Diamond.Action.Replace, - isFreezable: false, - selectors: getExecutorSelectors() - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - diamondCutTestContract.diamondCut(diamondCutData); - } - - function test_RemovingFacetFromOccupiedSelector() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](2); - facetCuts[0] = Diamond.FacetCut({ - facet: address(mailboxFacet), - action: Diamond.Action.Add, - isFreezable: false, - selectors: getMailboxSelectors() - }); - facetCuts[1] = Diamond.FacetCut({ - facet: address(0), - action: Diamond.Action.Remove, - isFreezable: false, - selectors: getMailboxSelectors() - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - diamondCutTestContract.diamondCut(diamondCutData); - } - - function test_AddingFacetAfterRemoving() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](3); - facetCuts[0] = Diamond.FacetCut({ - facet: address(mailboxFacet), - action: Diamond.Action.Add, - isFreezable: false, - selectors: getMailboxSelectors() - }); - facetCuts[1] = Diamond.FacetCut({ - facet: address(0), - action: Diamond.Action.Remove, - isFreezable: false, - selectors: getMailboxSelectors() - }); - facetCuts[2] = Diamond.FacetCut({ - facet: address(mailboxFacet), - action: Diamond.Action.Add, - isFreezable: false, - selectors: getMailboxSelectors() - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - diamondCutTestContract.diamondCut(diamondCutData); - } - - function test_ReplacingASelectorFacetWithItself() public { - bytes4[] memory selectors = new bytes4[](1); - selectors[0] = 0x00000005; - - Diamond.FacetCut[] memory facetCuts1 = new Diamond.FacetCut[](1); - facetCuts1[0] = Diamond.FacetCut({ - facet: address(0x000000000000000000000000000000000000000A), - action: Diamond.Action.Add, - isFreezable: true, - selectors: selectors - }); - - Diamond.DiamondCutData memory diamondCutData1 = Diamond.DiamondCutData({ - facetCuts: facetCuts1, - initAddress: address(0), - initCalldata: bytes("") - }); - - diamondCutTestContract.diamondCut(diamondCutData1); - - uint256 numOfFacetsAfterAdd = diamondCutTestContract.facetAddresses().length; - - Diamond.FacetCut[] memory facetCuts2 = new Diamond.FacetCut[](1); - facetCuts2[0] = Diamond.FacetCut({ - facet: address(0x000000000000000000000000000000000000000A), - action: Diamond.Action.Replace, - isFreezable: false, - selectors: selectors - }); - - Diamond.DiamondCutData memory diamondCutData2 = Diamond.DiamondCutData({ - facetCuts: facetCuts2, - initAddress: address(0), - initCalldata: bytes("") - }); - - diamondCutTestContract.diamondCut(diamondCutData2); - - uint256 numOfFacetsAfterReplace = diamondCutTestContract.facetAddresses().length; - - assertEq(numOfFacetsAfterAdd, numOfFacetsAfterReplace); - } - - function test_RevertWhen_AddingFacetWithDifferentFreezabilityThanExistingFacets() public { - bytes4[] memory selectors1 = new bytes4[](1); - selectors1[0] = 0x00000001; - - bytes4[] memory selectors2 = new bytes4[](1); - selectors2[0] = 0x00000002; - - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](2); - facetCuts[0] = Diamond.FacetCut({ - facet: address(mailboxFacet), - action: Diamond.Action.Add, - isFreezable: false, - selectors: selectors1 - }); - facetCuts[1] = Diamond.FacetCut({ - facet: address(mailboxFacet), - action: Diamond.Action.Add, - isFreezable: true, - selectors: selectors2 - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - vm.expectRevert(abi.encodePacked("J1")); - diamondCutTestContract.diamondCut(diamondCutData); - } - - function test_RevertWhen_ReplacingFacetWithDifferentFreezabilityThanExistingFacets() public { - bytes4[] memory selectors1 = new bytes4[](1); - selectors1[0] = 0x00000001; - bytes4[] memory selectors2 = new bytes4[](1); - selectors2[0] = 0x00000002; - - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](3); - facetCuts[0] = Diamond.FacetCut({ - facet: address(mailboxFacet), - action: Diamond.Action.Add, - isFreezable: false, - selectors: selectors1 - }); - facetCuts[1] = Diamond.FacetCut({ - facet: address(mailboxFacet), - action: Diamond.Action.Add, - isFreezable: false, - selectors: selectors2 - }); - facetCuts[2] = Diamond.FacetCut({ - facet: address(mailboxFacet), - action: Diamond.Action.Replace, - isFreezable: true, - selectors: selectors2 - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - vm.expectRevert(abi.encodePacked("J1")); - diamondCutTestContract.diamondCut(diamondCutData); - } - - function test_ChangingFacetFreezability() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](3); - facetCuts[0] = Diamond.FacetCut({ - facet: address(mailboxFacet), - action: Diamond.Action.Add, - isFreezable: false, - selectors: getMailboxSelectors() - }); - facetCuts[1] = Diamond.FacetCut({ - facet: address(0), - action: Diamond.Action.Remove, - isFreezable: false, - selectors: getMailboxSelectors() - }); - facetCuts[2] = Diamond.FacetCut({ - facet: address(mailboxFacet), - action: Diamond.Action.Add, - isFreezable: true, - selectors: getMailboxSelectors() - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - diamondCutTestContract.diamondCut(diamondCutData); - } -} diff --git a/ethereum/test/foundry/unit/concrete/DiamondCut/Initialization.t.sol b/ethereum/test/foundry/unit/concrete/DiamondCut/Initialization.t.sol deleted file mode 100644 index 5606f8620c..0000000000 --- a/ethereum/test/foundry/unit/concrete/DiamondCut/Initialization.t.sol +++ /dev/null @@ -1,77 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.17; - -// solhint-disable max-line-length - -import {DiamondCutTest} from "./_DiamondCut_Shared.t.sol"; -import {RevertFallback} from "../../../../../cache/solpp-generated-contracts/dev-contracts/RevertFallback.sol"; -import {ReturnSomething} from "../../../../../cache/solpp-generated-contracts/dev-contracts/ReturnSomething.sol"; -import {DiamondCutTestContract} from "../../../../../cache/solpp-generated-contracts/dev-contracts/test/DiamondCutTestContract.sol"; -import {Diamond} from "../../../../../cache/solpp-generated-contracts/zksync/libraries/Diamond.sol"; - -// solhint-enable max-line-length - -contract InitializationTest is DiamondCutTest { - address private revertFallbackAddress; - address private returnSomethingAddress; - address private signerAddress; // EOA - - function setUp() public { - signerAddress = makeAddr("signer"); - diamondCutTestContract = new DiamondCutTestContract(); - revertFallbackAddress = address(new RevertFallback()); - returnSomethingAddress = address(new ReturnSomething()); - } - - function test_RevertWhen_DelegateCallToFailedContract() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](0); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: revertFallbackAddress, - initCalldata: bytes("") - }); - - vm.expectRevert(abi.encodePacked("I")); - diamondCutTestContract.diamondCut(diamondCutData); - } - - function test_ReverWhen_DelegateCallToEOA() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](0); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: signerAddress, - initCalldata: bytes("") - }); - - vm.expectRevert(abi.encodePacked("lp")); - diamondCutTestContract.diamondCut(diamondCutData); - } - - function test_RevertWhen_InitializingDiamondCutWithZeroAddressAndNonZeroData() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](0); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("0x11") - }); - - vm.expectRevert(abi.encodePacked("H")); - diamondCutTestContract.diamondCut(diamondCutData); - } - - function test_RevertWhen_DelegateCallToAContractWithWrongReturn() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](0); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: returnSomethingAddress, - initCalldata: bytes("") - }); - - vm.expectRevert(abi.encodePacked("lp1")); - diamondCutTestContract.diamondCut(diamondCutData); - } -} diff --git a/ethereum/test/foundry/unit/concrete/DiamondCut/UpgradeLogic.t.sol b/ethereum/test/foundry/unit/concrete/DiamondCut/UpgradeLogic.t.sol deleted file mode 100644 index b3dcfde07c..0000000000 --- a/ethereum/test/foundry/unit/concrete/DiamondCut/UpgradeLogic.t.sol +++ /dev/null @@ -1,422 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.17; - -// solhint-disable max-line-length - -import {DiamondCutTest} from "./_DiamondCut_Shared.t.sol"; -import {Utils} from "../Utils/Utils.sol"; -import {DiamondCutTestContract} from "../../../../../cache/solpp-generated-contracts/dev-contracts/test/DiamondCutTestContract.sol"; -import {DiamondInit} from "../../../../../cache/solpp-generated-contracts/zksync/DiamondInit.sol"; -import {DiamondProxy} from "../../../../../cache/solpp-generated-contracts/zksync/DiamondProxy.sol"; -import {VerifierParams} from "../../../../../cache/solpp-generated-contracts/zksync/Storage.sol"; -import {DiamondCutFacet} from "../../../../../cache/solpp-generated-contracts/zksync/facets/DiamondCut.sol"; -import {GettersFacet} from "../../../../../cache/solpp-generated-contracts/zksync/facets/Getters.sol"; -import {Diamond} from "../../../../../cache/solpp-generated-contracts/zksync/libraries/Diamond.sol"; - -// solhint-enable max-line-length - -contract UpgradeLogicTest is DiamondCutTest { - DiamondProxy private diamondProxy; - DiamondInit private diamondInit; - DiamondCutFacet private diamondCutFacet; - DiamondCutFacet private proxyAsDiamondCut; - GettersFacet private proxyAsGetters; - address private governor; - address private randomSigner; - - function getDiamondCutSelectors() private view returns (bytes4[] memory) { - bytes4[] memory dcSelectors = new bytes4[](8); - dcSelectors[0] = diamondCutFacet.proposeTransparentUpgrade.selector; - dcSelectors[1] = diamondCutFacet.proposeShadowUpgrade.selector; - dcSelectors[2] = diamondCutFacet.cancelUpgradeProposal.selector; - dcSelectors[3] = diamondCutFacet.securityCouncilUpgradeApprove.selector; - dcSelectors[4] = diamondCutFacet.executeUpgrade.selector; - dcSelectors[5] = diamondCutFacet.freezeDiamond.selector; - dcSelectors[6] = diamondCutFacet.unfreezeDiamond.selector; - dcSelectors[7] = diamondCutFacet.upgradeProposalHash.selector; - return dcSelectors; - } - - function setUp() public { - governor = makeAddr("governor"); - randomSigner = makeAddr("randomSigner"); - - diamondCutTestContract = new DiamondCutTestContract(); - diamondInit = new DiamondInit(); - diamondCutFacet = new DiamondCutFacet(); - gettersFacet = new GettersFacet(); - - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](2); - facetCuts[0] = Diamond.FacetCut({ - facet: address(diamondCutFacet), - action: Diamond.Action.Add, - isFreezable: false, - selectors: getDiamondCutSelectors() - }); - facetCuts[1] = Diamond.FacetCut({ - facet: address(gettersFacet), - action: Diamond.Action.Add, - isFreezable: true, - selectors: getGettersSelectors() - }); - - VerifierParams memory dummyVerifierParams = VerifierParams({ - recursionNodeLevelVkHash: 0, - recursionLeafLevelVkHash: 0, - recursionCircuitsSetVksHash: 0 - }); - - bytes memory diamondInitCalldata = abi.encodeWithSelector( - diamondInit.initialize.selector, - 0x03752D8252d67f99888E741E3fB642803B29B155, - governor, - 0x02c775f0a90abf7a0e8043f2fdc38f0580ca9f9996a895d05a501bfeaa3b2e21, - 0, - 0x0000000000000000000000000000000000000000000000000000000000000000, - 0x70a0F165d6f8054d0d0CF8dFd4DD2005f0AF6B55, - dummyVerifierParams, - false, - 0x0100000000000000000000000000000000000000000000000000000000000000, - 0x0100000000000000000000000000000000000000000000000000000000000000, - 500000 // priority tx max L2 gas limit - ); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(diamondInit), - initCalldata: diamondInitCalldata - }); - - diamondProxy = new DiamondProxy(block.chainid, diamondCutData); - proxyAsDiamondCut = DiamondCutFacet(address(diamondProxy)); - proxyAsGetters = GettersFacet(address(diamondProxy)); - } - - function test_RevertWhen_EmergencyFreezeWhenUnauthurizedGovernor() public { - vm.startPrank(randomSigner); - - vm.expectRevert(abi.encodePacked("1g")); - proxyAsDiamondCut.freezeDiamond(); - } - - function test_RevertWhen_DoubleFreezingByGovernor() public { - vm.startPrank(governor); - - proxyAsDiamondCut.freezeDiamond(); - - vm.expectRevert(abi.encodePacked("a9")); - proxyAsDiamondCut.freezeDiamond(); - } - - function test_RevertWhen_UnfreezingWhenNotFrozen() public { - vm.startPrank(governor); - - vm.expectRevert(abi.encodePacked("a7")); - proxyAsDiamondCut.unfreezeDiamond(); - } - - function test_RevertWhen_ExecutingUnapprovedProposalWHenDiamondStorageIsFrozen() public { - vm.startPrank(governor); - - proxyAsDiamondCut.freezeDiamond(); - - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](1); - facetCuts[0] = Diamond.FacetCut({ - facet: address(gettersFacet), - action: Diamond.Action.Replace, - isFreezable: true, - selectors: getGettersSelectors() - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - proxyAsDiamondCut.proposeTransparentUpgrade(diamondCutData, 1); - - vm.expectRevert(abi.encodePacked("f3")); - proxyAsDiamondCut.executeUpgrade(diamondCutData, 0); - } - - function test_RevertWhen_ExecutingProposalWithDifferentInitAddress() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](1); - facetCuts[0] = Diamond.FacetCut({ - facet: address(gettersFacet), - action: Diamond.Action.Add, - isFreezable: true, - selectors: getGettersSelectors() - }); - - Diamond.DiamondCutData memory proposedDiamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - Diamond.DiamondCutData memory executedDiamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(1), - initCalldata: bytes("") - }); - - uint40 nextProposalId = uint40(proxyAsGetters.getCurrentProposalId() + 1); - - vm.startPrank(governor); - - proxyAsDiamondCut.proposeTransparentUpgrade(proposedDiamondCutData, nextProposalId); - - vm.expectRevert(abi.encodePacked("a4")); - proxyAsDiamondCut.executeUpgrade(executedDiamondCutData, 0); - } - - function test_RevertWhen_ExecutingProposalWithDifferentFacetCut() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](1); - facetCuts[0] = Diamond.FacetCut({ - facet: address(gettersFacet), - action: Diamond.Action.Replace, - isFreezable: true, - selectors: getGettersSelectors() - }); - - Diamond.FacetCut[] memory invalidFacetCuts = new Diamond.FacetCut[](1); - invalidFacetCuts[0] = Diamond.FacetCut({ - facet: address(gettersFacet), - action: Diamond.Action.Replace, - isFreezable: false, - selectors: getGettersSelectors() - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - Diamond.DiamondCutData memory invalidDiamondCutData = Diamond.DiamondCutData({ - facetCuts: invalidFacetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - uint40 nextProposalId = uint40(proxyAsGetters.getCurrentProposalId() + 1); - - vm.startPrank(governor); - proxyAsDiamondCut.proposeTransparentUpgrade(diamondCutData, nextProposalId); - - vm.expectRevert(abi.encodePacked("a4")); - proxyAsDiamondCut.executeUpgrade(invalidDiamondCutData, 0); - } - - function test_RevertWhen_CancelingEmptyProposal() public { - bytes32 proposalHash = proxyAsGetters.getProposedUpgradeHash(); - - vm.startPrank(governor); - - vm.expectRevert(abi.encodePacked("a3")); - proxyAsDiamondCut.cancelUpgradeProposal(proposalHash); - } - - function test_ProposeAndExecuteDiamondCut() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](1); - facetCuts[0] = Diamond.FacetCut({ - facet: address(gettersFacet), - action: Diamond.Action.Replace, - isFreezable: true, - selectors: getGettersSelectors() - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - uint40 nextProposalId = uint40(proxyAsGetters.getCurrentProposalId() + 1); - - vm.startPrank(governor); - - proxyAsDiamondCut.proposeTransparentUpgrade(diamondCutData, nextProposalId); - - proxyAsDiamondCut.executeUpgrade(diamondCutData, 0); - - bytes4[] memory gettersFacetSelectors = getGettersSelectors(); - for (uint256 i = 0; i < gettersFacetSelectors.length; i++) { - bytes4 selector = gettersFacetSelectors[i]; - - address addr = proxyAsGetters.facetAddress(selector); - assertEq(addr, address(gettersFacet), "facet address mismatch"); - - bool isFreezable = proxyAsGetters.isFunctionFreezable(selector); - assertTrue(isFreezable, "isFreezable mismatch"); - } - } - - function test_RevertWhen_ExecutingSameProposalTwoTimes() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](1); - facetCuts[0] = Diamond.FacetCut({ - facet: address(gettersFacet), - action: Diamond.Action.Replace, - isFreezable: true, - selectors: getGettersSelectors() - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - uint40 nextProposalId = uint40(proxyAsGetters.getCurrentProposalId() + 1); - - vm.startPrank(governor); - - proxyAsDiamondCut.proposeTransparentUpgrade(diamondCutData, nextProposalId); - - proxyAsDiamondCut.executeUpgrade(diamondCutData, 0); - - vm.expectRevert(abi.encodePacked("ab")); - proxyAsDiamondCut.executeUpgrade(diamondCutData, 0); - } - - function test_RevertWhen_ProposingAnAlreadyPropsedUpgrade() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](1); - facetCuts[0] = Diamond.FacetCut({ - facet: address(gettersFacet), - action: Diamond.Action.Replace, - isFreezable: true, - selectors: getGettersSelectors() - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - uint40 nextProposalId = uint40(proxyAsGetters.getCurrentProposalId() + 1); - - vm.startPrank(governor); - - proxyAsDiamondCut.proposeTransparentUpgrade(diamondCutData, nextProposalId); - - vm.expectRevert(abi.encodePacked("a8")); - proxyAsDiamondCut.proposeTransparentUpgrade(diamondCutData, nextProposalId); - } - - function test_RevertWhen_ExecutingUnapprovedShadowUpgrade() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](1); - facetCuts[0] = Diamond.FacetCut({ - facet: address(gettersFacet), - action: Diamond.Action.Replace, - isFreezable: true, - selectors: getGettersSelectors() - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - uint40 nextProposalId = uint40(proxyAsGetters.getCurrentProposalId() + 1); - - vm.startPrank(governor); - - bytes32 executingProposalHash = proxyAsDiamondCut.upgradeProposalHash(diamondCutData, nextProposalId, 0); - - proxyAsDiamondCut.proposeShadowUpgrade(executingProposalHash, nextProposalId); - - vm.expectRevert(abi.encodePacked("av")); - proxyAsDiamondCut.executeUpgrade(diamondCutData, 0); - } - - function test_RevertWhen_ProposingShadowUpgradeWithWrongProposalId() public { - uint40 nextProposalId = uint40(proxyAsGetters.getCurrentProposalId() + 1); - - vm.startPrank(governor); - - bytes32 porposalHash = Utils.randomBytes32("porposalHash"); - - vm.expectRevert(abi.encodePacked("ya")); - proxyAsDiamondCut.proposeShadowUpgrade(porposalHash, nextProposalId + 1); - } - - function test_RevertWhen_ProposingTransparentUpgradeWithWrongProposalId() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](1); - facetCuts[0] = Diamond.FacetCut({ - facet: address(gettersFacet), - action: Diamond.Action.Replace, - isFreezable: true, - selectors: getGettersSelectors() - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - uint40 currentProposalId = uint40(proxyAsGetters.getCurrentProposalId()); - - vm.startPrank(governor); - - vm.expectRevert(abi.encodePacked("yb")); - proxyAsDiamondCut.proposeTransparentUpgrade(diamondCutData, currentProposalId); - } - - function test_RevertWhen_CancellingUpgradeProposalWithWrongHash() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](1); - facetCuts[0] = Diamond.FacetCut({ - facet: address(gettersFacet), - action: Diamond.Action.Replace, - isFreezable: true, - selectors: getGettersSelectors() - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - uint40 nextProposalId = uint40(proxyAsGetters.getCurrentProposalId() + 1); - - vm.startPrank(governor); - - proxyAsDiamondCut.proposeTransparentUpgrade(diamondCutData, nextProposalId); - - bytes32 proposedUpgradeHash = Utils.randomBytes32("proposedUpgradeHash"); - - vm.expectRevert(abi.encodePacked("rx")); - proxyAsDiamondCut.cancelUpgradeProposal(proposedUpgradeHash); - } - - function test_RevertWhen_ExecutingTransparentUpgradeWithNonZeroSalt() public { - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](1); - facetCuts[0] = Diamond.FacetCut({ - facet: address(gettersFacet), - action: Diamond.Action.Replace, - isFreezable: true, - selectors: getGettersSelectors() - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(0), - initCalldata: bytes("") - }); - - uint40 nextProposalId = uint40(proxyAsGetters.getCurrentProposalId() + 1); - - vm.startPrank(governor); - - proxyAsDiamondCut.proposeTransparentUpgrade(diamondCutData, nextProposalId); - - bytes32 proposalSalt = Utils.randomBytes32("proposalSalt"); - - vm.expectRevert(abi.encodePacked("po")); - proxyAsDiamondCut.executeUpgrade(diamondCutData, proposalSalt); - } -} diff --git a/ethereum/test/foundry/unit/concrete/DiamondCut/_DiamondCut_Shared.t.sol b/ethereum/test/foundry/unit/concrete/DiamondCut/_DiamondCut_Shared.t.sol deleted file mode 100644 index a662c15361..0000000000 --- a/ethereum/test/foundry/unit/concrete/DiamondCut/_DiamondCut_Shared.t.sol +++ /dev/null @@ -1,52 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.17; - -// solhint-disable max-line-length - -import {Test} from "forge-std/Test.sol"; -import {DiamondCutTestContract} from "../../../../../cache/solpp-generated-contracts/dev-contracts/test/DiamondCutTestContract.sol"; -import {GettersFacet} from "../../../../../cache/solpp-generated-contracts/zksync/facets/Getters.sol"; - -// solhint-enable max-line-length - -contract DiamondCutTest is Test { - DiamondCutTestContract internal diamondCutTestContract; - GettersFacet internal gettersFacet; - - function getGettersSelectors() public view returns (bytes4[] memory) { - bytes4[] memory selectors = new bytes4[](32); - selectors[0] = gettersFacet.getVerifier.selector; - selectors[1] = gettersFacet.getGovernor.selector; - selectors[2] = gettersFacet.getPendingGovernor.selector; - selectors[3] = gettersFacet.getTotalBlocksCommitted.selector; - selectors[4] = gettersFacet.getTotalBlocksVerified.selector; - selectors[5] = gettersFacet.getTotalBlocksExecuted.selector; - selectors[6] = gettersFacet.getTotalPriorityTxs.selector; - selectors[7] = gettersFacet.getFirstUnprocessedPriorityTx.selector; - selectors[8] = gettersFacet.getPriorityQueueSize.selector; - selectors[9] = gettersFacet.priorityQueueFrontOperation.selector; - selectors[10] = gettersFacet.isValidator.selector; - selectors[11] = gettersFacet.l2LogsRootHash.selector; - selectors[12] = gettersFacet.storedBlockHash.selector; - selectors[13] = gettersFacet.getL2BootloaderBytecodeHash.selector; - selectors[14] = gettersFacet.getL2DefaultAccountBytecodeHash.selector; - selectors[15] = gettersFacet.getVerifierParams.selector; - selectors[16] = gettersFacet.isDiamondStorageFrozen.selector; - selectors[17] = gettersFacet.getSecurityCouncil.selector; - selectors[18] = gettersFacet.getUpgradeProposalState.selector; - selectors[19] = gettersFacet.getProposedUpgradeHash.selector; - selectors[20] = gettersFacet.getProposedUpgradeTimestamp.selector; - selectors[21] = gettersFacet.getCurrentProposalId.selector; - selectors[22] = gettersFacet.isApprovedBySecurityCouncil.selector; - selectors[23] = gettersFacet.getPriorityTxMaxGasLimit.selector; - selectors[24] = gettersFacet.getAllowList.selector; - selectors[25] = gettersFacet.isEthWithdrawalFinalized.selector; - selectors[26] = gettersFacet.facets.selector; - selectors[27] = gettersFacet.facetFunctionSelectors.selector; - selectors[28] = gettersFacet.facetAddresses.selector; - selectors[29] = gettersFacet.facetAddress.selector; - selectors[30] = gettersFacet.isFunctionFreezable.selector; - selectors[31] = gettersFacet.isFacetFreezable.selector; - return selectors; - } -} diff --git a/ethereum/test/foundry/unit/concrete/Executor/Authorization.t.sol b/ethereum/test/foundry/unit/concrete/Executor/Authorization.t.sol deleted file mode 100644 index df8542c6a6..0000000000 --- a/ethereum/test/foundry/unit/concrete/Executor/Authorization.t.sol +++ /dev/null @@ -1,69 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.17; - -import {ExecutorTest} from "./_Executor_Shared.t.sol"; -import {Utils} from "../Utils/Utils.sol"; -import {IExecutor} from "../../../../../cache/solpp-generated-contracts/zksync/interfaces/IExecutor.sol"; - -contract AuthorizationTest is ExecutorTest { - IExecutor.StoredBlockInfo private storedBlockInfo; - IExecutor.CommitBlockInfo private commitBlockInfo; - - function setUp() public { - storedBlockInfo = IExecutor.StoredBlockInfo({ - blockNumber: 1, - blockHash: Utils.randomBytes32("blockHash"), - indexRepeatedStorageChanges: 0, - numberOfLayer1Txs: 0, - priorityOperationsHash: keccak256(""), - l2LogsTreeRoot: Utils.randomBytes32("l2LogsTreeRoot"), - timestamp: 0, - commitment: Utils.randomBytes32("commitment") - }); - - commitBlockInfo = IExecutor.CommitBlockInfo({ - blockNumber: 0, - timestamp: 0, - indexRepeatedStorageChanges: 0, - newStateRoot: Utils.randomBytes32("newStateRoot"), - numberOfLayer1Txs: 0, - l2LogsTreeRoot: Utils.randomBytes32("l2LogsTreeRoot"), - priorityOperationsHash: keccak256(""), - initialStorageChanges: bytes(""), - repeatedStorageChanges: bytes(""), - l2Logs: bytes(""), - l2ArbitraryLengthMessages: new bytes[](0), - factoryDeps: new bytes[](0) - }); - } - - function test_RevertWhen_CommitingByUnauthorisedAddress() public { - IExecutor.CommitBlockInfo[] memory commitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - commitBlockInfoArray[0] = commitBlockInfo; - - vm.prank(randomSigner); - - vm.expectRevert(bytes.concat("1h")); - executor.commitBlocks(storedBlockInfo, commitBlockInfoArray); - } - - function test_RevertWhen_ProvingByUnauthorisedAddress() public { - IExecutor.StoredBlockInfo[] memory storedBlockInfoArray = new IExecutor.StoredBlockInfo[](1); - storedBlockInfoArray[0] = storedBlockInfo; - - vm.prank(owner); - - vm.expectRevert(bytes.concat("1h")); - executor.proveBlocks(storedBlockInfo, storedBlockInfoArray, proofInput); - } - - function test_RevertWhen_ExecutingByUnauthorizedAddress() public { - IExecutor.StoredBlockInfo[] memory storedBlockInfoArray = new IExecutor.StoredBlockInfo[](1); - storedBlockInfoArray[0] = storedBlockInfo; - - vm.prank(randomSigner); - - vm.expectRevert(bytes.concat("1h")); - executor.executeBlocks(storedBlockInfoArray); - } -} diff --git a/ethereum/test/foundry/unit/concrete/Executor/Committing.t.sol b/ethereum/test/foundry/unit/concrete/Executor/Committing.t.sol deleted file mode 100644 index b07c59062c..0000000000 --- a/ethereum/test/foundry/unit/concrete/Executor/Committing.t.sol +++ /dev/null @@ -1,618 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.17; - -import {Vm} from "forge-std/Test.sol"; -import {ExecutorTest} from "./_Executor_Shared.t.sol"; -import {Utils} from "../Utils/Utils.sol"; -import {L2_BOOTLOADER_ADDRESS} from "../../../../../cache/solpp-generated-contracts/common/L2ContractAddresses.sol"; -import {IExecutor} from "../../../../../cache/solpp-generated-contracts/zksync/interfaces/IExecutor.sol"; - -contract CommittingTest is ExecutorTest { - function test_RevertWhen_ComittingWithWrongLastCommittedBlockData() public { - IExecutor.CommitBlockInfo[] memory newCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - newCommitBlockInfoArray[0] = newCommitBlockInfo; - - IExecutor.StoredBlockInfo memory wrongGenesisStoredBlockInfo = genesisStoredBlockInfo; - wrongGenesisStoredBlockInfo.timestamp = 1000; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("i")); - executor.commitBlocks(wrongGenesisStoredBlockInfo, newCommitBlockInfoArray); - } - - function test_RevertWhen_ComittingWithWrongOrderOfBlocks() public { - IExecutor.CommitBlockInfo memory wrongNewCommitBlockInfo = newCommitBlockInfo; - wrongNewCommitBlockInfo.blockNumber = 2; // wrong block number - - IExecutor.CommitBlockInfo[] memory wrongNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - wrongNewCommitBlockInfoArray[0] = wrongNewCommitBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("f")); - executor.commitBlocks(genesisStoredBlockInfo, wrongNewCommitBlockInfoArray); - } - - function test_RevertWhen_CommittingWithWrongNewBlockTimestamp() public { - bytes32 wrongNewBlockTimestamp = Utils.randomBytes32("wrongNewBlockTimestamp"); - bytes memory wrongL2Logs = abi.encodePacked( - bytes4(0x00000001), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - wrongNewBlockTimestamp, - bytes32("") - ); - - IExecutor.CommitBlockInfo memory wrongNewCommitBlockInfo = newCommitBlockInfo; - wrongNewCommitBlockInfo.l2Logs = wrongL2Logs; - - IExecutor.CommitBlockInfo[] memory wrongNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - wrongNewCommitBlockInfoArray[0] = wrongNewCommitBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("tb")); - executor.commitBlocks(genesisStoredBlockInfo, wrongNewCommitBlockInfoArray); - } - - function test_RevertWhen_CommittingWithTooSmallNewBlockTimestamp() public { - bytes memory wrongL2Logs = abi.encodePacked( - bytes4(0x00000001), - bytes4(0x00000000), - address(L2_SYSTEM_CONTEXT_ADDRESS), - Utils.packBatchTimestampAndBlockTimestamp(1, 1), - bytes32("") - ); - - IExecutor.CommitBlockInfo memory wrongNewCommitBlockInfo = newCommitBlockInfo; - wrongNewCommitBlockInfo.l2Logs = wrongL2Logs; - wrongNewCommitBlockInfo.timestamp = 1; // too small - - IExecutor.CommitBlockInfo[] memory wrongNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - wrongNewCommitBlockInfoArray[0] = wrongNewCommitBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("h1")); - executor.commitBlocks(genesisStoredBlockInfo, wrongNewCommitBlockInfoArray); - } - - function test_RevertWhen_CommittingTooBigLastL2BlockTimestamp() public { - uint64 wrongL2BlockTimestamp = 0xffffffff; - bytes memory wrongL2Logs = abi.encodePacked( - bytes4(0x00000001), - bytes4(0x00000000), - address(L2_SYSTEM_CONTEXT_ADDRESS), - Utils.packBatchTimestampAndBlockTimestamp(wrongL2BlockTimestamp, wrongL2BlockTimestamp), - bytes32("") - ); - - IExecutor.CommitBlockInfo memory wrongNewCommitBlockInfo = newCommitBlockInfo; - wrongNewCommitBlockInfo.l2Logs = wrongL2Logs; - wrongNewCommitBlockInfo.timestamp = wrongL2BlockTimestamp; - - IExecutor.CommitBlockInfo[] memory wrongNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - wrongNewCommitBlockInfoArray[0] = wrongNewCommitBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("h2")); - executor.commitBlocks(genesisStoredBlockInfo, wrongNewCommitBlockInfoArray); - } - - function test_RevertWhen_CommittingWithWrongPreviousBlockHash() public { - bytes32 wrongPreviousBlockHash = Utils.randomBytes32("wrongPreviousBlockHash"); - bytes memory wrongL2Logs = abi.encodePacked( - bytes4(0x00000001), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - uint256(currentTimestamp), - wrongPreviousBlockHash - ); - - IExecutor.CommitBlockInfo memory wrongNewCommitBlockInfo = newCommitBlockInfo; - wrongNewCommitBlockInfo.l2Logs = wrongL2Logs; - - IExecutor.CommitBlockInfo[] memory wrongNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - wrongNewCommitBlockInfoArray[0] = wrongNewCommitBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("l")); - executor.commitBlocks(genesisStoredBlockInfo, wrongNewCommitBlockInfoArray); - } - - function test_RevertWhen_CommittingWithoutProcessingSystemContextLog() public { - bytes memory wrongL2Logs = abi.encodePacked(bytes4(0x00000000)); - - IExecutor.CommitBlockInfo memory wrongNewCommitBlockInfo = newCommitBlockInfo; - wrongNewCommitBlockInfo.l2Logs = wrongL2Logs; - - IExecutor.CommitBlockInfo[] memory wrongNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - wrongNewCommitBlockInfoArray[0] = wrongNewCommitBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("by")); - executor.commitBlocks(genesisStoredBlockInfo, wrongNewCommitBlockInfoArray); - } - - function test_RevertWhen_CommittingWithProcessingSystemContextLogTwice() public { - bytes memory wrongL2Logs = abi.encodePacked( - bytes4(0x00000002), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - uint256(currentTimestamp), - bytes32(""), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - uint256(currentTimestamp), - bytes32("") - ); - - IExecutor.CommitBlockInfo memory wrongNewCommitBlockInfo = newCommitBlockInfo; - wrongNewCommitBlockInfo.l2Logs = wrongL2Logs; - - IExecutor.CommitBlockInfo[] memory wrongNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - wrongNewCommitBlockInfoArray[0] = wrongNewCommitBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("fx")); - executor.commitBlocks(genesisStoredBlockInfo, wrongNewCommitBlockInfoArray); - } - - function test_RevertWhen_UnexpectedL2ToL1Log() public { - address unexpectedAddress = address(0); - bytes memory wrongL2Logs = abi.encodePacked( - bytes4(0x00000001), - bytes4(0x00000000), - unexpectedAddress, - uint256(currentTimestamp), - bytes32("") - ); - - IExecutor.CommitBlockInfo memory wrongNewCommitBlockInfo = newCommitBlockInfo; - wrongNewCommitBlockInfo.l2Logs = wrongL2Logs; - - IExecutor.CommitBlockInfo[] memory wrongNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - wrongNewCommitBlockInfoArray[0] = wrongNewCommitBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("ne")); - executor.commitBlocks(genesisStoredBlockInfo, wrongNewCommitBlockInfoArray); - } - - function test_RevertWhen_CommittingWithWrongCanonicalTxHash() public { - bytes32 canonicalTxHash = Utils.randomBytes32("canonicalTxHash"); - - bytes memory wrongL2Logs = abi.encodePacked( - bytes4(0x00000002), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - uint256(currentTimestamp), - bytes32(""), - bytes4(0x00010000), - L2_BOOTLOADER_ADDRESS, - canonicalTxHash, - uint256(1) - ); - - IExecutor.CommitBlockInfo memory wrongNewCommitBlockInfo = newCommitBlockInfo; - wrongNewCommitBlockInfo.l2Logs = wrongL2Logs; - - IExecutor.CommitBlockInfo[] memory wrongNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - wrongNewCommitBlockInfoArray[0] = wrongNewCommitBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("t")); - executor.commitBlocks(genesisStoredBlockInfo, wrongNewCommitBlockInfoArray); - } - - function test_RevertWhen_CommittingWithWrongNumberOfLayer1txs() public { - bytes32 arbitraryCanonicalTxHash = Utils.randomBytes32("arbitraryCanonicalTxHash"); - bytes32 chainedPriorityTxHash = keccak256(bytes.concat(keccak256(""), arbitraryCanonicalTxHash)); - - bytes memory wrongL2Logs = abi.encodePacked( - bytes4(0x00000002), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - uint256(currentTimestamp), - bytes32(""), - bytes4(0x00010000), - L2_BOOTLOADER_ADDRESS, - arbitraryCanonicalTxHash, - uint256(1) - ); - - IExecutor.CommitBlockInfo memory wrongNewCommitBlockInfo = newCommitBlockInfo; - wrongNewCommitBlockInfo.l2Logs = wrongL2Logs; - wrongNewCommitBlockInfo.priorityOperationsHash = bytes32(chainedPriorityTxHash); - wrongNewCommitBlockInfo.numberOfLayer1Txs = 2; - - IExecutor.CommitBlockInfo[] memory wrongNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - wrongNewCommitBlockInfoArray[0] = wrongNewCommitBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("ta")); - executor.commitBlocks(genesisStoredBlockInfo, wrongNewCommitBlockInfoArray); - } - - function test_RevertWhen_CommittingWithWrongFactoryDepsData() public { - bytes32 randomFactoryDeps0 = Utils.randomBytes32("randomFactoryDeps0"); - bytes32 randomFactoryDeps1 = Utils.randomBytes32("randomFactoryDeps1"); - - bytes memory wrongL2Logs = abi.encodePacked( - bytes4(0x00000002), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - uint256(currentTimestamp), - bytes32(""), - bytes4(0x00010000), - L2_KNOWN_CODE_STORAGE_ADDRESS, - randomFactoryDeps0 - ); - - IExecutor.CommitBlockInfo memory wrongNewCommitBlockInfo = newCommitBlockInfo; - wrongNewCommitBlockInfo.l2Logs = wrongL2Logs; - - bytes[] memory factoryDeps = new bytes[](1); - factoryDeps[0] = bytes.concat(randomFactoryDeps1); - - wrongNewCommitBlockInfo.factoryDeps = factoryDeps; - - IExecutor.CommitBlockInfo[] memory wrongNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - wrongNewCommitBlockInfoArray[0] = wrongNewCommitBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("k3")); - executor.commitBlocks(genesisStoredBlockInfo, wrongNewCommitBlockInfoArray); - } - - function test_RevertWhen_CommittingWithWrongFactoryDepsArrayLength() public { - bytes32 arbitraryBytecode = Utils.randomBytes32("arbitraryBytecode"); - bytes32 arbitraryBytecodeHash = sha256(bytes.concat(arbitraryBytecode)); - uint256 arbitraryBytecodeHashManipulated1 = uint256(arbitraryBytecodeHash) & - 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; - uint256 arbitraryBytecodeHashManipulated2 = arbitraryBytecodeHashManipulated1 | - 0x0100000100000000000000000000000000000000000000000000000000000000; - - bytes memory wrongL2Logs = abi.encodePacked( - bytes4(0x00000002), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - uint256(currentTimestamp), - bytes32(""), - bytes4(0x00010000), - L2_KNOWN_CODE_STORAGE_ADDRESS, - uint256(arbitraryBytecodeHashManipulated2) - ); - - IExecutor.CommitBlockInfo memory wrongNewCommitBlockInfo = newCommitBlockInfo; - wrongNewCommitBlockInfo.l2Logs = wrongL2Logs; - - bytes[] memory factoryDeps = new bytes[](2); - factoryDeps[0] = bytes.concat(arbitraryBytecode); - factoryDeps[1] = bytes.concat(arbitraryBytecode); - - wrongNewCommitBlockInfo.factoryDeps = factoryDeps; - - IExecutor.CommitBlockInfo[] memory wrongNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - wrongNewCommitBlockInfoArray[0] = wrongNewCommitBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("ym")); - executor.commitBlocks(genesisStoredBlockInfo, wrongNewCommitBlockInfoArray); - } - - function test_RevertWhen_ComittingWithWrongHashedMessage() public { - bytes32 randomL2LogValue = Utils.randomBytes32("randomL2LogValue"); - - bytes memory wrongL2Logs = abi.encodePacked( - bytes4(0x00000002), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - uint256(currentTimestamp), - bytes32(""), - bytes4(0x00010000), - L2_TO_L1_MESSENGER, - bytes32(""), - randomL2LogValue - ); - - IExecutor.CommitBlockInfo memory wrongNewCommitBlockInfo = newCommitBlockInfo; - wrongNewCommitBlockInfo.l2Logs = wrongL2Logs; - - bytes32 randomL2Message = Utils.randomBytes32("randomL2Message"); - - bytes[] memory l2ArbitraryLengthMessages = new bytes[](1); - l2ArbitraryLengthMessages[0] = bytes.concat(randomL2Message); - - wrongNewCommitBlockInfo.l2ArbitraryLengthMessages = l2ArbitraryLengthMessages; - - IExecutor.CommitBlockInfo[] memory wrongNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - wrongNewCommitBlockInfoArray[0] = wrongNewCommitBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("k2")); - executor.commitBlocks(genesisStoredBlockInfo, wrongNewCommitBlockInfoArray); - } - - function test_RevertWhen_CommittingWithWrongNumberOfMessages() public { - bytes memory arbitraryMessage = abi.encodePacked(uint8(0xaa)); - bytes32 arbitraryHashedMessage = keccak256(arbitraryMessage); - - bytes memory wrongL2Logs = abi.encodePacked( - bytes4(0x00000002), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - uint256(currentTimestamp), - bytes32(""), - bytes4(0x00010000), - L2_TO_L1_MESSENGER, - bytes32(""), - arbitraryHashedMessage - ); - - bytes[] memory l2ArbitraryLengthMessagesArray = new bytes[](2); - l2ArbitraryLengthMessagesArray[0] = arbitraryMessage; - l2ArbitraryLengthMessagesArray[1] = arbitraryMessage; - - IExecutor.CommitBlockInfo memory wrongNewCommitBlockInfo = newCommitBlockInfo; - - wrongNewCommitBlockInfo.l2Logs = wrongL2Logs; - wrongNewCommitBlockInfo.l2ArbitraryLengthMessages = l2ArbitraryLengthMessagesArray; - - IExecutor.CommitBlockInfo[] memory wrongNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - wrongNewCommitBlockInfoArray[0] = wrongNewCommitBlockInfo; - - vm.prank(validator); - vm.expectRevert(bytes.concat("pl")); - executor.commitBlocks(genesisStoredBlockInfo, wrongNewCommitBlockInfoArray); - } - - function test_RevertWhen_CommittingWithWrongBytecodeLength() public { - bytes32 randomFactoryDeps0 = Utils.randomBytes32("randomFactoryDeps0"); - - bytes memory wrongL2Logs = abi.encodePacked( - bytes4(0x00000002), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - uint256(currentTimestamp), - bytes32(""), - bytes4(0x00010000), - L2_KNOWN_CODE_STORAGE_ADDRESS, - randomFactoryDeps0 - ); - - bytes20 randomFactoryDeps1 = bytes20(randomFactoryDeps0); - - bytes[] memory factoryDeps = new bytes[](1); - factoryDeps[0] = bytes.concat(randomFactoryDeps1); - - IExecutor.CommitBlockInfo memory wrongNewCommitBlockInfo = newCommitBlockInfo; - wrongNewCommitBlockInfo.l2Logs = wrongL2Logs; - wrongNewCommitBlockInfo.factoryDeps = factoryDeps; - - IExecutor.CommitBlockInfo[] memory wrongNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - wrongNewCommitBlockInfoArray[0] = wrongNewCommitBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("bl")); - executor.commitBlocks(genesisStoredBlockInfo, wrongNewCommitBlockInfoArray); - } - - function test_RevertWhen_CommittingWithWrongNumberOfWordsInBytecode() public { - bytes32 randomFactoryDeps0 = Utils.randomBytes32("randomFactoryDeps0"); - - bytes memory wrongL2Logs = abi.encodePacked( - bytes4(0x00000002), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - uint256(currentTimestamp), - bytes32(""), - bytes4(0x00010000), - L2_KNOWN_CODE_STORAGE_ADDRESS, - randomFactoryDeps0 - ); - - bytes memory randomFactoryDeps1 = bytes.concat(randomFactoryDeps0, randomFactoryDeps0); - - bytes[] memory factoryDeps = new bytes[](1); - factoryDeps[0] = bytes.concat(randomFactoryDeps1); - - IExecutor.CommitBlockInfo memory wrongNewCommitBlockInfo = newCommitBlockInfo; - wrongNewCommitBlockInfo.l2Logs = wrongL2Logs; - wrongNewCommitBlockInfo.factoryDeps = factoryDeps; - - IExecutor.CommitBlockInfo[] memory wrongNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - wrongNewCommitBlockInfoArray[0] = wrongNewCommitBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("pr")); - executor.commitBlocks(genesisStoredBlockInfo, wrongNewCommitBlockInfoArray); - } - - function test_RevertWhen_CommittingWithWrongRepeatedStorageWrites() public { - bytes memory wrongL2Logs = abi.encodePacked( - bytes4(0x00000001), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - Utils.packBatchTimestampAndBlockTimestamp(currentTimestamp, currentTimestamp), - bytes32("") - ); - - IExecutor.CommitBlockInfo memory wrongNewCommitBlockInfo = newCommitBlockInfo; - wrongNewCommitBlockInfo.l2Logs = wrongL2Logs; - wrongNewCommitBlockInfo.indexRepeatedStorageChanges = 0; - wrongNewCommitBlockInfo.initialStorageChanges = "0x00000001"; - - IExecutor.CommitBlockInfo[] memory wrongNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - wrongNewCommitBlockInfoArray[0] = wrongNewCommitBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("yq")); - executor.commitBlocks(genesisStoredBlockInfo, wrongNewCommitBlockInfoArray); - } - - function test_RevertWhen_CommittingWithTooLongL2Logs() public { - // uint256 constant MAX_L2_TO_L1_LOGS_COMMITMENT_BYTES = 4 + L2_TO_L1_LOG_SERIALIZE_SIZE * 512; - bytes memory arr1; - - for (uint16 i = 0; i < 512; i++) { - arr1 = abi.encodePacked(arr1, bytes4(0x00000000), L2_TO_L1_MESSENGER, bytes32(""), keccak256("")); - } - - bytes memory wrongL2Logs = abi.encodePacked( - bytes4(0x00000001), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - Utils.packBatchTimestampAndBlockTimestamp(currentTimestamp, currentTimestamp), - bytes32(""), - arr1 - ); - - bytes[] memory l2ArbitraryLengthMessages = new bytes[](512); - - for (uint16 i = 0; i < l2ArbitraryLengthMessages.length; i++) { - l2ArbitraryLengthMessages[i] = bytes(""); - } - - IExecutor.CommitBlockInfo memory wrongNewCommitBlockInfo = newCommitBlockInfo; - wrongNewCommitBlockInfo.l2Logs = wrongL2Logs; - wrongNewCommitBlockInfo.l2ArbitraryLengthMessages = l2ArbitraryLengthMessages; - - IExecutor.CommitBlockInfo[] memory wrongNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - wrongNewCommitBlockInfoArray[0] = wrongNewCommitBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("pu")); - executor.commitBlocks(genesisStoredBlockInfo, wrongNewCommitBlockInfoArray); - } - - function test_RevertWhen_CommittingTooLongRepeatedStorageChanges() public { - bytes memory correctL2Logs = abi.encodePacked( - bytes4(0x00000001), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - Utils.packBatchTimestampAndBlockTimestamp(currentTimestamp, currentTimestamp), - bytes32("") - ); - - // 7565 * 40 bytes = 302600 bytes long repeatedStorageChanges - // which is longer than 302564 (MAX_REPEATED_STORAGE_CHANGES_COMMITMENT_BYTES = - // 4 + REPEATED_STORAGE_CHANGE_SERIALIZE_SIZE * 7564) - uint256 wrongRepeatedStorageChangesLen = 7565 * 40; - bytes memory wrongRepeatedStorageChanges = new bytes(wrongRepeatedStorageChangesLen); - - assembly { - let ptr := add(wrongRepeatedStorageChanges, 32) - let end := add(ptr, wrongRepeatedStorageChangesLen) - - for { - - } lt(ptr, end) { - - } { - mstore(ptr, 0x0000000000000000000000000000000000000000000000000000000000000000) - ptr := add(ptr, 40) - } - } - - IExecutor.CommitBlockInfo memory wrongNewCommitBlockInfo = newCommitBlockInfo; - wrongNewCommitBlockInfo.l2Logs = correctL2Logs; - wrongNewCommitBlockInfo.repeatedStorageChanges = wrongRepeatedStorageChanges; - - IExecutor.CommitBlockInfo[] memory wrongNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - wrongNewCommitBlockInfoArray[0] = wrongNewCommitBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("py")); - executor.commitBlocks(genesisStoredBlockInfo, wrongNewCommitBlockInfoArray); - } - - function test_RevertWhen_CommittingTooLongInitialStorageChanges() public { - bytes memory correctL2Logs = abi.encodePacked( - bytes4(0x00000001), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - Utils.packBatchTimestampAndBlockTimestamp(currentTimestamp, currentTimestamp), - bytes32("") - ); - - // 4766 * 64 bytes = 305024 bytes long initialStorageChangesLen - // which is longer than 304964 (MAX_INITIAL_STORAGE_CHANGES_COMMITMENT_BYTES = - // 4 + INITIAL_STORAGE_CHANGE_SERIALIZE_SIZE * 4765) - uint256 wrongInitialStorageChangesLen = 4766 * 64; - bytes memory wrongInitialStorageChanges = new bytes(wrongInitialStorageChangesLen); - - assembly { - let ptr := add(wrongInitialStorageChanges, 32) - let end := add(ptr, wrongInitialStorageChangesLen) - - for { - - } lt(ptr, end) { - - } { - mstore(ptr, 0x0000000000000000000000000000000000000000000000000000000000000000) - ptr := add(ptr, 64) - } - } - - IExecutor.CommitBlockInfo memory wrongNewCommitBlockInfo = newCommitBlockInfo; - wrongNewCommitBlockInfo.l2Logs = correctL2Logs; - wrongNewCommitBlockInfo.initialStorageChanges = wrongInitialStorageChanges; - - IExecutor.CommitBlockInfo[] memory wrongNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - wrongNewCommitBlockInfoArray[0] = wrongNewCommitBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("pf")); - executor.commitBlocks(genesisStoredBlockInfo, wrongNewCommitBlockInfoArray); - } - - function test_SuccessfullyCommitBlock() public { - bytes memory correctL2Logs = abi.encodePacked( - bytes4(0x00000001), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - Utils.packBatchTimestampAndBlockTimestamp(currentTimestamp, currentTimestamp), - bytes32("") - ); - - IExecutor.CommitBlockInfo memory correctNewCommitBlockInfo = newCommitBlockInfo; - correctNewCommitBlockInfo.l2Logs = correctL2Logs; - - IExecutor.CommitBlockInfo[] memory commitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - commitBlockInfoArray[0] = correctNewCommitBlockInfo; - - vm.prank(validator); - - vm.recordLogs(); - - executor.commitBlocks(genesisStoredBlockInfo, commitBlockInfoArray); - - Vm.Log[] memory entries = vm.getRecordedLogs(); - - assertEq(entries.length, 1); - assertEq(entries[0].topics[0], keccak256("BlockCommit(uint256,bytes32,bytes32)")); - assertEq(entries[0].topics[1], bytes32(uint256(1))); // blockNumber - - uint256 totalBlocksCommitted = getters.getTotalBlocksCommitted(); - assertEq(totalBlocksCommitted, 1); - } -} diff --git a/ethereum/test/foundry/unit/concrete/Executor/Executing.t.sol b/ethereum/test/foundry/unit/concrete/Executor/Executing.t.sol deleted file mode 100644 index bbfaa2d290..0000000000 --- a/ethereum/test/foundry/unit/concrete/Executor/Executing.t.sol +++ /dev/null @@ -1,247 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.17; - -// solhint-disable max-line-length - -import {Vm} from "forge-std/Test.sol"; -import {ExecutorTest} from "./_Executor_Shared.t.sol"; -import {Utils} from "../Utils/Utils.sol"; -import {L2_BOOTLOADER_ADDRESS} from "../../../../../cache/solpp-generated-contracts/common/L2ContractAddresses.sol"; -import {COMMIT_TIMESTAMP_NOT_OLDER, REQUIRED_L2_GAS_PRICE_PER_PUBDATA} from "../../../../../cache/solpp-generated-contracts/zksync/Config.sol"; -import {IExecutor} from "../../../../../cache/solpp-generated-contracts/zksync/interfaces/IExecutor.sol"; - -// solhint-enable max-line-length - -contract ExecutingTest is ExecutorTest { - function setUp() public { - vm.warp(COMMIT_TIMESTAMP_NOT_OLDER + 1); - currentTimestamp = block.timestamp; - - bytes memory correctL2Logs = abi.encodePacked( - bytes4(0x00000001), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - Utils.packBatchTimestampAndBlockTimestamp(currentTimestamp, currentTimestamp), - bytes32("") - ); - - newCommitBlockInfo.l2Logs = correctL2Logs; - newCommitBlockInfo.timestamp = uint64(currentTimestamp); - - IExecutor.CommitBlockInfo[] memory commitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - commitBlockInfoArray[0] = newCommitBlockInfo; - - vm.prank(validator); - vm.recordLogs(); - executor.commitBlocks(genesisStoredBlockInfo, commitBlockInfoArray); - Vm.Log[] memory entries = vm.getRecordedLogs(); - - newStoredBlockInfo = IExecutor.StoredBlockInfo({ - blockNumber: 1, - blockHash: entries[0].topics[2], - indexRepeatedStorageChanges: 0, - numberOfLayer1Txs: 0, - priorityOperationsHash: keccak256(""), - l2LogsTreeRoot: 0, - timestamp: currentTimestamp, - commitment: entries[0].topics[3] - }); - - IExecutor.StoredBlockInfo[] memory storedBlockInfoArray = new IExecutor.StoredBlockInfo[](1); - storedBlockInfoArray[0] = newStoredBlockInfo; - - vm.prank(validator); - executor.proveBlocks(genesisStoredBlockInfo, storedBlockInfoArray, proofInput); - } - - function test_RevertWhen_ExecutingBlockWithWrongBlockNumber() public { - IExecutor.StoredBlockInfo memory wrongNewStoredBlockInfo = newStoredBlockInfo; - wrongNewStoredBlockInfo.blockNumber = 10; // Correct is 1 - - IExecutor.StoredBlockInfo[] memory storedBlockInfoArray = new IExecutor.StoredBlockInfo[](1); - storedBlockInfoArray[0] = wrongNewStoredBlockInfo; - - vm.prank(validator); - vm.expectRevert(bytes.concat("k")); - executor.executeBlocks(storedBlockInfoArray); - } - - function test_RevertWhen_ExecutingBlockWithWrongData() public { - IExecutor.StoredBlockInfo memory wrongNewStoredBlockInfo = newStoredBlockInfo; - wrongNewStoredBlockInfo.timestamp = 0; // incorrect timestamp - - IExecutor.StoredBlockInfo[] memory storedBlockInfoArray = new IExecutor.StoredBlockInfo[](1); - storedBlockInfoArray[0] = wrongNewStoredBlockInfo; - - vm.prank(validator); - vm.expectRevert(bytes.concat("exe10")); - executor.executeBlocks(storedBlockInfoArray); - } - - function test_RevertWhen_ExecutingRevertedBlockWithoutCommittingAndProvingAgain() public { - vm.prank(validator); - executor.revertBlocks(0); - - IExecutor.StoredBlockInfo[] memory storedBlockInfoArray = new IExecutor.StoredBlockInfo[](1); - storedBlockInfoArray[0] = newStoredBlockInfo; - - vm.prank(validator); - vm.expectRevert(bytes.concat("n")); - executor.executeBlocks(storedBlockInfoArray); - } - - function test_RevertWhen_ExecutingUnavailablePriorityOperationHash() public { - vm.prank(validator); - executor.revertBlocks(0); - - bytes32 arbitraryCanonicalTxHash = Utils.randomBytes32("arbitraryCanonicalTxHash"); - bytes32 chainedPriorityTxHash = keccak256(bytes.concat(keccak256(""), arbitraryCanonicalTxHash)); - - bytes memory correctL2Logs = abi.encodePacked( - bytes4(0x00000002), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - Utils.packBatchTimestampAndBlockTimestamp(currentTimestamp, currentTimestamp), - bytes32(""), - bytes4(0x00010000), - L2_BOOTLOADER_ADDRESS, - arbitraryCanonicalTxHash, - uint256(1) - ); - - IExecutor.CommitBlockInfo memory correctNewCommitBlockInfo = newCommitBlockInfo; - correctNewCommitBlockInfo.l2Logs = correctL2Logs; - correctNewCommitBlockInfo.priorityOperationsHash = chainedPriorityTxHash; - correctNewCommitBlockInfo.numberOfLayer1Txs = 1; - - IExecutor.CommitBlockInfo[] memory correctNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - correctNewCommitBlockInfoArray[0] = correctNewCommitBlockInfo; - - vm.prank(validator); - vm.recordLogs(); - executor.commitBlocks(genesisStoredBlockInfo, correctNewCommitBlockInfoArray); - Vm.Log[] memory entries = vm.getRecordedLogs(); - - IExecutor.StoredBlockInfo memory correctNewStoredBlockInfo = newStoredBlockInfo; - correctNewStoredBlockInfo.blockHash = entries[0].topics[2]; - correctNewStoredBlockInfo.numberOfLayer1Txs = 1; - correctNewStoredBlockInfo.priorityOperationsHash = chainedPriorityTxHash; - correctNewStoredBlockInfo.commitment = entries[0].topics[3]; - - IExecutor.StoredBlockInfo[] memory correctNewStoredBlockInfoArray = new IExecutor.StoredBlockInfo[](1); - correctNewStoredBlockInfoArray[0] = correctNewStoredBlockInfo; - - vm.prank(validator); - executor.proveBlocks(genesisStoredBlockInfo, correctNewStoredBlockInfoArray, proofInput); - - vm.prank(validator); - vm.expectRevert(bytes.concat("s")); - executor.executeBlocks(correctNewStoredBlockInfoArray); - } - - function test_RevertWhen_ExecutingWithUnmatchedPriorityOperationHash() public { - vm.prank(validator); - executor.revertBlocks(0); - - bytes32 arbitraryCanonicalTxHash = Utils.randomBytes32("arbitraryCanonicalTxHash"); - bytes32 chainedPriorityTxHash = keccak256(bytes.concat(keccak256(""), arbitraryCanonicalTxHash)); - - bytes memory correctL2Logs = abi.encodePacked( - bytes4(0x00000002), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - Utils.packBatchTimestampAndBlockTimestamp(currentTimestamp, currentTimestamp), - bytes32(""), - bytes4(0x00010000), - L2_BOOTLOADER_ADDRESS, - arbitraryCanonicalTxHash, - uint256(1) - ); - - IExecutor.CommitBlockInfo memory correctNewCommitBlockInfo = newCommitBlockInfo; - correctNewCommitBlockInfo.l2Logs = correctL2Logs; - correctNewCommitBlockInfo.priorityOperationsHash = chainedPriorityTxHash; - correctNewCommitBlockInfo.numberOfLayer1Txs = 1; - - IExecutor.CommitBlockInfo[] memory correctNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - correctNewCommitBlockInfoArray[0] = correctNewCommitBlockInfo; - - vm.prank(validator); - vm.recordLogs(); - executor.commitBlocks(genesisStoredBlockInfo, correctNewCommitBlockInfoArray); - Vm.Log[] memory entries = vm.getRecordedLogs(); - - IExecutor.StoredBlockInfo memory correctNewStoredBlockInfo = newStoredBlockInfo; - correctNewStoredBlockInfo.blockHash = entries[0].topics[2]; - correctNewStoredBlockInfo.numberOfLayer1Txs = 1; - correctNewStoredBlockInfo.priorityOperationsHash = chainedPriorityTxHash; - correctNewStoredBlockInfo.commitment = entries[0].topics[3]; - - IExecutor.StoredBlockInfo[] memory correctNewStoredBlockInfoArray = new IExecutor.StoredBlockInfo[](1); - correctNewStoredBlockInfoArray[0] = correctNewStoredBlockInfo; - - vm.prank(validator); - executor.proveBlocks(genesisStoredBlockInfo, correctNewStoredBlockInfoArray, proofInput); - - bytes32 randomFactoryDeps0 = Utils.randomBytes32("randomFactoryDeps0"); - - bytes[] memory factoryDeps = new bytes[](1); - factoryDeps[0] = bytes.concat(randomFactoryDeps0); - - uint256 gasPrice = 1000000000; - uint256 l2GasLimit = 1000000; - uint256 baseCost = mailbox.l2TransactionBaseCost(gasPrice, l2GasLimit, REQUIRED_L2_GAS_PRICE_PER_PUBDATA); - uint256 l2Value = 10 ether; - uint256 totalCost = baseCost + l2Value; - - mailbox.requestL2Transaction{value: totalCost}( - address(0), - l2Value, - bytes(""), - l2GasLimit, - REQUIRED_L2_GAS_PRICE_PER_PUBDATA, - factoryDeps, - address(0) - ); - - vm.prank(validator); - vm.expectRevert(bytes.concat("x")); - executor.executeBlocks(correctNewStoredBlockInfoArray); - } - - function test_RevertWhen_CommittingBlockWithWrongPreviousBlockHash() public { - bytes memory correctL2Logs = abi.encodePacked( - bytes4(0x00000001), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - Utils.packBatchTimestampAndBlockTimestamp(currentTimestamp, currentTimestamp), - bytes32("") - ); - - IExecutor.CommitBlockInfo memory correctNewCommitBlockInfo = newCommitBlockInfo; - correctNewCommitBlockInfo.l2Logs = correctL2Logs; - - IExecutor.CommitBlockInfo[] memory correctNewCommitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - correctNewCommitBlockInfoArray[0] = correctNewCommitBlockInfo; - - bytes32 wrongPreviousBlockHash = Utils.randomBytes32("wrongPreviousBlockHash"); - - IExecutor.StoredBlockInfo memory genesisBlock = genesisStoredBlockInfo; - genesisBlock.blockHash = wrongPreviousBlockHash; - - vm.prank(validator); - vm.expectRevert(bytes.concat("i")); - executor.commitBlocks(genesisBlock, correctNewCommitBlockInfoArray); - } - - function test_ShouldExecuteBlockSuccessfully() public { - IExecutor.StoredBlockInfo[] memory storedBlockInfoArray = new IExecutor.StoredBlockInfo[](1); - storedBlockInfoArray[0] = newStoredBlockInfo; - - vm.prank(validator); - executor.executeBlocks(storedBlockInfoArray); - - uint256 totalBlocksExecuted = getters.getTotalBlocksExecuted(); - assertEq(totalBlocksExecuted, 1); - } -} diff --git a/ethereum/test/foundry/unit/concrete/Executor/Proving.t.sol b/ethereum/test/foundry/unit/concrete/Executor/Proving.t.sol deleted file mode 100644 index 806db9d026..0000000000 --- a/ethereum/test/foundry/unit/concrete/Executor/Proving.t.sol +++ /dev/null @@ -1,96 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.17; - -import {Vm} from "forge-std/Test.sol"; -import {ExecutorTest} from "./_Executor_Shared.t.sol"; -import {Utils} from "../Utils/Utils.sol"; -import {COMMIT_TIMESTAMP_NOT_OLDER} from "../../../../../cache/solpp-generated-contracts/zksync/Config.sol"; -import {IExecutor} from "../../../../../cache/solpp-generated-contracts/zksync/interfaces/IExecutor.sol"; - -contract ProvingTest is ExecutorTest { - function setUp() public { - vm.warp(COMMIT_TIMESTAMP_NOT_OLDER + 1); - currentTimestamp = block.timestamp; - - bytes memory correctL2Logs = abi.encodePacked( - bytes4(0x00000001), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - Utils.packBatchTimestampAndBlockTimestamp(currentTimestamp, currentTimestamp), - bytes32("") - ); - - newCommitBlockInfo.timestamp = uint64(currentTimestamp); - newCommitBlockInfo.l2Logs = correctL2Logs; - - IExecutor.CommitBlockInfo[] memory commitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - commitBlockInfoArray[0] = newCommitBlockInfo; - - vm.prank(validator); - vm.recordLogs(); - executor.commitBlocks(genesisStoredBlockInfo, commitBlockInfoArray); - Vm.Log[] memory entries = vm.getRecordedLogs(); - - newStoredBlockInfo = IExecutor.StoredBlockInfo({ - blockNumber: 1, - blockHash: entries[0].topics[2], - indexRepeatedStorageChanges: 0, - numberOfLayer1Txs: 0, - priorityOperationsHash: keccak256(""), - l2LogsTreeRoot: 0, - timestamp: currentTimestamp, - commitment: entries[0].topics[3] - }); - } - - function test_RevertWhen_ProvingWithWrongPreviousBlockData() public { - IExecutor.StoredBlockInfo memory wrongPreviousStoredBlockInfo = genesisStoredBlockInfo; - wrongPreviousStoredBlockInfo.blockNumber = 10; // Correct is 0 - - IExecutor.StoredBlockInfo[] memory storedBlockInfoArray = new IExecutor.StoredBlockInfo[](1); - storedBlockInfoArray[0] = newStoredBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("t1")); - executor.proveBlocks(wrongPreviousStoredBlockInfo, storedBlockInfoArray, proofInput); - } - - function test_RevertWhen_ProvingWithWrongCommittedBlock() public { - IExecutor.StoredBlockInfo memory wrongNewStoredBlockInfo = newStoredBlockInfo; - wrongNewStoredBlockInfo.blockNumber = 10; // Correct is 1 - - IExecutor.StoredBlockInfo[] memory storedBlockInfoArray = new IExecutor.StoredBlockInfo[](1); - storedBlockInfoArray[0] = wrongNewStoredBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("o1")); - executor.proveBlocks(genesisStoredBlockInfo, storedBlockInfoArray, proofInput); - } - - function test_RevertWhen_ProvingRevertedBlockWithoutCommittingAgain() public { - vm.prank(validator); - executor.revertBlocks(0); - - IExecutor.StoredBlockInfo[] memory storedBlockInfoArray = new IExecutor.StoredBlockInfo[](1); - storedBlockInfoArray[0] = newStoredBlockInfo; - - vm.prank(validator); - - vm.expectRevert(bytes.concat("q")); - executor.proveBlocks(genesisStoredBlockInfo, storedBlockInfoArray, proofInput); - } - - function test_SuccessfulProve() public { - IExecutor.StoredBlockInfo[] memory storedBlockInfoArray = new IExecutor.StoredBlockInfo[](1); - storedBlockInfoArray[0] = newStoredBlockInfo; - - vm.prank(validator); - - executor.proveBlocks(genesisStoredBlockInfo, storedBlockInfoArray, proofInput); - - uint256 totalBlocksVerified = getters.getTotalBlocksVerified(); - assertEq(totalBlocksVerified, 1); - } -} diff --git a/ethereum/test/foundry/unit/concrete/Executor/Reverting.t.sol b/ethereum/test/foundry/unit/concrete/Executor/Reverting.t.sol deleted file mode 100644 index 44d8f7a866..0000000000 --- a/ethereum/test/foundry/unit/concrete/Executor/Reverting.t.sol +++ /dev/null @@ -1,75 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.17; - -import {Vm} from "forge-std/Test.sol"; -import {ExecutorTest} from "./_Executor_Shared.t.sol"; -import {Utils} from "../Utils/Utils.sol"; -import {COMMIT_TIMESTAMP_NOT_OLDER} from "../../../../../cache/solpp-generated-contracts/zksync/Config.sol"; -import {IExecutor} from "../../../../../cache/solpp-generated-contracts/zksync/interfaces/IExecutor.sol"; - -contract RevertingTest is ExecutorTest { - function setUp() public { - vm.warp(COMMIT_TIMESTAMP_NOT_OLDER + 1); - currentTimestamp = block.timestamp; - - bytes memory correctL2Logs = abi.encodePacked( - bytes4(0x00000001), - bytes4(0x00000000), - L2_SYSTEM_CONTEXT_ADDRESS, - Utils.packBatchTimestampAndBlockTimestamp(currentTimestamp, currentTimestamp), - bytes32("") - ); - - newCommitBlockInfo.timestamp = uint64(currentTimestamp); - newCommitBlockInfo.l2Logs = correctL2Logs; - - IExecutor.CommitBlockInfo[] memory commitBlockInfoArray = new IExecutor.CommitBlockInfo[](1); - commitBlockInfoArray[0] = newCommitBlockInfo; - - vm.prank(validator); - vm.recordLogs(); - executor.commitBlocks(genesisStoredBlockInfo, commitBlockInfoArray); - Vm.Log[] memory entries = vm.getRecordedLogs(); - - newStoredBlockInfo = IExecutor.StoredBlockInfo({ - blockNumber: 1, - blockHash: entries[0].topics[2], - indexRepeatedStorageChanges: 0, - numberOfLayer1Txs: 0, - priorityOperationsHash: keccak256(""), - l2LogsTreeRoot: 0, - timestamp: currentTimestamp, - commitment: entries[0].topics[3] - }); - - IExecutor.StoredBlockInfo[] memory storedBlockInfoArray = new IExecutor.StoredBlockInfo[](1); - storedBlockInfoArray[0] = newStoredBlockInfo; - - vm.prank(validator); - - executor.proveBlocks(genesisStoredBlockInfo, storedBlockInfoArray, proofInput); - } - - function test_RevertWhen_RevertingMoreBlocksThanAlreadyCommitted() public { - vm.prank(validator); - vm.expectRevert(bytes.concat("v1")); - executor.revertBlocks(10); - } - - function test_SuccessfulRevert() public { - uint256 totalBlocksCommittedBefore = getters.getTotalBlocksCommitted(); - assertEq(totalBlocksCommittedBefore, 1, "totalBlocksCommittedBefore"); - - uint256 totalBlocksVerifiedBefore = getters.getTotalBlocksVerified(); - assertEq(totalBlocksVerifiedBefore, 1, "totalBlocksVerifiedBefore"); - - vm.prank(validator); - executor.revertBlocks(0); - - uint256 totalBlocksCommitted = getters.getTotalBlocksCommitted(); - assertEq(totalBlocksCommitted, 0, "totalBlocksCommitted"); - - uint256 totalBlocksVerified = getters.getTotalBlocksVerified(); - assertEq(totalBlocksVerified, 0, "totalBlocksVerified"); - } -} diff --git a/ethereum/test/foundry/unit/concrete/Executor/_Executor_Shared.t.sol b/ethereum/test/foundry/unit/concrete/Executor/_Executor_Shared.t.sol deleted file mode 100644 index 3a5d58bff5..0000000000 --- a/ethereum/test/foundry/unit/concrete/Executor/_Executor_Shared.t.sol +++ /dev/null @@ -1,220 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import {Test} from "forge-std/Test.sol"; -import {Utils} from "../Utils/Utils.sol"; -import {AllowList} from "../../../../../cache/solpp-generated-contracts/common/AllowList.sol"; -import {IAllowList} from "../../../../../cache/solpp-generated-contracts/common/interfaces/IAllowList.sol"; -import {COMMIT_TIMESTAMP_NOT_OLDER} from "../../../../../cache/solpp-generated-contracts/zksync/Config.sol"; -import {DiamondInit} from "../../../../../cache/solpp-generated-contracts/zksync/DiamondInit.sol"; -import {DiamondProxy} from "../../../../../cache/solpp-generated-contracts/zksync/DiamondProxy.sol"; -import {VerifierParams} from "../../../../../cache/solpp-generated-contracts/zksync/Storage.sol"; -import {ExecutorFacet} from "../../../../../cache/solpp-generated-contracts/zksync/facets/Executor.sol"; -import {GettersFacet} from "../../../../../cache/solpp-generated-contracts/zksync/facets/Getters.sol"; -import {GovernanceFacet} from "../../../../../cache/solpp-generated-contracts/zksync/facets/Governance.sol"; -import {MailboxFacet} from "../../../../../cache/solpp-generated-contracts/zksync/facets/Mailbox.sol"; -import {IExecutor} from "../../../../../cache/solpp-generated-contracts/zksync/interfaces/IExecutor.sol"; -import {Diamond} from "../../../../../cache/solpp-generated-contracts/zksync/libraries/Diamond.sol"; - -contract ExecutorTest is Test { - address internal constant L2_SYSTEM_CONTEXT_ADDRESS = 0x000000000000000000000000000000000000800B; - address internal constant L2_KNOWN_CODE_STORAGE_ADDRESS = 0x0000000000000000000000000000000000008004; - address internal constant L2_TO_L1_MESSENGER = 0x0000000000000000000000000000000000008008; - - address internal owner; - address internal validator; - address internal randomSigner; - AllowList internal allowList; - GovernanceFacet internal governance; - ExecutorFacet internal executor; - GettersFacet internal getters; - MailboxFacet internal mailbox; - bytes32 internal newCommittedBlockBlockHash; - bytes32 internal newCommittedBlockCommitment; - uint256 internal currentTimestamp; - IExecutor.CommitBlockInfo internal newCommitBlockInfo; - IExecutor.StoredBlockInfo internal newStoredBlockInfo; - - IExecutor.StoredBlockInfo internal genesisStoredBlockInfo; - IExecutor.ProofInput internal proofInput; - - function getGovernanceSelectors() private view returns (bytes4[] memory) { - bytes4[] memory selectors = new bytes4[](5); - selectors[0] = governance.setPendingGovernor.selector; - selectors[1] = governance.acceptGovernor.selector; - selectors[2] = governance.setValidator.selector; - selectors[3] = governance.setPorterAvailability.selector; - selectors[4] = governance.setPriorityTxMaxGasLimit.selector; - return selectors; - } - - function getExecutorSelectors() private view returns (bytes4[] memory) { - bytes4[] memory selectors = new bytes4[](4); - selectors[0] = executor.commitBlocks.selector; - selectors[1] = executor.proveBlocks.selector; - selectors[2] = executor.executeBlocks.selector; - selectors[3] = executor.revertBlocks.selector; - return selectors; - } - - function getGettersSelectors() public view returns (bytes4[] memory) { - bytes4[] memory selectors = new bytes4[](32); - selectors[0] = getters.getVerifier.selector; - selectors[1] = getters.getGovernor.selector; - selectors[2] = getters.getPendingGovernor.selector; - selectors[3] = getters.getTotalBlocksCommitted.selector; - selectors[4] = getters.getTotalBlocksVerified.selector; - selectors[5] = getters.getTotalBlocksExecuted.selector; - selectors[6] = getters.getTotalPriorityTxs.selector; - selectors[7] = getters.getFirstUnprocessedPriorityTx.selector; - selectors[8] = getters.getPriorityQueueSize.selector; - selectors[9] = getters.priorityQueueFrontOperation.selector; - selectors[10] = getters.isValidator.selector; - selectors[11] = getters.l2LogsRootHash.selector; - selectors[12] = getters.storedBlockHash.selector; - selectors[13] = getters.getL2BootloaderBytecodeHash.selector; - selectors[14] = getters.getL2DefaultAccountBytecodeHash.selector; - selectors[15] = getters.getVerifierParams.selector; - selectors[16] = getters.isDiamondStorageFrozen.selector; - selectors[17] = getters.getSecurityCouncil.selector; - selectors[18] = getters.getUpgradeProposalState.selector; - selectors[19] = getters.getProposedUpgradeHash.selector; - selectors[20] = getters.getProposedUpgradeTimestamp.selector; - selectors[21] = getters.getCurrentProposalId.selector; - selectors[22] = getters.isApprovedBySecurityCouncil.selector; - selectors[23] = getters.getPriorityTxMaxGasLimit.selector; - selectors[24] = getters.getAllowList.selector; - selectors[25] = getters.isEthWithdrawalFinalized.selector; - selectors[26] = getters.facets.selector; - selectors[27] = getters.facetFunctionSelectors.selector; - selectors[28] = getters.facetAddresses.selector; - selectors[29] = getters.facetAddress.selector; - selectors[30] = getters.isFunctionFreezable.selector; - selectors[31] = getters.isFacetFreezable.selector; - return selectors; - } - - function getMailboxSelectors() private view returns (bytes4[] memory) { - bytes4[] memory selectors = new bytes4[](6); - selectors[0] = mailbox.proveL2MessageInclusion.selector; - selectors[1] = mailbox.proveL2LogInclusion.selector; - selectors[2] = mailbox.proveL1ToL2TransactionStatus.selector; - selectors[3] = mailbox.finalizeEthWithdrawal.selector; - selectors[4] = mailbox.requestL2Transaction.selector; - selectors[5] = mailbox.l2TransactionBaseCost.selector; - return selectors; - } - - constructor() { - owner = makeAddr("owner"); - validator = makeAddr("validator"); - randomSigner = makeAddr("randomSigner"); - - executor = new ExecutorFacet(); - governance = new GovernanceFacet(); - getters = new GettersFacet(); - mailbox = new MailboxFacet(); - - allowList = new AllowList(owner); - DiamondInit diamondInit = new DiamondInit(); - - bytes8 dummyHash = 0x1234567890123456; - address dummyAddress = makeAddr("dummyAddress"); - bytes memory diamondInitData = abi.encodeWithSelector( - diamondInit.initialize.selector, - dummyAddress, //verifier - owner, - 0, - 0, - 0, - allowList, - VerifierParams({recursionNodeLevelVkHash: 0, recursionLeafLevelVkHash: 0, recursionCircuitsSetVksHash: 0}), - false, - dummyHash, - dummyHash, - 100000000000 - ); - - Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](4); - facetCuts[0] = Diamond.FacetCut({ - facet: address(governance), - action: Diamond.Action.Add, - isFreezable: true, - selectors: getGovernanceSelectors() - }); - facetCuts[1] = Diamond.FacetCut({ - facet: address(executor), - action: Diamond.Action.Add, - isFreezable: true, - selectors: getExecutorSelectors() - }); - facetCuts[2] = Diamond.FacetCut({ - facet: address(getters), - action: Diamond.Action.Add, - isFreezable: false, - selectors: getGettersSelectors() - }); - facetCuts[3] = Diamond.FacetCut({ - facet: address(mailbox), - action: Diamond.Action.Add, - isFreezable: true, - selectors: getMailboxSelectors() - }); - - Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ - facetCuts: facetCuts, - initAddress: address(diamondInit), - initCalldata: diamondInitData - }); - - uint256 chainId = block.chainid; - DiamondProxy diamondProxy = new DiamondProxy(chainId, diamondCutData); - - vm.prank(owner); - allowList.setAccessMode(address(diamondProxy), IAllowList.AccessMode.Public); - - executor = ExecutorFacet(address(diamondProxy)); - getters = GettersFacet(address(diamondProxy)); - mailbox = MailboxFacet(address(diamondProxy)); - governance = GovernanceFacet(address(diamondProxy)); - - vm.prank(owner); - governance.setValidator(validator, true); - - uint256[] memory recursiveAggregationInput; - uint256[] memory serializedProof; - proofInput = IExecutor.ProofInput(recursiveAggregationInput, serializedProof); - - genesisStoredBlockInfo = IExecutor.StoredBlockInfo({ - blockNumber: 0, - blockHash: 0, - indexRepeatedStorageChanges: 0, - numberOfLayer1Txs: 0, - priorityOperationsHash: keccak256(""), - l2LogsTreeRoot: 0, - timestamp: 0, - commitment: 0 - }); - - // foundry's default value is 1 for the block's timestamp, it is expected - // that block.timestamp > COMMIT_TIMESTAMP_NOT_OLDER + 1 - vm.warp(COMMIT_TIMESTAMP_NOT_OLDER + 1 + 1); - currentTimestamp = block.timestamp; - - newCommitBlockInfo = IExecutor.CommitBlockInfo({ - blockNumber: 1, - timestamp: uint64(currentTimestamp), - indexRepeatedStorageChanges: 0, - newStateRoot: Utils.randomBytes32("newStateRoot"), - numberOfLayer1Txs: 0, - l2LogsTreeRoot: 0, - priorityOperationsHash: keccak256(""), - initialStorageChanges: abi.encodePacked(uint256(0x00000000)), - repeatedStorageChanges: bytes(""), - l2Logs: bytes(""), - l2ArbitraryLengthMessages: new bytes[](0), - factoryDeps: new bytes[](0) - }); - } -}