From 2c1c688fc11ea87de59652ddc97579ccd148a22f Mon Sep 17 00:00:00 2001 From: Stanislav Breadless Date: Tue, 7 May 2024 13:24:57 +0200 Subject: [PATCH 1/8] script for verification + gas bound caller disclaimer --- .github/workflows/l2-contracts-ci.yaml | 33 +++++ gas-bound-caller/README.md | 18 ++- .../canonical-bytecodes/GasBoundCaller | 2 +- gas-bound-caller/hardhat.config.ts | 22 +++ gas-bound-caller/package.json | 8 +- ...ode.ts => calculate-canonical-bytecode.ts} | 4 +- .../scripts/deploy-on-hyperchain.ts | 18 +-- gas-bound-caller/scripts/utils.ts | 28 ++++ gas-bound-caller/scripts/verify.ts | 37 +++++ yarn.lock | 138 +++++++++++++++++- 10 files changed, 285 insertions(+), 23 deletions(-) rename gas-bound-caller/scripts/{check-canonical-bytecode.ts => calculate-canonical-bytecode.ts} (88%) create mode 100644 gas-bound-caller/scripts/verify.ts diff --git a/.github/workflows/l2-contracts-ci.yaml b/.github/workflows/l2-contracts-ci.yaml index 20bb9583f..caae76c5e 100644 --- a/.github/workflows/l2-contracts-ci.yaml +++ b/.github/workflows/l2-contracts-ci.yaml @@ -94,3 +94,36 @@ jobs: - name: Run tests run: yarn l2 test + + gas-bound-caller: + needs: [build, lint] + runs-on: ubuntu-latest + + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: 18.18.0 + cache: yarn + + - name: Install dependencies + run: yarn + + - name: Build GasBoundCaller + run: yarn gas-bound-caller build + + - name: CHeck the correcntess of the canonical bytecode + run: yarn gas-bound-caller calculate-canonical-bytecode:check + + - name: Use era-test-node for testing + uses: dutterbutter/era-test-node-action@v0.1.3 + with: + releaseTag: v0.0.1-vm1.5.0 + + - name: Run tests + run: yarn gas-bound-caller test diff --git a/gas-bound-caller/README.md b/gas-bound-caller/README.md index 71962937b..678a343e1 100644 --- a/gas-bound-caller/README.md +++ b/gas-bound-caller/README.md @@ -1,5 +1,7 @@ # GasBoundCaller +> ⚠️⚠️ The GasBoundCaller's bytecode is not yet finalized, this version is for testnet trial only ⚠️⚠️ + Starting from v24 On Era, the gas for pubdata is charged at the end of the execution of the entire transaction. This means that if a subcall is not trusted, it can consume a significant amount of pubdata during the process. While this may not be an issue for most contracts, there are use cases, e.g., for relayers, where it is crucial to ensure that the subcall will not spend more money than intended. The `GasBoundCaller` is a contract with the following interface: @@ -44,8 +46,18 @@ uint256 totalGasConsumed = computeGasBefore - computeGasAfter + pubdataGasSpent; Since `GasBoundCaller` would be the contract that calls the `_to` contract, the `msg.sender` will be equal to the `GasBoundCaller`'s address. To preserve the current `msg.sender`, this contract can be inherited from and used the same way, but instead of calling `GasBoundCaller.gasBoundCall`, `this.gasBoundCall` could be called. -## Deployed Address +## Deploying on a zkSync-based chain + +Note, that it requires the v1.5.0 version of the contracts to be active on the network, i.e. the protocol version should be at least v24. + +``` +yarn deploy-on-hyperchain --private-key --l2-rpc +``` + +### Deployed addresses -It should be deployed via a built-in CREATE2 factory on each individual chain. +| Network | Address | +| -------- | ------- | +| Era Testnet | [0xDaAD9137Deec2FCbB8C4aB3820553E0da60328b6](https://sepolia.explorer.zksync.io/address/0xDaAD9137Deec2FCbB8C4aB3820553E0da60328b6#contract) | +| Era Mainnet | TODO | -TODO(EVM-585) diff --git a/gas-bound-caller/canonical-bytecodes/GasBoundCaller b/gas-bound-caller/canonical-bytecodes/GasBoundCaller index 17dcacc84..2e5c1ec23 100644 --- a/gas-bound-caller/canonical-bytecodes/GasBoundCaller +++ b/gas-bound-caller/canonical-bytecodes/GasBoundCaller @@ -1 +1 @@ -0x00120000000000020006000000000002000000000301001900000060043002700000009e03400197000100000031035500020000003103550003000000310355000400000031035500050000003103550006000000310355000700000031035500080000003103550009000000310355000a000000310355000b000000310355000c000000310355000d000000310355000e000000310355000f000000310355001000000031035500110000000103550000009e0040019d0000008004000039000000400040043f00000001022001900000004d0000c13d000000040230008c000000a50000413d000000000201043b000000a002200197000000a10220009c000000a50000c13d000000040230008a000000600220008c000000a50000413d0000000402100370000000000802043b000000a20280009c000000a50000213d0000004402100370000000000202043b000000a30420009c000000a50000213d0000002304200039000000a405000041000000000634004b00000000060000190000000006058019000000a404400197000000000704004b0000000005008019000000a40440009c000000000506c019000000000405004b000000a50000c13d0000000404200039000000000441034f000000000604043b000000a30460009c000000a50000213d00000024052000390000000004560019000000000234004b000000a50000213d0000002401100370000000000201043b0000000003000414000003200100008a000000000113004b000000550000413d000000b10100004100000000001004350000001101000039000000040010043f000000b20100004100000274000104300000000001000416000000000101004b000000a50000c13d0000002001000039000001000010044300000120000004430000009f01000041000002730001042e0000000001000414000000000121004b000000620000a13d000000af01000041000000800010043f0000002001000039000000840010043f0000001401000039000000a40010043f000000b401000041000000c40010043f000000b5010000410000027400010430000200000006001d000100000005001d000500000004001d000600000008001d000000a501000041000000800010043f0000009e01000041000400000002001d0000000002000414000300000003001d0000009e0320009c0000000002018019000000c001200210000000a6011001c70000800b02000039027202680000040f00000003030000290000000403300069000003200a30008a0000000403a0006c00000000030000190000000103002039000000000303004b000000000a00c019000000000301001900000060033002700000009e03300197000000200430008c000000000403001900000020040080390000001f0540018f00000005064002720000008c0000613d00000000070000190000000508700210000000000981034f000000000909043b000000800880003900000000009804350000000107700039000000000867004b000000840000413d000000000705004b000000060b0000290000009c0000613d0000000506600210000000000761034f00000003055002100000008006600039000000000806043300000000085801cf000000000858022f000000000707043b0000010005500089000000000757022f00000000055701cf000000000585019f00000000005604350000000102200190000000050c000029000000a70000613d0000001f01400039000000600210018f00000080012001bf000000400010043f000000200330008c000000ca0000813d00000000010000190000027400010430000000400200043d0000001f0430018f0000000505300272000000b40000613d000000000600001900000005076002100000000008720019000000000771034f000000000707043b00000000007804350000000106600039000000000756004b000000ac0000413d000000000604004b000000c30000613d0000000505500210000000000151034f00000000055200190000000304400210000000000605043300000000064601cf000000000646022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000161019f00000000001504350000009e010000410000009e0420009c000000000201801900000040012002100000006002300210000000000121019f0000027400010430000000800900043d0000000004000414000000000600003100000011050003670000000003000416000000000703004b000000e80000c13d000000020300006b000000da0000613d00000001030000290000009e0330019700010000003503550000000007c6004b000000470000413d000000000535034f0000000006c600490000009e0360019700010000003503e50000009e0640009c000000f50000213d000400000009001d00050000000a001d00000000013503df000000c002400210000000a802200197000000aa022001c700010000002103b500000000012103af00000000020b00190000010f0000013d000000020700006b000000f10000613d00000001070000290000009e0770019700010000007503550000000008c6004b000000470000413d000000000575034f0000000006c600490000009e0660019700010000006503e5000000a70740009c000001030000413d000000af03000041000000000031043500000084032001bf00000020040000390000000000430435000000c403200039000000b3040000410000000000430435000000a402200039000000080300003900000000003204350000004001100210000000b0011001c70000027400010430000400000009001d00050000000a001d00000000016503df000000c002400210000000a802200197000000a9022001c700010000002103b500000000012103af000080090200003900000000040b0019000000000500001900000000060000190272026d0000040f000000000301001900000060033002700000009e033001970000000102200190000001d90000613d0000003f02300039000000ab02200197000000400600043d0000000002260019000000000462004b00000000040000190000000104004039000000a30520009c000001d50000213d0000000104400190000001d50000c13d000000400020043f000200000006001d00000000023604360000001f043000390000000504400272000001310000613d00000000050000310000001105500367000000000600001900000005076002100000000008720019000000000775034f000000000707043b00000000007804350000000106600039000000000746004b000001290000413d000000000400004b000001330000613d0000001f0430018f00000005033002720000013f0000613d000000000500001900000005065002100000000007620019000000000661034f000000000606043b00000000006704350000000105500039000000000635004b000001370000413d000000000504004b0000014e0000613d0000000503300210000000000131034f00000000023200190000000303400210000000000402043300000000043401cf000000000434022f000000000101043b0000010003300089000000000131022f00000000013101cf000000000141019f0000000000120435000000400400043d000600000004001d000000a50100004100000000001404350000009e0100004100000000020004140000009e0320009c00000000020180190000009e0340009c00000000010440190000004001100210000000c002200210000000000112019f000000ac011001c70000800b02000039027202680000040f000000060a000029000000000301001900000060033002700000009e03300197000000200430008c000000000403001900000020040080390000001f0540018f0000000506400272000001710000613d0000000007000019000000050870021000000000098a0019000000000881034f000000000808043b00000000008904350000000107700039000000000867004b000001690000413d00000000090a0019000000000705004b000001810000613d0000000506600210000000000761034f00000000066900190000000305500210000000000806043300000000085801cf000000000858022f000000000707043b0000010005500089000000000757022f00000000055701cf000000000585019f00000000005604350000000102200190000001f40000613d0000001f01400039000000600110018f0000000002910019000000000112004b00000000010000190000000101004039000300000002001d000000a30220009c000001d50000213d0000000101100190000001d50000c13d0000000301000029000000400010043f000000200130008c0000000501000029000000a50000413d000500000001001d0000000001090433000600000001001d000000ad01000041000000030400002900000000001404350000009e0100004100000000020004140000009e0320009c00000000020180190000009e0340009c00000000010440190000004001100210000000c002200210000000000112019f000000ac011001c70000800b02000039027202680000040f000000030b0000290000000605000029000000040450006a000000000354004b00000000030000190000000103002039000000000303004b000000000400c019000000000301001900000060033002700000009e03300197000000200530008c000000000503001900000020050080390000001f0650018f0000000507500272000001bf0000613d00000000080000190000000509800210000000000a9b0019000000000991034f000000000909043b00000000009a04350000000108800039000000000978004b000001b70000413d000000000806004b000001ce0000613d0000000507700210000000000871034f00000003077000290000000306600210000000000907043300000000096901cf000000000969022f000000000808043b0000010006600089000000000868022f00000000066801cf000000000696019f00000000006704350000000102200190000002110000613d0000001f01500039000000600110018f0000000301100029000000a30210009c0000022e0000a13d000000b101000041000000000010043500000041010000390000004a0000013d0000001f0430018f0000000502300272000001e40000613d00000000050000190000000506500210000000000761034f000000000707043b00000000007604350000000105500039000000000625004b000001dd0000413d000000000504004b000001f20000613d00000003044002100000000502200210000000000502043300000000054501cf000000000545022f000000000121034f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f000000000012043500000060013002100000027400010430000000400200043d0000001f0430018f0000000505300272000002010000613d000000000600001900000005076002100000000008720019000000000771034f000000000707043b00000000007804350000000106600039000000000756004b000001f90000413d000000000604004b000002100000613d0000000505500210000000000151034f00000000055200190000000304400210000000000605043300000000064601cf000000000646022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000161019f0000000000150435000000c30000013d000000400200043d0000001f0430018f00000005053002720000021e0000613d000000000600001900000005076002100000000008720019000000000771034f000000000707043b00000000007804350000000106600039000000000756004b000002160000413d000000000604004b0000022d0000613d0000000505500210000000000151034f00000000055200190000000304400210000000000605043300000000064601cf000000000646022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000161019f0000000000150435000000c30000013d000000400010043f000000200230008c000000a50000413d0000000302000029000000000302043300000000524300a9000000000503004b0000023b0000613d00000000533200d9000000000343004b000000470000c13d000000000302004b0000024c0000c13d0000000203000029000000200130008a0000000000210435000000400130008a00000040020000390000000000210435000000000203043300000060022000390000009e030000410000009e0420009c00000000020380190000009e0410009c000000000103801900000040011002100000006002200210000000000112019f000002730001042e00000000040004140000000503400029000000000443004b000000000400001900000001040040390000000104400190000000470000c13d000001910400008a000000000442004b000000470000213d0000019004200039000000000343004b0000023b0000813d0000004402100039000000ae03000041000000000032043500000024021000390000001a030000390000000000320435000000af0200004100000000002104350000000402100039000000200300003900000000003204350000009e020000410000009e0310009c0000000001028019000001000000013d0000026b002104230000000102000039000000000001042d0000000002000019000000000001042d00000270002104210000000102000039000000000001042d0000000002000019000000000001042d0000027200000432000002730001042e000002740001043000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0000000200000000000000000000000000000040000001000000000000000000ffffffff0000000000000000000000000000000000000000000000000000000041a8596c00000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000ffffffffffffffff8000000000000000000000000000000000000000000000000000000000000000c0d5b949000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000800000000000000000000000000000000000000000000000000000000000000000000000010000000000000000ffffffff0000000000000000000000000000000000000000000000000100000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001ffffffe000000000000000000000000000000000000000040000000000000000000000007cb9357e000000000000000000000000000000000000000000000000000000004e6f7420656e6f7567682067617320666f72207075626461746100000000000008c379a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000640000000000000000000000004e487b710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000240000000000000000000000004f766572666c6f77000000000000000000000000000000000000000000000000476173206c696d697420697320746f6f206c6f7700000000000000000000000000000000000000000000000000000000000000640000008000000000000000006c300d3e2b009b9a5b1fe7d853a9ae64e30e1d513df698d5c9801da939df7831 \ No newline at end of file +0x0012000000000002000600000000000200000000030100190000006004300270000000a203400197000100000031035500020000003103550003000000310355000400000031035500050000003103550006000000310355000700000031035500080000003103550009000000310355000a000000310355000b000000310355000c000000310355000d000000310355000e000000310355000f00000031035500100000003103550011000000010355000000a20040019d0000008004000039000000400040043f00000001022001900000004d0000c13d000000040230008c000000a50000413d000000000201043b000000a402200197000000a50220009c000000a50000c13d000000040230008a000000600220008c000000a50000413d0000000402100370000000000802043b000000a60280009c000000a50000213d0000004402100370000000000202043b000000a70420009c000000a50000213d0000002304200039000000a805000041000000000634004b00000000060000190000000006058019000000a804400197000000000704004b0000000005008019000000a80440009c000000000506c019000000000405004b000000a50000c13d0000000404200039000000000441034f000000000604043b000000a70460009c000000a50000213d00000024052000390000000004560019000000000234004b000000a50000213d0000002401100370000000000201043b0000000003000414000003200100008a000000000113004b000000550000413d000000b50100004100000000001004350000001101000039000000040010043f000000b60100004100000283000104300000000001000416000000000101004b000000a50000c13d000000200100003900000100001004430000012000000443000000a301000041000002820001042e0000000001000414000000000121004b000000620000a13d000000b301000041000000800010043f0000002001000039000000840010043f0000001401000039000000a40010043f000000b801000041000000c40010043f000000b9010000410000028300010430000200000006001d000100000005001d000500000004001d000600000008001d000000a901000041000000800010043f000000a201000041000400000002001d0000000002000414000300000003001d000000a20320009c0000000002018019000000c001200210000000aa011001c70000800b02000039028102770000040f00000003030000290000000403300069000003200a30008a0000000403a0006c00000000030000190000000103002039000000000303004b000000000a00c01900000000030100190000006003300270000000a203300197000000200430008c000000000403001900000020040080390000001f0540018f00000005064002720000008c0000613d00000000070000190000000508700210000000000981034f000000000909043b000000800880003900000000009804350000000107700039000000000867004b000000840000413d000000000705004b000000060b0000290000009c0000613d0000000506600210000000000761034f00000003055002100000008006600039000000000806043300000000085801cf000000000858022f000000000707043b0000010005500089000000000757022f00000000055701cf000000000585019f00000000005604350000000102200190000000050c000029000000a70000613d0000001f01400039000000600210018f00000080012001bf000000400010043f000000200330008c000000ca0000813d00000000010000190000028300010430000000400200043d0000001f0430018f0000000505300272000000b40000613d000000000600001900000005076002100000000008720019000000000771034f000000000707043b00000000007804350000000106600039000000000756004b000000ac0000413d000000000604004b000000c30000613d0000000505500210000000000151034f00000000055200190000000304400210000000000605043300000000064601cf000000000646022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000161019f0000000000150435000000a201000041000000a20420009c000000000201801900000040012002100000006002300210000000000121019f0000028300010430000000800900043d0000000004000414000000000600003100000011050003670000000003000416000000000703004b000000e80000c13d000000020300006b000000da0000613d0000000103000029000000a20330019700010000003503550000000007c6004b000000470000413d000000000535034f0000000006c60049000000a20360019700010000003503e5000000a20640009c000000f50000213d000500000009001d00040000000a001d00000000013503df000000c002400210000000ac02200197000000ae022001c700010000002103b500000000012103af00000000020b00190000010f0000013d000000020700006b000000f10000613d0000000107000029000000a20770019700010000007503550000000008c6004b000000470000413d000000000575034f0000000006c60049000000a20660019700010000006503e5000000ab0740009c000001030000413d000000b303000041000000000031043500000084032001bf00000020040000390000000000430435000000c403200039000000b7040000410000000000430435000000a402200039000000080300003900000000003204350000004001100210000000b4011001c70000028300010430000500000009001d00040000000a001d00000000016503df000000c002400210000000ac02200197000000ad022001c700010000002103b500000000012103af000080090200003900000000040b0019000000000500001900000000060000190281027c0000040f00000000030100190000006003300270000000a2033001970000000102200190000001e90000613d0000003f02300039000000af02200197000000400600043d0000000002260019000000000462004b00000000040000190000000104004039000000a70520009c000001e50000213d0000000104400190000001e50000c13d000000400020043f000600000006001d00000000023604360000001f043000390000000504400272000001310000613d00000000050000310000001105500367000000000600001900000005076002100000000008720019000000000775034f000000000707043b00000000007804350000000106600039000000000746004b000001290000413d000000000400004b000001330000613d0000001f0430018f00000005033002720000013f0000613d000000000500001900000005065002100000000007620019000000000661034f000000000606043b00000000006704350000000105500039000000000635004b000001370000413d000000000504004b0000014e0000613d0000000503300210000000000131034f00000000023200190000000303400210000000000402043300000000043401cf000000000434022f000000000101043b0000010003300089000000000131022f00000000013101cf000000000141019f000000000012043500000006010000290000000001010433000000610200008a000000000221004b00000004030000290000000504000029000000470000213d000300600010003d0000001f021001900000015e0000613d0000008001100039000000200200008a000000000121016f000000030210006c000300000001001d000000470000413d000500000004001d000400000003001d000000400400043d000200000004001d000000a9010000410000000000140435000000a2010000410000000002000414000000a20320009c0000000002018019000000a20340009c00000000010440190000004001100210000000c002200210000000000112019f000000b0011001c70000800b02000039028102770000040f000000020a00002900000000030100190000006003300270000000a203300197000000200430008c000000000403001900000020040080390000001f0540018f0000000506400272000001830000613d0000000007000019000000050870021000000000098a0019000000000881034f000000000808043b00000000008904350000000107700039000000000867004b0000017b0000413d00000000090a0019000000000705004b000001930000613d0000000506600210000000000761034f00000000066900190000000305500210000000000806043300000000085801cf000000000858022f000000000707043b0000010005500089000000000757022f00000000055701cf000000000585019f00000000005604350000000102200190000002040000613d0000001f01400039000000600110018f0000000002910019000000000112004b00000000010000190000000101004039000100000002001d000000a70220009c000001e50000213d0000000101100190000001e50000c13d0000000101000029000000400010043f000000200130008c000000a50000413d0000000001090433000200000001001d000000b10100004100000001040000290000000000140435000000a2010000410000000002000414000000a20320009c0000000002018019000000a20340009c00000000010440190000004001100210000000c002200210000000000112019f000000b0011001c70000800b02000039028102770000040f000000010b0000290000000205000029000000050450006a000000000354004b00000000030000190000000103002039000000000303004b000000000400c01900000000030100190000006003300270000000a203300197000000200530008c000000000503001900000020050080390000001f0650018f0000000507500272000001cf0000613d00000000080000190000000509800210000000000a9b0019000000000991034f000000000909043b00000000009a04350000000108800039000000000978004b000001c70000413d000000000806004b000001de0000613d0000000507700210000000000871034f00000001077000290000000306600210000000000907043300000000096901cf000000000969022f000000000808043b0000010006600089000000000868022f00000000066801cf000000000696019f00000000006704350000000102200190000002210000613d0000001f01500039000000600110018f0000000101100029000000a70210009c0000023e0000a13d000000b501000041000000000010043500000041010000390000004a0000013d0000001f0430018f0000000502300272000001f40000613d00000000050000190000000506500210000000000761034f000000000707043b00000000007604350000000105500039000000000625004b000001ed0000413d000000000504004b000002020000613d00000003044002100000000502200210000000000502043300000000054501cf000000000545022f000000000121034f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f000000000012043500000060013002100000028300010430000000400200043d0000001f0430018f0000000505300272000002110000613d000000000600001900000005076002100000000008720019000000000771034f000000000707043b00000000007804350000000106600039000000000756004b000002090000413d000000000604004b000002200000613d0000000505500210000000000151034f00000000055200190000000304400210000000000605043300000000064601cf000000000646022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000161019f0000000000150435000000c30000013d000000400200043d0000001f0430018f00000005053002720000022e0000613d000000000600001900000005076002100000000008720019000000000771034f000000000707043b00000000007804350000000106600039000000000756004b000002260000413d000000000604004b0000023d0000613d0000000505500210000000000151034f00000000055200190000000304400210000000000605043300000000064601cf000000000646022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000161019f0000000000150435000000c30000013d000000400010043f000000200230008c000000a50000413d0000000102000029000000000302043300000000524300a9000000000503004b0000024b0000613d00000000533200d9000000000343004b000000470000c13d000000000302004b0000025b0000c13d0000000603000029000000200130008a0000000000210435000000400130008a00000040020000390000000000210435000000a202000041000000a20310009c00000000010280190000000304000029000000a20340009c000000000402801900000060024002100000004001100210000000000112019f000002820001042e00000000040004140000000403400029000000000443004b000000000400001900000001040040390000000104400190000000470000c13d000001910400008a000000000442004b000000470000213d0000019004200039000000000343004b0000024b0000813d0000004402100039000000b203000041000000000032043500000024021000390000001a030000390000000000320435000000b3020000410000000000210435000000040210003900000020030000390000000000320435000000a202000041000000a20310009c0000000001028019000001000000013d0000027a002104230000000102000039000000000001042d0000000002000019000000000001042d0000027f002104210000000102000039000000000001042d0000000002000019000000000001042d0000028100000432000002820001042e0000028300010430000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0000000200000000000000000000000000000040000001000000000000000000ffffffff0000000000000000000000000000000000000000000000000000000041a8596c00000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000ffffffffffffffff8000000000000000000000000000000000000000000000000000000000000000c0d5b949000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000800000000000000000000000000000000000000000000000000000000000000000000000010000000000000000ffffffff0000000000000000000000000000000000000000000000000100000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001ffffffe000000000000000000000000000000000000000040000000000000000000000007cb9357e000000000000000000000000000000000000000000000000000000004e6f7420656e6f7567682067617320666f72207075626461746100000000000008c379a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000640000000000000000000000004e487b710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000240000000000000000000000004f766572666c6f77000000000000000000000000000000000000000000000000476173206c696d697420697320746f6f206c6f7700000000000000000000000000000000000000000000000000000000000000640000008000000000000000007f588b2c68c838d2b548c578274002018c22ac12a97a1086e075a96f7142768a \ No newline at end of file diff --git a/gas-bound-caller/hardhat.config.ts b/gas-bound-caller/hardhat.config.ts index 2c50fa5fc..8b7211a27 100644 --- a/gas-bound-caller/hardhat.config.ts +++ b/gas-bound-caller/hardhat.config.ts @@ -1,6 +1,7 @@ import "@matterlabs/hardhat-zksync-chai-matchers"; import "@matterlabs/hardhat-zksync-node"; import "@matterlabs/hardhat-zksync-solc"; +import "@matterlabs/hardhat-zksync-verify"; import "@nomiclabs/hardhat-ethers"; import "hardhat-typechain"; @@ -55,6 +56,27 @@ export default { ethNetwork: "localhost", zksync: true, }, + zkSyncStage: { + url: process.env.STAGE2, + ethNetwork: "sepolia", + zksync: true, + // contract verification endpoint + verifyURL: "https://goerli-beta.staging-scan-v2.zksync.dev/contract_verification", + }, + zkSyncTestnet: { + url: "https://sepolia.era.zksync.dev", + ethNetwork: "sepolia", + zksync: true, + // contract verification endpoint + verifyURL: "https://explorer.sepolia.era.zksync.dev/contract_verification", + }, + zksyncMainnet: { + url: "https://mainnet.era.zksync.io", + ethNetwork: "mainnet", + zksync: true, + // contract verification endpoint + verifyURL: "https://zksync2-mainnet-explorer.zksync.io/contract_verification", + }, }, paths: { sources: "./contracts", diff --git a/gas-bound-caller/package.json b/gas-bound-caller/package.json index de6220930..6132cf272 100644 --- a/gas-bound-caller/package.json +++ b/gas-bound-caller/package.json @@ -20,7 +20,9 @@ "devDependencies": { "@matterlabs/hardhat-zksync-chai-matchers": "^0.1.4", "@matterlabs/hardhat-zksync-node": "^0.0.1-beta.7", + "@matterlabs/hardhat-zksync-verify": "^1.4.2", "@nomicfoundation/hardhat-chai-matchers": "^1.0.3", + "@nomicfoundation/hardhat-verify": "^2.0.6", "@nomiclabs/hardhat-ethers": "^2.0.0", "@typechain/ethers-v5": "^2.0.0", "@types/chai": "^4.2.21", @@ -51,10 +53,12 @@ }, "scripts": { "build": "hardhat compile", - "clean": "yarn clean:bootloader && yarn clean:system-contracts", + "clean": "yarn hardhat clean", "test": "yarn build && hardhat test --network zkSyncTestNode", "test-node": "hardhat node-zksync --tag v0.0.1-vm1.5.0", "deploy-on-hyperchain": "ts-node ./scripts/deploy-on-hyperchain.ts", - "deploy-on-localhost": "hardhat deploy --network localhost" + "calculate-canonical-bytecode:check": "ts-node ./scripts/calculate-canonical-bytecode.ts check", + "calculate-canonical-bytecode:fix": "ts-node ./scripts/calculate-canonical-bytecode.ts fix", + "verify": "hardhat run ./scripts/verify.ts" } } diff --git a/gas-bound-caller/scripts/check-canonical-bytecode.ts b/gas-bound-caller/scripts/calculate-canonical-bytecode.ts similarity index 88% rename from gas-bound-caller/scripts/check-canonical-bytecode.ts rename to gas-bound-caller/scripts/calculate-canonical-bytecode.ts index 041e8e9d1..17f5d10e8 100644 --- a/gas-bound-caller/scripts/check-canonical-bytecode.ts +++ b/gas-bound-caller/scripts/calculate-canonical-bytecode.ts @@ -8,8 +8,8 @@ async function main() { program .version("0.1.0") - .name("check canonical bytecode") - .description("Checks that the locally built artifacts match the canonical bytecode"); + .name("calculate canonical bytecode") + .description("A script that is used to check that the locally built artifacts match the canonical bytecode"); program.command("check").action(async () => { const compiledBytecode = (await hre.artifacts.readArtifact("GasBoundCaller")).bytecode; diff --git a/gas-bound-caller/scripts/deploy-on-hyperchain.ts b/gas-bound-caller/scripts/deploy-on-hyperchain.ts index 35d013fd7..8bb407c64 100644 --- a/gas-bound-caller/scripts/deploy-on-hyperchain.ts +++ b/gas-bound-caller/scripts/deploy-on-hyperchain.ts @@ -1,12 +1,9 @@ // hardhat import should be the first import in the file import { ethers } from "ethers"; import { Command } from "commander"; -import { readCanonicalArtifact } from "./utils"; +import { PREDEPLOYED_CREATE2_ADDRESS, getCreate2DeploymentInfo, readCanonicalArtifact } from "./utils"; import { Wallet, Provider, Contract, utils } from "zksync-ethers"; -// This factory should be predeployed on each post-v24 zksync network -const PREDEPLOYED_CREATE2_ADDRESS = "0x0000000000000000000000000000000000010000"; - const singletonFactoryAbi = [ { inputs: [ @@ -47,23 +44,16 @@ async function main() { .name("Deploy on hyperchain") .description("Deploys the GasBoundCaller on a predetermined Hyperchain network") .option("--private-key ") - .option("--l2Rpc ") + .option("--l2-rpc ") .action(async (cmd) => { console.log("Reading the canonical bytecode of the GasBoundCaller"); - const bytecode = readCanonicalArtifact(); + + const { bytecode, bytecodeHash, expectedAddress } = getCreate2DeploymentInfo(); const wallet = new Wallet(cmd.privateKey, new Provider(cmd.l2Rpc)); const singleTonFactory = new Contract(PREDEPLOYED_CREATE2_ADDRESS, singletonFactoryAbi, wallet); - const bytecodeHash = ethers.utils.hexlify(utils.hashBytecode(bytecode)); - - const expectedAddress = utils.create2Address( - PREDEPLOYED_CREATE2_ADDRESS, - bytecodeHash, - ethers.constants.HashZero, - "0x" - ); console.log("Expected address:", expectedAddress); const currentCode = await wallet.provider.getCode(expectedAddress); diff --git a/gas-bound-caller/scripts/utils.ts b/gas-bound-caller/scripts/utils.ts index 81c84b4a7..e5c81d001 100644 --- a/gas-bound-caller/scripts/utils.ts +++ b/gas-bound-caller/scripts/utils.ts @@ -1,4 +1,9 @@ +import { ethers } from "ethers"; import * as fs from "fs"; +import { utils } from "zksync-ethers"; + +// This factory should be predeployed on each post-v24 zksync network +export const PREDEPLOYED_CREATE2_ADDRESS = "0x0000000000000000000000000000000000010000"; const CANONICAL_BYTECODES_PATH = "./canonical-bytecodes/GasBoundCaller"; @@ -9,3 +14,26 @@ export function writeCanonicalArtifact(newBytecode: string) { export function readCanonicalArtifact() { return fs.readFileSync(CANONICAL_BYTECODES_PATH).toString(); } + +export interface Create2DeploymentInfo { + bytecode: string, + bytecodeHash: string, + expectedAddress: string, +} + +export function getCreate2DeploymentInfo(): Create2DeploymentInfo { + const bytecode = readCanonicalArtifact(); + const bytecodeHash = ethers.utils.hexlify(utils.hashBytecode(bytecode)); + const expectedAddress = utils.create2Address( + PREDEPLOYED_CREATE2_ADDRESS, + bytecodeHash, + ethers.constants.HashZero, + "0x" + ); + + return { + bytecode, + bytecodeHash, + expectedAddress, + }; +} diff --git a/gas-bound-caller/scripts/verify.ts b/gas-bound-caller/scripts/verify.ts new file mode 100644 index 000000000..eceec2448 --- /dev/null +++ b/gas-bound-caller/scripts/verify.ts @@ -0,0 +1,37 @@ +// hardhat import should be the first import in the file +import * as hardhat from "hardhat"; +import { getCreate2DeploymentInfo } from "./utils"; + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function verifyPromise(address: string, constructorArguments?: Array, libraries?: object): Promise { + return new Promise((resolve, reject) => { + hardhat + .run("verify:verify", { address, constructorArguments, libraries }) + .then(() => resolve(`Successfully verified ${address}`)) + .catch((e) => reject(`Failed to verify ${address}\nError: ${e.message}`)); + }); +} + +async function main() { + if (process.env.CHAIN_ETH_NETWORK == "localhost") { + console.log("Contract verification not available on localhost"); + return; + } + + const { expectedAddress } = getCreate2DeploymentInfo(); + + const verificationMessage = await verifyPromise(expectedAddress); + + if(verificationMessage.status == "fulfilled") { + console.log(verificationMessage.value); + } else { + console.log(verificationMessage.reason); + } +} + +main() + .then(() => process.exit(0)) + .catch((err) => { + console.error("Error:", err.message || err); + process.exit(1); + }); diff --git a/yarn.lock b/yarn.lock index a1b9caf1e..46c6c3ed2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -768,6 +768,25 @@ chalk "4.1.2" dockerode "^3.3.4" +"@matterlabs/hardhat-zksync-verify@^1.4.2": + version "1.4.2" + resolved "https://registry.yarnpkg.com/@matterlabs/hardhat-zksync-verify/-/hardhat-zksync-verify-1.4.2.tgz#095af84021ad775ae45df3a94c95efd2528714ab" + integrity sha512-GKdb4/5Xx5O9AbwtUnKQELxzVrWzv8HzZtvTJulekNe7+zy43O4AYb0uOjD6jbGRBoTGjWektlh0JYdAHJEdZQ== + dependencies: + "@ethersproject/abi" "^5.1.2" + "@ethersproject/address" "5.7.0" + "@matterlabs/hardhat-zksync-solc" "^1.1.4" + "@nomicfoundation/hardhat-verify" "^2.0.0" + "@openzeppelin/contracts" "^4.9.2" + axios "^1.6.2" + cbor "^8.1.0" + chai "^4.3.6" + chalk "4.1.2" + debug "^4.1.1" + hardhat "^2.19.4" + sinon "^17.0.1" + sinon-chai "^3.7.0" + "@matterlabs/prettier-config@^1.0.3": version "1.0.3" resolved "https://registry.yarnpkg.com/@matterlabs/prettier-config/-/prettier-config-1.0.3.tgz#3e2eb559c0112bbe9671895f935700dad2a15d38" @@ -837,31 +856,61 @@ resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-darwin-arm64/-/edr-darwin-arm64-0.3.4.tgz#e5aac2b7726f44cffe120bdd7e25e1f120471591" integrity sha512-tjavrUFLWnkn0PI+jk0D83hP2jjbmeXT1QLd5NtIleyGrJ00ZWVl+sfuA2Lle3kzfOceoI2VTR0n1pZB4KJGbQ== +"@nomicfoundation/edr-darwin-arm64@0.3.7": + version "0.3.7" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-darwin-arm64/-/edr-darwin-arm64-0.3.7.tgz#c204edc79643624dbd431b489b254778817d8244" + integrity sha512-6tK9Lv/lSfyBvpEQ4nsTfgxyDT1y1Uv/x8Wa+aB+E8qGo3ToexQ1BMVjxJk6PChXCDOWxB3B4KhqaZFjdhl3Ow== + "@nomicfoundation/edr-darwin-x64@0.3.4": version "0.3.4" resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-darwin-x64/-/edr-darwin-x64-0.3.4.tgz#cbcc0a2dcda0a7c0a900a74efc6918cff134dc23" integrity sha512-dXO0vlIoBosp8gf5/ah3dESMymjwit0Daef1E4Ew3gZ8q3LAdku0RC+YEQJi9f0I3QNfdgIrBTzibRZUoP+kVA== +"@nomicfoundation/edr-darwin-x64@0.3.7": + version "0.3.7" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-darwin-x64/-/edr-darwin-x64-0.3.7.tgz#c3b394445084270cc5250d6c1869b0574e7ef810" + integrity sha512-1RrQ/1JPwxrYO69e0tglFv5H+ggour5Ii3bb727+yBpBShrxtOTQ7fZyfxA5h62LCN+0Z9wYOPeQ7XFcVurMaQ== + "@nomicfoundation/edr-linux-arm64-gnu@0.3.4": version "0.3.4" resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-arm64-gnu/-/edr-linux-arm64-gnu-0.3.4.tgz#12073f97d310176bb24ad7d48c25128ea8eff093" integrity sha512-dv38qmFUaqkkeeA9S0JjerqruytTfHav7gbPLpZUAEXPlJGo49R0+HQxd45I0msbm6NAXbkmKEchTLApp1ohaA== +"@nomicfoundation/edr-linux-arm64-gnu@0.3.7": + version "0.3.7" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-arm64-gnu/-/edr-linux-arm64-gnu-0.3.7.tgz#6d65545a44d1323bb7ab08c3306947165d2071de" + integrity sha512-ds/CKlBoVXIihjhflhgPn13EdKWed6r5bgvMs/YwRqT5wldQAQJZWAfA2+nYm0Yi2gMGh1RUpBcfkyl4pq7G+g== + "@nomicfoundation/edr-linux-arm64-musl@0.3.4": version "0.3.4" resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-arm64-musl/-/edr-linux-arm64-musl-0.3.4.tgz#c9bc685d4d14bf21d9c3e326edd44e009e24492d" integrity sha512-CfEsb6gdCMVIlRSpWYTxoongEKHB60V6alE/y8mkfjIo7tA95wyiuvCtyo3fpiia3wQV7XoMYgIJHObHiKLKtA== +"@nomicfoundation/edr-linux-arm64-musl@0.3.7": + version "0.3.7" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-arm64-musl/-/edr-linux-arm64-musl-0.3.7.tgz#5368534bceac1a8c18b1be6b908caca5d39b0c03" + integrity sha512-e29udiRaPujhLkM3+R6ju7QISrcyOqpcaxb2FsDWBkuD7H8uU9JPZEyyUIpEp5uIY0Jh1eEJPKZKIXQmQAEAuw== + "@nomicfoundation/edr-linux-x64-gnu@0.3.4": version "0.3.4" resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-x64-gnu/-/edr-linux-x64-gnu-0.3.4.tgz#37486cbe317b8caf7961e500fc0150c45c895a56" integrity sha512-V0CpJA2lYWulgTR+zP11ftBAEwkpMAAki/AuMu3vd7HoPfjwIDzWDQR5KFU17qFmqAVz0ICRxsxDlvvBZ/PUxA== +"@nomicfoundation/edr-linux-x64-gnu@0.3.7": + version "0.3.7" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-x64-gnu/-/edr-linux-x64-gnu-0.3.7.tgz#42349bf5941dbb54a5719942924c6e4e8cde348e" + integrity sha512-/xkjmTyv+bbJ4akBCW0qzFKxPOV4AqLOmqurov+s9umHb16oOv72osSa3SdzJED2gHDaKmpMITT4crxbar4Axg== + "@nomicfoundation/edr-linux-x64-musl@0.3.4": version "0.3.4" resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-x64-musl/-/edr-linux-x64-musl-0.3.4.tgz#399278807100a1833f6c8a39c17d5beaaf7a9223" integrity sha512-0sgTrwZajarukerU/QSb+oRdlQLnJdd7of8OlXq2wtpeTNTqemgCOwY2l2qImbWboMpVrYgcmGbINXNVPCmuJw== +"@nomicfoundation/edr-linux-x64-musl@0.3.7": + version "0.3.7" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-x64-musl/-/edr-linux-x64-musl-0.3.7.tgz#e6babe11c9a8012f1284e6e48c3551861f2a7cd4" + integrity sha512-QwBP9xlmsbf/ldZDGLcE4QiAb8Zt46E/+WLpxHBATFhGa7MrpJh6Zse+h2VlrT/SYLPbh2cpHgSmoSlqVxWG9g== + "@nomicfoundation/edr-win32-arm64-msvc@0.3.4": version "0.3.4" resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-win32-arm64-msvc/-/edr-win32-arm64-msvc-0.3.4.tgz#879028e2708538fd54efc349c1a4de107a15abb4" @@ -877,6 +926,11 @@ resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-win32-x64-msvc/-/edr-win32-x64-msvc-0.3.4.tgz#abfc447eb6bd1a9be868bec5c9d14546398ab609" integrity sha512-fResvsL/fSucep1K5W6iOs8lqqKKovHLsAmigMzAYVovqkyZKgCGVS/D8IVxA0nxuGCOlNxFnVmwWtph3pbKWA== +"@nomicfoundation/edr-win32-x64-msvc@0.3.7": + version "0.3.7" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-win32-x64-msvc/-/edr-win32-x64-msvc-0.3.7.tgz#1504b98f305f03be153b0220a546985660de9dc6" + integrity sha512-j/80DEnkxrF2ewdbk/gQ2EOPvgF0XSsg8D0o4+6cKhUVAW6XwtWKzIphNL6dyD2YaWEPgIrNvqiJK/aln0ww4Q== + "@nomicfoundation/edr@^0.3.1": version "0.3.4" resolved "https://registry.yarnpkg.com/@nomicfoundation/edr/-/edr-0.3.4.tgz#e8eaf41963460139c47b0785f1a6a2a1c1b24ae0" @@ -892,6 +946,19 @@ "@nomicfoundation/edr-win32-ia32-msvc" "0.3.4" "@nomicfoundation/edr-win32-x64-msvc" "0.3.4" +"@nomicfoundation/edr@^0.3.5": + version "0.3.7" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr/-/edr-0.3.7.tgz#9c75edf1fcf601617905b2c89acf103f4786d017" + integrity sha512-v2JFWnFKRsnOa6PDUrD+sr8amcdhxnG/YbL7LzmgRGU1odWEyOF4/EwNeUajQr4ZNKVWrYnJ6XjydXtUge5OBQ== + optionalDependencies: + "@nomicfoundation/edr-darwin-arm64" "0.3.7" + "@nomicfoundation/edr-darwin-x64" "0.3.7" + "@nomicfoundation/edr-linux-arm64-gnu" "0.3.7" + "@nomicfoundation/edr-linux-arm64-musl" "0.3.7" + "@nomicfoundation/edr-linux-x64-gnu" "0.3.7" + "@nomicfoundation/edr-linux-x64-musl" "0.3.7" + "@nomicfoundation/edr-win32-x64-msvc" "0.3.7" + "@nomicfoundation/ethereumjs-common@4.0.4": version "4.0.4" resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-common/-/ethereumjs-common-4.0.4.tgz#9901f513af2d4802da87c66d6f255b510bef5acb" @@ -956,6 +1023,21 @@ table "^6.8.0" undici "^5.14.0" +"@nomicfoundation/hardhat-verify@^2.0.0", "@nomicfoundation/hardhat-verify@^2.0.6": + version "2.0.6" + resolved "https://registry.yarnpkg.com/@nomicfoundation/hardhat-verify/-/hardhat-verify-2.0.6.tgz#02623c431244c92a852c524008239fc616e1c658" + integrity sha512-oKUI5fl8QC8jysE2LUBHE6rObzEmccJcc4b43Ov7LFMlCBZJE27qoqGIsg/++wX7L8Jdga+bkejPxl8NvsecpQ== + dependencies: + "@ethersproject/abi" "^5.1.2" + "@ethersproject/address" "^5.0.2" + cbor "^8.1.0" + chalk "^2.4.2" + debug "^4.1.1" + lodash.clonedeep "^4.5.0" + semver "^6.3.0" + table "^6.8.0" + undici "^5.14.0" + "@nomicfoundation/solidity-analyzer-darwin-arm64@0.1.1": version "0.1.1" resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-darwin-arm64/-/solidity-analyzer-darwin-arm64-0.1.1.tgz#4c858096b1c17fe58a474fe81b46815f93645c15" @@ -1067,6 +1149,11 @@ resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.5.tgz#1eed23d4844c861a1835b5d33507c1017fa98de8" integrity sha512-ZK+W5mVhRppff9BE6YdR8CC52C8zAvsVAiWhEtQ5+oNxFE6h1WdeWo+FJSF8KKvtxxVYZ7MTP/5KoVpAU3aSWg== +"@openzeppelin/contracts@^4.9.2": + version "4.9.6" + resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.6.tgz#2a880a24eb19b4f8b25adc2a5095f2aa27f39677" + integrity sha512-xSmezSupL+y9VkHZJGDoCBpmnB2ogM13ccaYDWqJTfS3dbuHkgjuwDFUmaFauBCboQMGB/S5UqUl2y54X99BmA== + "@pkgr/core@^0.1.0": version "0.1.1" resolved "https://registry.yarnpkg.com/@pkgr/core/-/core-0.1.1.tgz#1ec17e2edbec25c8306d424ecfbf13c7de1aaa31" @@ -2002,7 +2089,7 @@ axios@^0.21.1: dependencies: follow-redirects "^1.14.0" -axios@^1.4.0, axios@^1.5.1: +axios@^1.4.0, axios@^1.5.1, axios@^1.6.2: version "1.6.8" resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.8.tgz#66d294951f5d988a00e87a0ffb955316a619ea66" integrity sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ== @@ -4154,6 +4241,55 @@ hardhat@^2.18.3: uuid "^8.3.2" ws "^7.4.6" +hardhat@^2.19.4: + version "2.22.3" + resolved "https://registry.yarnpkg.com/hardhat/-/hardhat-2.22.3.tgz#50605daca6b29862397e446c42ec14c89430bec3" + integrity sha512-k8JV2ECWNchD6ahkg2BR5wKVxY0OiKot7fuxiIpRK0frRqyOljcR2vKwgWSLw6YIeDcNNA4xybj7Og7NSxr2hA== + dependencies: + "@ethersproject/abi" "^5.1.2" + "@metamask/eth-sig-util" "^4.0.0" + "@nomicfoundation/edr" "^0.3.5" + "@nomicfoundation/ethereumjs-common" "4.0.4" + "@nomicfoundation/ethereumjs-tx" "5.0.4" + "@nomicfoundation/ethereumjs-util" "9.0.4" + "@nomicfoundation/solidity-analyzer" "^0.1.0" + "@sentry/node" "^5.18.1" + "@types/bn.js" "^5.1.0" + "@types/lru-cache" "^5.1.0" + adm-zip "^0.4.16" + aggregate-error "^3.0.0" + ansi-escapes "^4.3.0" + boxen "^5.1.2" + chalk "^2.4.2" + chokidar "^3.4.0" + ci-info "^2.0.0" + debug "^4.1.1" + enquirer "^2.3.0" + env-paths "^2.2.0" + ethereum-cryptography "^1.0.3" + ethereumjs-abi "^0.6.8" + find-up "^2.1.0" + fp-ts "1.19.3" + fs-extra "^7.0.1" + glob "7.2.0" + immutable "^4.0.0-rc.12" + io-ts "1.10.4" + keccak "^3.0.2" + lodash "^4.17.11" + mnemonist "^0.38.0" + mocha "^10.0.0" + p-map "^4.0.0" + raw-body "^2.4.1" + resolve "1.17.0" + semver "^6.3.0" + solc "0.7.3" + source-map-support "^0.5.13" + stacktrace-parser "^0.1.10" + tsort "0.0.1" + undici "^5.14.0" + uuid "^8.3.2" + ws "^7.4.6" + has-bigints@^1.0.1, has-bigints@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/has-bigints/-/has-bigints-1.0.2.tgz#0871bd3e3d51626f6ca0966668ba35d5602d6eaa" From 6afb3abdb5d25f2ea9a0fa261510945c88e13f81 Mon Sep 17 00:00:00 2001 From: Stanislav Breadless Date: Tue, 7 May 2024 13:36:47 +0200 Subject: [PATCH 2/8] lint fix + move gas bound caller to separate file --- .github/workflows/gas-bound-caller-ci.yaml | 92 +++++++++++++++++++ .github/workflows/l2-contracts-ci.yaml | 33 ------- gas-bound-caller/README.md | 9 +- .../scripts/deploy-on-hyperchain.ts | 4 +- gas-bound-caller/scripts/utils.ts | 6 +- gas-bound-caller/scripts/verify.ts | 2 +- l1-contracts/test/unit_tests/utils.ts | 6 +- system-contracts/contracts/DefaultAccount.sol | 1 + 8 files changed, 104 insertions(+), 49 deletions(-) create mode 100644 .github/workflows/gas-bound-caller-ci.yaml diff --git a/.github/workflows/gas-bound-caller-ci.yaml b/.github/workflows/gas-bound-caller-ci.yaml new file mode 100644 index 000000000..8ae23a8b7 --- /dev/null +++ b/.github/workflows/gas-bound-caller-ci.yaml @@ -0,0 +1,92 @@ +name: GasBoundCaller CI + +on: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: 18.18.0 + cache: yarn + + - name: Install dependencies + run: yarn + + - name: Build L1 artifacts + run: yarn gas-bound-caller build + + - name: Check the correcntess of the canonical bytecode + run: yarn gas-bound-caller calculate-canonical-bytecode:check + + - name: Create cache + uses: actions/cache/save@v3 + with: + key: artifacts-gas-bound-caller-${{ github.sha }} + path: | + gas-bound-caller/artifacts-zk + gas-bound-caller/cache-zk + gas-bound-caller/typechain + + lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: 18.18.0 + cache: yarn + + - name: Install dependencies + run: yarn + + - name: Lint + run: yarn lint:check + + test: + needs: [build, lint] + runs-on: ubuntu-latest + + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: 18.18.0 + cache: yarn + + - name: Install dependencies + run: yarn + + - name: Restore artifacts cache + uses: actions/cache/restore@v3 + with: + fail-on-cache-miss: true + key: artifacts-gas-bound-caller-${{ github.sha }} + path: | + gas-bound-caller/artifacts-zk + gas-bound-caller/cache-zk + gas-bound-caller/typechain + + - name: Use era-test-node for testing + uses: dutterbutter/era-test-node-action@v0.1.3 + with: + releaseTag: v0.0.1-vm1.5.0 + + - name: Run tests + run: yarn gas-bound-caller test diff --git a/.github/workflows/l2-contracts-ci.yaml b/.github/workflows/l2-contracts-ci.yaml index caae76c5e..20bb9583f 100644 --- a/.github/workflows/l2-contracts-ci.yaml +++ b/.github/workflows/l2-contracts-ci.yaml @@ -94,36 +94,3 @@ jobs: - name: Run tests run: yarn l2 test - - gas-bound-caller: - needs: [build, lint] - runs-on: ubuntu-latest - - steps: - - name: Checkout the repository - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Use Node.js - uses: actions/setup-node@v3 - with: - node-version: 18.18.0 - cache: yarn - - - name: Install dependencies - run: yarn - - - name: Build GasBoundCaller - run: yarn gas-bound-caller build - - - name: CHeck the correcntess of the canonical bytecode - run: yarn gas-bound-caller calculate-canonical-bytecode:check - - - name: Use era-test-node for testing - uses: dutterbutter/era-test-node-action@v0.1.3 - with: - releaseTag: v0.0.1-vm1.5.0 - - - name: Run tests - run: yarn gas-bound-caller test diff --git a/gas-bound-caller/README.md b/gas-bound-caller/README.md index 678a343e1..2aa1276c3 100644 --- a/gas-bound-caller/README.md +++ b/gas-bound-caller/README.md @@ -56,8 +56,7 @@ yarn deploy-on-hyperchain --private-key --l2-rpc ### Deployed addresses -| Network | Address | -| -------- | ------- | -| Era Testnet | [0xDaAD9137Deec2FCbB8C4aB3820553E0da60328b6](https://sepolia.explorer.zksync.io/address/0xDaAD9137Deec2FCbB8C4aB3820553E0da60328b6#contract) | -| Era Mainnet | TODO | - +| Network | Address | +| ----------- | -------------------------------------------------------------------------------------------------------------------------------------------- | +| Era Testnet | [0xDaAD9137Deec2FCbB8C4aB3820553E0da60328b6](https://sepolia.explorer.zksync.io/address/0xDaAD9137Deec2FCbB8C4aB3820553E0da60328b6#contract) | +| Era Mainnet | TODO | diff --git a/gas-bound-caller/scripts/deploy-on-hyperchain.ts b/gas-bound-caller/scripts/deploy-on-hyperchain.ts index 8bb407c64..8366136dd 100644 --- a/gas-bound-caller/scripts/deploy-on-hyperchain.ts +++ b/gas-bound-caller/scripts/deploy-on-hyperchain.ts @@ -1,8 +1,8 @@ // hardhat import should be the first import in the file import { ethers } from "ethers"; import { Command } from "commander"; -import { PREDEPLOYED_CREATE2_ADDRESS, getCreate2DeploymentInfo, readCanonicalArtifact } from "./utils"; -import { Wallet, Provider, Contract, utils } from "zksync-ethers"; +import { PREDEPLOYED_CREATE2_ADDRESS, getCreate2DeploymentInfo } from "./utils"; +import { Wallet, Provider, Contract } from "zksync-ethers"; const singletonFactoryAbi = [ { diff --git a/gas-bound-caller/scripts/utils.ts b/gas-bound-caller/scripts/utils.ts index e5c81d001..f6e9e6255 100644 --- a/gas-bound-caller/scripts/utils.ts +++ b/gas-bound-caller/scripts/utils.ts @@ -16,9 +16,9 @@ export function readCanonicalArtifact() { } export interface Create2DeploymentInfo { - bytecode: string, - bytecodeHash: string, - expectedAddress: string, + bytecode: string; + bytecodeHash: string; + expectedAddress: string; } export function getCreate2DeploymentInfo(): Create2DeploymentInfo { diff --git a/gas-bound-caller/scripts/verify.ts b/gas-bound-caller/scripts/verify.ts index eceec2448..2b1b5225c 100644 --- a/gas-bound-caller/scripts/verify.ts +++ b/gas-bound-caller/scripts/verify.ts @@ -22,7 +22,7 @@ async function main() { const verificationMessage = await verifyPromise(expectedAddress); - if(verificationMessage.status == "fulfilled") { + if (verificationMessage.status == "fulfilled") { console.log(verificationMessage.value); } else { console.log(verificationMessage.reason); diff --git a/l1-contracts/test/unit_tests/utils.ts b/l1-contracts/test/unit_tests/utils.ts index fd34a0e7f..4a0342db8 100644 --- a/l1-contracts/test/unit_tests/utils.ts +++ b/l1-contracts/test/unit_tests/utils.ts @@ -59,11 +59,7 @@ export const REQUIRED_L2_GAS_PRICE_PER_PUBDATA = /// Set of parameters that are needed to test the processing of priority operations export class DummyOp { - constructor( - public id: number, - public expirationBatch: BigNumber, - public layer2Tip: number - ) {} + constructor(public id: number, public expirationBatch: BigNumber, public layer2Tip: number) {} } export async function getCallRevertReason(promise) { diff --git a/system-contracts/contracts/DefaultAccount.sol b/system-contracts/contracts/DefaultAccount.sol index 4c7356dd8..6d4f90d7a 100644 --- a/system-contracts/contracts/DefaultAccount.sol +++ b/system-contracts/contracts/DefaultAccount.sol @@ -230,6 +230,7 @@ contract DefaultAccount is IAccount { assert(msg.sender != BOOTLOADER_FORMAL_ADDRESS); // If the contract is called directly, behave like an EOA + } receive() external payable { From 74ffddb04ba75f7c6b08cfd08d0a571e6c4842a7 Mon Sep 17 00:00:00 2001 From: Stanislav Breadless Date: Tue, 7 May 2024 15:10:44 +0200 Subject: [PATCH 3/8] turn off prettier in eslint due to conflicts --- .eslintrc | 3 ++- .prettierignore | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index 077931cae..e346d3460 100644 --- a/.eslintrc +++ b/.eslintrc @@ -8,7 +8,8 @@ "import/namespace": "off", "import/no-unresolved": "off", "import/order": "off", - "no-console": "off" + "no-console": "off", + "prettier/prettier": "off" }, "ignorePatterns": [ "**/lib/*" diff --git a/.prettierignore b/.prettierignore index 5bc4f9aa7..7d6ff1567 100644 --- a/.prettierignore +++ b/.prettierignore @@ -6,6 +6,10 @@ system-contracts/contracts/Constants.sol system-contracts/artifacts-zk system-contracts/cache-zk system-contracts/contracts-preprocessed +system-contracts/typechain +gas-bound-caller/artifacts-zk +gas-bound-caller/cache-zk +gas-bound-caller/typechain l1-contracts/cache l1-contracts/cache-forge l1-contracts/artifacts From 97b4731d994ce8f5f93f8f18312ef32828362b7c Mon Sep 17 00:00:00 2001 From: Stanislav Breadless Date: Tue, 7 May 2024 15:14:29 +0200 Subject: [PATCH 4/8] lint fix --- .github/workflows/slither.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/slither.yaml b/.github/workflows/slither.yaml index ea278b2a3..fa253e159 100644 --- a/.github/workflows/slither.yaml +++ b/.github/workflows/slither.yaml @@ -44,5 +44,5 @@ jobs: - name: Run Slither run: | - cd l1-contracts - slither --config ./slither.config.json . + cd l1-contracts + slither --config ./slither.config.json . From 2a947229394edcded3e379beee353a9e10acc94a Mon Sep 17 00:00:00 2001 From: Stanislav Breadless Date: Tue, 7 May 2024 15:16:41 +0200 Subject: [PATCH 5/8] lint fix 2 --- .eslintrc | 3 +-- l1-contracts/test/unit_tests/utils.ts | 6 +++++- system-contracts/contracts/DefaultAccount.sol | 1 - 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.eslintrc b/.eslintrc index e346d3460..077931cae 100644 --- a/.eslintrc +++ b/.eslintrc @@ -8,8 +8,7 @@ "import/namespace": "off", "import/no-unresolved": "off", "import/order": "off", - "no-console": "off", - "prettier/prettier": "off" + "no-console": "off" }, "ignorePatterns": [ "**/lib/*" diff --git a/l1-contracts/test/unit_tests/utils.ts b/l1-contracts/test/unit_tests/utils.ts index 4a0342db8..fd34a0e7f 100644 --- a/l1-contracts/test/unit_tests/utils.ts +++ b/l1-contracts/test/unit_tests/utils.ts @@ -59,7 +59,11 @@ export const REQUIRED_L2_GAS_PRICE_PER_PUBDATA = /// Set of parameters that are needed to test the processing of priority operations export class DummyOp { - constructor(public id: number, public expirationBatch: BigNumber, public layer2Tip: number) {} + constructor( + public id: number, + public expirationBatch: BigNumber, + public layer2Tip: number + ) {} } export async function getCallRevertReason(promise) { diff --git a/system-contracts/contracts/DefaultAccount.sol b/system-contracts/contracts/DefaultAccount.sol index 6d4f90d7a..4c7356dd8 100644 --- a/system-contracts/contracts/DefaultAccount.sol +++ b/system-contracts/contracts/DefaultAccount.sol @@ -230,7 +230,6 @@ contract DefaultAccount is IAccount { assert(msg.sender != BOOTLOADER_FORMAL_ADDRESS); // If the contract is called directly, behave like an EOA - } receive() external payable { From 21a867c51da38d597e0ad88a431557c63721c823 Mon Sep 17 00:00:00 2001 From: Stanislav Breadless Date: Tue, 7 May 2024 15:17:21 +0200 Subject: [PATCH 6/8] fix --- gas-bound-caller/hardhat.config.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/gas-bound-caller/hardhat.config.ts b/gas-bound-caller/hardhat.config.ts index 8b7211a27..4aa9b9149 100644 --- a/gas-bound-caller/hardhat.config.ts +++ b/gas-bound-caller/hardhat.config.ts @@ -56,13 +56,6 @@ export default { ethNetwork: "localhost", zksync: true, }, - zkSyncStage: { - url: process.env.STAGE2, - ethNetwork: "sepolia", - zksync: true, - // contract verification endpoint - verifyURL: "https://goerli-beta.staging-scan-v2.zksync.dev/contract_verification", - }, zkSyncTestnet: { url: "https://sepolia.era.zksync.dev", ethNetwork: "sepolia", From 55b5fb12e3c555ffb262d8cd55bf57dc613c4d0a Mon Sep 17 00:00:00 2001 From: Stanislav Breadless Date: Tue, 7 May 2024 15:26:28 +0200 Subject: [PATCH 7/8] fix testing gas bound caller --- .github/workflows/gas-bound-caller-ci.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/gas-bound-caller-ci.yaml b/.github/workflows/gas-bound-caller-ci.yaml index 8ae23a8b7..ab570de91 100644 --- a/.github/workflows/gas-bound-caller-ci.yaml +++ b/.github/workflows/gas-bound-caller-ci.yaml @@ -88,5 +88,10 @@ jobs: with: releaseTag: v0.0.1-vm1.5.0 + # The tests of GasBoundCaller reuse utility methods of the system contracts tests, + # so we need to deploy those also. + - name: Build system contracts + run: yarn sc build + - name: Run tests run: yarn gas-bound-caller test From 221f237823c629da228efc7e307a2ab3c5f9a2d7 Mon Sep 17 00:00:00 2001 From: Vlad Bochok <41153528+vladbochok@users.noreply.github.com> Date: Tue, 7 May 2024 18:26:10 +0100 Subject: [PATCH 8/8] Add CI coverage (#451) --- .github/workflows/l1-contracts-ci.yaml | 70 ++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/.github/workflows/l1-contracts-ci.yaml b/.github/workflows/l1-contracts-ci.yaml index 2123b47cb..d761b63ed 100644 --- a/.github/workflows/l1-contracts-ci.yaml +++ b/.github/workflows/l1-contracts-ci.yaml @@ -145,3 +145,73 @@ jobs: - name: Compare run: diff tools/data/Verifier.sol l1-contracts/contracts/state-transition/Verifier.sol + + coverage: + defaults: + run: + working-directory: l1-contracts + needs: [build, lint] + runs-on: ubuntu-latest + + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Use Foundry + uses: foundry-rs/foundry-toolchain@v1 + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: 18.18.0 + cache: yarn + + - name: Install dependencies + run: yarn + + - name: Restore artifacts cache + uses: actions/cache/restore@v3 + with: + fail-on-cache-miss: true + key: artifacts-l1-${{ github.sha }} + path: | + l1-contracts/artifacts + l1-contracts/cache + l1-contracts/typechain + + - name: Run coverage + run: FOUNDRY_PROFILE=default yarn test:foundry && FOUNDRY_PROFILE=default yarn coverage:foundry --report summary --report lcov + + # To ignore coverage for certain directories modify the paths in this step as needed. The + # below default ignores coverage results for the test and script directories. Alternatively, + # to include coverage in all directories, comment out this step. Note that because this + # filtering applies to the lcov file, the summary table generated in the previous step will + # still include all files and directories. + # The `--rc lcov_branch_coverage=1` part keeps branch info in the filtered report, since lcov + # defaults to removing branch info. + - name: Filter directories + run: | + sudo apt update && sudo apt install -y lcov + lcov --remove lcov.info 'test/*' 'contracts/dev-contracts/*' 'lib/*' --output-file lcov.info --rc lcov_branch_coverage=1 + + # This step posts a detailed coverage report as a comment and deletes previous comments on + # each push. The below step is used to fail coverage if the specified coverage threshold is + # not met. The below step can post a comment (when it's `github-token` is specified) but it's + # not as useful, and this action cannot fail CI based on a minimum coverage threshold, which + # is why we use both in this way. + - name: Post coverage report + if: github.event_name == 'pull_request' # This action fails when ran outside of a pull request. + uses: romeovs/lcov-reporter-action@v0.3.1 + with: + delete-old-comments: true + lcov-file: ./l1-contracts/lcov.info + github-token: ${{ secrets.GITHUB_TOKEN }} # Adds a coverage summary comment to the PR. + + - name: Verify minimum coverage + uses: zgosalvez/github-actions-report-lcov@v2 + with: + coverage-files: ./l1-contracts/lcov.info + working-directory: l1-contracts + minimum-coverage: 85 # Set coverage threshold.