From c33a13a78230f1c67ef793f9bfc4e046ed8815ff Mon Sep 17 00:00:00 2001 From: Sebastian T F Date: Sun, 21 Apr 2024 17:42:38 +0530 Subject: [PATCH 1/2] chore: capture gas snapshot --- contracts/.gas-snapshot | 27 +++++++++++++++++++++++++++ contracts/hardhat.config.ts | 3 +++ 2 files changed, 30 insertions(+) create mode 100644 contracts/.gas-snapshot diff --git a/contracts/.gas-snapshot b/contracts/.gas-snapshot new file mode 100644 index 00000000..9c85feb1 --- /dev/null +++ b/contracts/.gas-snapshot @@ -0,0 +1,27 @@ +·------------------------------------------------------|---------------------------|-------------|-----------------------------· +| Solc version: 0.8.18 · Optimizer enabled: true · Runs: 200 · Block limit: 30000000 gas │ +·······················································|···························|·············|······························ +| Methods │ +·····················|·································|·············|·············|·············|···············|·············· +| Contract · Method · Min · Max · Avg · # calls · usd (avg) │ +·····················|·································|·············|·············|·············|···············|·············· +| GrandSumVerifier · verifyProof · - · - · 271155 · 2 · - │ +·····················|·································|·············|·············|·············|···············|·············· +| Summa · submitCommitment · - · - · 1068958 · 5 · - │ +·····················|·································|·············|·············|·············|···············|·············· +| Summa · submitProofOfAddressOwnership · - · - · 700479 · 3 · - │ +·····················|·································|·············|·············|·············|···············|·············· +| Deployments · · % of limit · │ +·······················································|·············|·············|·············|···············|·············· +| GrandSumVerifier · - · - · 277127 · 0.9 % · - │ +·······················································|·············|·············|·············|···············|·············· +| InclusionVerifier · - · - · 284887 · 0.9 % · - │ +·······················································|·············|·············|·············|···············|·············· +| src/DummyVerifyingKey.sol:Halo2VerifyingKey · - · - · 266321 · 0.9 % · - │ +·······················································|·············|·············|·············|···············|·············· +| src/VerifyingKey.sol:Halo2VerifyingKey · - · - · 350335 · 1.2 % · - │ +·······················································|·············|·············|·············|···············|·············· +| Summa · - · - · 1961848 · 6.5 % · - │ +·······················································|·············|·············|·············|···············|·············· +| Verifier · - · - · 1907494 · 6.4 % · - │ +·------------------------------------------------------|-------------|-------------|-------------|---------------|-------------· \ No newline at end of file diff --git a/contracts/hardhat.config.ts b/contracts/hardhat.config.ts index cea08afb..4c84ac97 100644 --- a/contracts/hardhat.config.ts +++ b/contracts/hardhat.config.ts @@ -21,6 +21,9 @@ module.exports = { gasReporter: { currency: "USD", gasPrice: 30, + enabled: process.env.REPORT_GAS ? true : false, + outputFile: ".gas-snapshot", + noColors: true }, solidity: { compilers: [ From 340734d955ff757b6afdf4b2baa93ec9a40aea14 Mon Sep 17 00:00:00 2001 From: Sebastian T F Date: Sun, 21 Apr 2024 17:43:08 +0530 Subject: [PATCH 2/2] perf: use encodePacked for combinedProof --- contracts/.gas-snapshot | 2 +- contracts/src/Summa.sol | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/contracts/.gas-snapshot b/contracts/.gas-snapshot index 9c85feb1..64fb4de1 100644 --- a/contracts/.gas-snapshot +++ b/contracts/.gas-snapshot @@ -21,7 +21,7 @@ ·······················································|·············|·············|·············|···············|·············· | src/VerifyingKey.sol:Halo2VerifyingKey · - · - · 350335 · 1.2 % · - │ ·······················································|·············|·············|·············|···············|·············· -| Summa · - · - · 1961848 · 6.5 % · - │ +| Summa · - · - · 1915414 · 6.4 % · - │ ·······················································|·············|·············|·············|···············|·············· | Verifier · - · - · 1907494 · 6.4 % · - │ ·------------------------------------------------------|-------------|-------------|-------------|---------------|-------------· \ No newline at end of file diff --git a/contracts/src/Summa.sol b/contracts/src/Summa.sol index 66904f83..e2fed642 100644 --- a/contracts/src/Summa.sol +++ b/contracts/src/Summa.sol @@ -272,13 +272,7 @@ contract Summa is Ownable { bytes memory snarkProof = commitments[timestamp]; - bytes memory combinedProofs = new bytes(snarkProof.length + inclusionProof.length); - for (uint256 i = 0; i < inclusionProof.length; i++) { - combinedProofs[i] = inclusionProof[i]; - } - for (uint256 i = 0; i < snarkProof.length; i++) { - combinedProofs[i + inclusionProof.length] = snarkProof[i]; - } + bytes memory combinedProofs = abi.encodePacked(inclusionProof, snarkProof); return inclusionVerifier.verifyProof(verifyingKey, combinedProofs, challenges, values); }