From 1c701af05fff55efdb37584db6fc4339077e1c33 Mon Sep 17 00:00:00 2001 From: invocamanman Date: Thu, 14 Mar 2024 13:13:12 +0100 Subject: [PATCH] add claim compressor deplyoment --- .githooks/pre-commit | 3 + compiled-contracts/ClaimCompressor.json | 116 ++++++++++++++++++ .../deployClaimCompressor.ts | 85 +++++++++++++ .../deploy_claimCompressor.json.example | 8 ++ 4 files changed, 212 insertions(+) create mode 100644 compiled-contracts/ClaimCompressor.json create mode 100644 tools/deployClaimCompressor/deployClaimCompressor.ts create mode 100644 tools/deployClaimCompressor/deploy_claimCompressor.json.example diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 0d12d192d..89c92e9b8 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -37,6 +37,9 @@ if npm run lint; then cp artifacts/contracts/v2/consensus/validium/PolygonValidiumEtrog.sol/PolygonValidiumEtrog.json compiled-contracts/ cp artifacts/contracts/v2/consensus/validium/PolygonDataCommittee.sol/PolygonDataCommittee.json compiled-contracts/ + + cp artifacts/contracts/v2/utils/ClaimCompressor.sol/ClaimCompressor.json compiled-contracts/ + git add compiled-contracts exit 0 else diff --git a/compiled-contracts/ClaimCompressor.json b/compiled-contracts/ClaimCompressor.json new file mode 100644 index 000000000..f099f8ac9 --- /dev/null +++ b/compiled-contracts/ClaimCompressor.json @@ -0,0 +1,116 @@ +{ + "_format": "hh-sol-artifact-1", + "contractName": "ClaimCompressor", + "sourceName": "contracts/v2/utils/ClaimCompressor.sol", + "abi": [ + { + "inputs": [ + { + "internalType": "address", + "name": "__bridgeAddress", + "type": "address" + }, + { + "internalType": "uint32", + "name": "__networkID", + "type": "uint32" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "mainnetExitRoot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "rollupExitRoot", + "type": "bytes32" + }, + { + "components": [ + { + "internalType": "bytes32[32]", + "name": "smtProofLocalExitRoot", + "type": "bytes32[32]" + }, + { + "internalType": "bytes32[32]", + "name": "smtProofRollupExitRoot", + "type": "bytes32[32]" + }, + { + "internalType": "uint256", + "name": "globalIndex", + "type": "uint256" + }, + { + "internalType": "uint32", + "name": "originNetwork", + "type": "uint32" + }, + { + "internalType": "address", + "name": "originAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "destinationAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "metadata", + "type": "bytes" + }, + { + "internalType": "bool", + "name": "isMessage", + "type": "bool" + } + ], + "internalType": "struct ClaimCompressor.CompressClaimCallData[]", + "name": "compressClaimCalldata", + "type": "tuple[]" + } + ], + "name": "compressClaimCall", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "compressedClaimCalls", + "type": "bytes" + } + ], + "name": "sendCompressedClaims", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } + ], + "bytecode": "0x60c060405234801561000f575f80fd5b50604051610dd5380380610dd583398101604081905261002e9161004a565b6001600160a01b0390911660805263ffffffff1660a052610095565b5f806040838503121561005b575f80fd5b82516001600160a01b0381168114610071575f80fd5b602084015190925063ffffffff8116811461008a575f80fd5b809150509250929050565b60805160a051610d1f6100b65f395f61043201525f6104540152610d1f5ff3fe608060405234801561000f575f80fd5b5060043610610034575f3560e01c806304e5557b1461003857806397b1410f14610061575b5f80fd5b61004b6100463660046105e9565b610076565b6040516100589190610687565b60405180910390f35b61007461006f3660046106d7565b61042b565b005b60605f8585604051602001610095929190918252602082015260400190565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815291905290505f805b8481101561041f575f8686838181106100e3576100e3610743565b90506020028101906100f59190610770565b6100fe9061095f565b90505f825f03610110575060206101a0565b5f5b602081101561019e578888610128600187610a55565b81811061013757610137610743565b90506020028101906101499190610770565b816020811061015a5761015a610743565b6020020135835f0151826020811061017457610174610743565b60200201511461018c57610189816001610a6e565b91505b8061019681610a81565b915050610112565b505b6040805160f883901b7fff000000000000000000000000000000000000000000000000000000000000001660208201528151600181830301815260219091019091525f5b8281101561023b5783518290826020811061020157610201610743565b6020020151604051602001610217929190610ad3565b6040516020818303038152906040529150808061023390610a81565b9150506101e4565b506020830151515f9250156102fd57831580610255575084155b1561026357602091506102f8565b5f5b60208110156102f657898961027b600188610a55565b81811061028a5761028a610743565b905060200281019061029c9190610770565b6104000181602081106102b1576102b1610743565b6020020135846020015182602081106102cc576102cc610743565b6020020151146102e4576102e1816001610a6e565b92505b806102ee81610a81565b915050610265565b505b600194505b8082604051602001610310929190610af4565b60405160208183030381529060405290505f5b8281101561037c57818460200151826020811061034257610342610743565b6020020151604051602001610358929190610ad3565b6040516020818303038152906040529150808061037490610a81565b915050610323565b505f83610100015161038e575f610391565b60015b6040858101516060870151608088015160a089015160c08a015160e08b0151805187516103d399988c989081901c979096909590949093909291602001610b3d565b604051602081830303815290604052905086816040516020016103f7929190610cbb565b604051602081830303815290604052965050505050808061041790610a81565b9150506100c8565b50909695505050505050565b63ffffffff7f0000000000000000000000000000000000000000000000000000000000000000167f000000000000000000000000000000000000000000000000000000000000000063ccaa2d1163f5efcd798585602082610824376020828101610844376108a486905261092061090452604082015b8183018110156105de57803560f81c80156104c357600181146104e0576104f9565b856003538560081c6002538560101c6001538560181c5f536104f9565b846003538460081c6002538460101c6001538460181c5f535b5060028101906004906001013560f81c60200280838337909101600181019161040001906020903560f81c02808383379190910190610400810190823560f81c9061041701536001820191506008826018830137600882019150606081019050600482601c830137600482019150602081019050601482600c83013760149182019160408201918390604c01376014820191506020810190506020828237602082013560e01c60408201819052602490920191606090910190808383375f91810182905291820191601f80821660200316016109440190808281808b5af150506104a1565b505050505050505050565b5f805f80606085870312156105fc575f80fd5b8435935060208501359250604085013567ffffffffffffffff80821115610621575f80fd5b818701915087601f830112610634575f80fd5b813581811115610642575f80fd5b8860208260051b8501011115610656575f80fd5b95989497505060200194505050565b5f5b8381101561067f578181015183820152602001610667565b50505f910152565b602081525f82518060208401526106a5816040850160208701610665565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169190910160400192915050565b5f80602083850312156106e8575f80fd5b823567ffffffffffffffff808211156106ff575f80fd5b818501915085601f830112610712575f80fd5b813581811115610720575f80fd5b866020828501011115610731575f80fd5b60209290920196919550909350505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f82357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7218336030181126107a2575f80fd5b9190910192915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b604051610120810167ffffffffffffffff811182821017156107fd576107fd6107ac565b60405290565b5f82601f830112610812575f80fd5b60405161040080820182811067ffffffffffffffff82111715610837576108376107ac565b60405283018185821115610849575f80fd5b845b8281101561086357803582526020918201910161084b565b509195945050505050565b803563ffffffff81168114610881575f80fd5b919050565b803573ffffffffffffffffffffffffffffffffffffffff81168114610881575f80fd5b5f82601f8301126108b8575f80fd5b813567ffffffffffffffff808211156108d3576108d36107ac565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f01168101908282118183101715610919576109196107ac565b81604052838152866020858801011115610931575f80fd5b836020870160208301375f602085830101528094505050505092915050565b80358015158114610881575f80fd5b5f6108e08236031215610970575f80fd5b6109786107d9565b6109823684610803565b8152610992366104008501610803565b602082015261080083013560408201526109af610820840161086e565b60608201526109c16108408401610886565b60808201526109d36108608401610886565b60a082015261088083013560c08201526108a083013567ffffffffffffffff8111156109fd575f80fd5b610a09368286016108a9565b60e083015250610a1c6108c08401610950565b61010082015292915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b81810381811115610a6857610a68610a28565b92915050565b80820180821115610a6857610a68610a28565b5f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610ab157610ab1610a28565b5060010190565b5f8151610ac9818560208601610665565b9290920192915050565b5f8351610ae4818460208801610665565b9190910191825250602001919050565b5f8351610b05818460208801610665565b60f89390931b7fff00000000000000000000000000000000000000000000000000000000000000169190920190815260010192915050565b7fff000000000000000000000000000000000000000000000000000000000000008b60f81b1681525f8a51610b79816001850160208f01610665565b7fff000000000000000000000000000000000000000000000000000000000000008b60f81b16600182850101527fffffffffffffffff0000000000000000000000000000000000000000000000008a60c01b16600282850101527fffffffff000000000000000000000000000000000000000000000000000000008960e01b16600a82850101527fffffffffffffffffffffffffffffffffffffffff0000000000000000000000008860601b16600e8285010152610c606022828501018860601b7fffffffffffffffffffffffffffffffffffffffff000000000000000000000000169052565b8560368285010152610c9b6056828501018660e01b7fffffffff00000000000000000000000000000000000000000000000000000000169052565b610caa605a8285010185610ab8565b9d9c50505050505050505050505050565b5f8351610ccc818460208801610665565b835190830190610ce0818360208801610665565b0194935050505056fea26469706673582212203790926a4982ec1c7e6a5fa8272afc0fcbc3412fa5f2bf734bdb6a421c359caa64736f6c63430008140033", + "deployedBytecode": "0x608060405234801561000f575f80fd5b5060043610610034575f3560e01c806304e5557b1461003857806397b1410f14610061575b5f80fd5b61004b6100463660046105e9565b610076565b6040516100589190610687565b60405180910390f35b61007461006f3660046106d7565b61042b565b005b60605f8585604051602001610095929190918252602082015260400190565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815291905290505f805b8481101561041f575f8686838181106100e3576100e3610743565b90506020028101906100f59190610770565b6100fe9061095f565b90505f825f03610110575060206101a0565b5f5b602081101561019e578888610128600187610a55565b81811061013757610137610743565b90506020028101906101499190610770565b816020811061015a5761015a610743565b6020020135835f0151826020811061017457610174610743565b60200201511461018c57610189816001610a6e565b91505b8061019681610a81565b915050610112565b505b6040805160f883901b7fff000000000000000000000000000000000000000000000000000000000000001660208201528151600181830301815260219091019091525f5b8281101561023b5783518290826020811061020157610201610743565b6020020151604051602001610217929190610ad3565b6040516020818303038152906040529150808061023390610a81565b9150506101e4565b506020830151515f9250156102fd57831580610255575084155b1561026357602091506102f8565b5f5b60208110156102f657898961027b600188610a55565b81811061028a5761028a610743565b905060200281019061029c9190610770565b6104000181602081106102b1576102b1610743565b6020020135846020015182602081106102cc576102cc610743565b6020020151146102e4576102e1816001610a6e565b92505b806102ee81610a81565b915050610265565b505b600194505b8082604051602001610310929190610af4565b60405160208183030381529060405290505f5b8281101561037c57818460200151826020811061034257610342610743565b6020020151604051602001610358929190610ad3565b6040516020818303038152906040529150808061037490610a81565b915050610323565b505f83610100015161038e575f610391565b60015b6040858101516060870151608088015160a089015160c08a015160e08b0151805187516103d399988c989081901c979096909590949093909291602001610b3d565b604051602081830303815290604052905086816040516020016103f7929190610cbb565b604051602081830303815290604052965050505050808061041790610a81565b9150506100c8565b50909695505050505050565b63ffffffff7f0000000000000000000000000000000000000000000000000000000000000000167f000000000000000000000000000000000000000000000000000000000000000063ccaa2d1163f5efcd798585602082610824376020828101610844376108a486905261092061090452604082015b8183018110156105de57803560f81c80156104c357600181146104e0576104f9565b856003538560081c6002538560101c6001538560181c5f536104f9565b846003538460081c6002538460101c6001538460181c5f535b5060028101906004906001013560f81c60200280838337909101600181019161040001906020903560f81c02808383379190910190610400810190823560f81c9061041701536001820191506008826018830137600882019150606081019050600482601c830137600482019150602081019050601482600c83013760149182019160408201918390604c01376014820191506020810190506020828237602082013560e01c60408201819052602490920191606090910190808383375f91810182905291820191601f80821660200316016109440190808281808b5af150506104a1565b505050505050505050565b5f805f80606085870312156105fc575f80fd5b8435935060208501359250604085013567ffffffffffffffff80821115610621575f80fd5b818701915087601f830112610634575f80fd5b813581811115610642575f80fd5b8860208260051b8501011115610656575f80fd5b95989497505060200194505050565b5f5b8381101561067f578181015183820152602001610667565b50505f910152565b602081525f82518060208401526106a5816040850160208701610665565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169190910160400192915050565b5f80602083850312156106e8575f80fd5b823567ffffffffffffffff808211156106ff575f80fd5b818501915085601f830112610712575f80fd5b813581811115610720575f80fd5b866020828501011115610731575f80fd5b60209290920196919550909350505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f82357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7218336030181126107a2575f80fd5b9190910192915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b604051610120810167ffffffffffffffff811182821017156107fd576107fd6107ac565b60405290565b5f82601f830112610812575f80fd5b60405161040080820182811067ffffffffffffffff82111715610837576108376107ac565b60405283018185821115610849575f80fd5b845b8281101561086357803582526020918201910161084b565b509195945050505050565b803563ffffffff81168114610881575f80fd5b919050565b803573ffffffffffffffffffffffffffffffffffffffff81168114610881575f80fd5b5f82601f8301126108b8575f80fd5b813567ffffffffffffffff808211156108d3576108d36107ac565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f01168101908282118183101715610919576109196107ac565b81604052838152866020858801011115610931575f80fd5b836020870160208301375f602085830101528094505050505092915050565b80358015158114610881575f80fd5b5f6108e08236031215610970575f80fd5b6109786107d9565b6109823684610803565b8152610992366104008501610803565b602082015261080083013560408201526109af610820840161086e565b60608201526109c16108408401610886565b60808201526109d36108608401610886565b60a082015261088083013560c08201526108a083013567ffffffffffffffff8111156109fd575f80fd5b610a09368286016108a9565b60e083015250610a1c6108c08401610950565b61010082015292915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b81810381811115610a6857610a68610a28565b92915050565b80820180821115610a6857610a68610a28565b5f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610ab157610ab1610a28565b5060010190565b5f8151610ac9818560208601610665565b9290920192915050565b5f8351610ae4818460208801610665565b9190910191825250602001919050565b5f8351610b05818460208801610665565b60f89390931b7fff00000000000000000000000000000000000000000000000000000000000000169190920190815260010192915050565b7fff000000000000000000000000000000000000000000000000000000000000008b60f81b1681525f8a51610b79816001850160208f01610665565b7fff000000000000000000000000000000000000000000000000000000000000008b60f81b16600182850101527fffffffffffffffff0000000000000000000000000000000000000000000000008a60c01b16600282850101527fffffffff000000000000000000000000000000000000000000000000000000008960e01b16600a82850101527fffffffffffffffffffffffffffffffffffffffff0000000000000000000000008860601b16600e8285010152610c606022828501018860601b7fffffffffffffffffffffffffffffffffffffffff000000000000000000000000169052565b8560368285010152610c9b6056828501018660e01b7fffffffff00000000000000000000000000000000000000000000000000000000169052565b610caa605a8285010185610ab8565b9d9c50505050505050505050505050565b5f8351610ccc818460208801610665565b835190830190610ce0818360208801610665565b0194935050505056fea26469706673582212203790926a4982ec1c7e6a5fa8272afc0fcbc3412fa5f2bf734bdb6a421c359caa64736f6c63430008140033", + "linkReferences": {}, + "deployedLinkReferences": {} +} diff --git a/tools/deployClaimCompressor/deployClaimCompressor.ts b/tools/deployClaimCompressor/deployClaimCompressor.ts new file mode 100644 index 000000000..f8b3bc5c9 --- /dev/null +++ b/tools/deployClaimCompressor/deployClaimCompressor.ts @@ -0,0 +1,85 @@ +/* eslint-disable no-await-in-loop, no-use-before-define, no-lonely-if */ +/* eslint-disable no-console, no-inner-declarations, no-undef, import/no-unresolved */ +import {expect} from "chai"; +import path = require("path"); +import fs = require("fs"); + +import * as dotenv from "dotenv"; +dotenv.config({path: path.resolve(__dirname, "../../../.env")}); +import {ethers, network, upgrades} from "hardhat"; +const deployParameters = require("./deploy_claimCompressor.json"); + +async function main() { + // Load provider + let currentProvider = ethers.provider; + if (deployParameters.multiplierGas || deployParameters.maxFeePerGas) { + if (process.env.HARDHAT_NETWORK !== "hardhat") { + currentProvider = ethers.getDefaultProvider( + `https://${process.env.HARDHAT_NETWORK}.infura.io/v3/${process.env.INFURA_PROJECT_ID}` + ) as any; + if (deployParameters.maxPriorityFeePerGas && deployParameters.maxFeePerGas) { + console.log( + `Hardcoded gas used: MaxPriority${deployParameters.maxPriorityFeePerGas} gwei, MaxFee${deployParameters.maxFeePerGas} gwei` + ); + const FEE_DATA = new ethers.FeeData( + null, + ethers.parseUnits(deployParameters.maxFeePerGas, "gwei"), + ethers.parseUnits(deployParameters.maxPriorityFeePerGas, "gwei") + ); + + currentProvider.getFeeData = async () => FEE_DATA; + } else { + console.log("Multiplier gas used: ", deployParameters.multiplierGas); + async function overrideFeeData() { + const feedata = await ethers.provider.getFeeData(); + return new ethers.FeeData( + null, + ((feedata.maxFeePerGas as bigint) * BigInt(deployParameters.multiplierGas)) / 1000n, + ((feedata.maxPriorityFeePerGas as bigint) * BigInt(deployParameters.multiplierGas)) / 1000n + ); + } + currentProvider.getFeeData = overrideFeeData; + } + } + } + + // Load deployer + let deployer; + if (deployParameters.deployerPvtKey) { + deployer = new ethers.Wallet(deployParameters.deployerPvtKey, currentProvider); + } else if (process.env.MNEMONIC) { + deployer = ethers.HDNodeWallet.fromMnemonic( + ethers.Mnemonic.fromPhrase(process.env.MNEMONIC), + "m/44'/60'/0'/0/0" + ).connect(currentProvider); + } else { + [deployer] = await ethers.getSigners(); + } + + console.log("deploying with: ", deployer.address); + + /* + *Deployment pol + */ + const bridgeAddress = deployParameters.bridgeAddress; + const networkId = deployParameters.networkId; + + const ClaimCompressor = await ethers.getContractFactory("ClaimCompressor", deployer); + const ClaimCompressorContract = await ClaimCompressor.deploy(bridgeAddress, networkId); + await ClaimCompressorContract.waitForDeployment(); + + console.log("#######################\n"); + console.log("Verifier deployed to:", ClaimCompressorContract.target); + console.log("#######################\n"); + + console.log("you can verify the contract address with:"); + console.log( + `npx hardhat verify --constructor-args upgrade/arguments.js ${ClaimCompressorContract.target} --network ${process.env.HARDHAT_NETWORK}\n` + ); + console.log("Copy the following constructor arguments on: upgrade/arguments.js \n", [bridgeAddress, networkId]); +} + +main().catch((e) => { + console.error(e); + process.exit(1); +}); diff --git a/tools/deployClaimCompressor/deploy_claimCompressor.json.example b/tools/deployClaimCompressor/deploy_claimCompressor.json.example new file mode 100644 index 000000000..3e032ea6d --- /dev/null +++ b/tools/deployClaimCompressor/deploy_claimCompressor.json.example @@ -0,0 +1,8 @@ +{ + "bridgeAddress": "0xaddress", + "networkId": 0, + "deployerPvtKey": "", + "maxFeePerGas":"", + "maxPriorityFeePerGas":"", + "multiplierGas": "" +}