From efecda4f303a15552d16d7662a71a2f4840b4af7 Mon Sep 17 00:00:00 2001 From: cedoor Date: Thu, 3 Feb 2022 10:13:41 +0100 Subject: [PATCH] perf: replace memory with calldata --- packages/incremental-merkle-tree.sol/README.md | 6 +++--- .../contracts/BinaryTreeTest.sol | 4 ++-- .../contracts/IncrementalBinaryTree.sol | 8 ++++---- .../contracts/IncrementalQuinTree.sol | 8 ++++---- .../contracts/QuinTreeTest.sol | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/incremental-merkle-tree.sol/README.md b/packages/incremental-merkle-tree.sol/README.md index dac4a80..68deeef 100644 --- a/packages/incremental-merkle-tree.sol/README.md +++ b/packages/incremental-merkle-tree.sol/README.md @@ -97,8 +97,8 @@ contract Example { function removeLeaf( bytes32 _treeId, uint256 _leaf, - uint256[] memory _proofSiblings, - uint8[] memory _proofPathIndices + uint256[] calldata _proofSiblings, + uint8[] calldata _proofPathIndices ) external { require(trees[_treeId].depth != 0, "Example: tree does not exist"); @@ -112,7 +112,7 @@ contract Example { ### Creating an Hardhat task to deploy the contract -```ts +```typescript import { poseidon_gencontract as poseidonContract } from "circomlibjs" import { Contract } from "ethers" import { task, types } from "hardhat/config" diff --git a/packages/incremental-merkle-tree.sol/contracts/BinaryTreeTest.sol b/packages/incremental-merkle-tree.sol/contracts/BinaryTreeTest.sol index 15a8644..3403c00 100644 --- a/packages/incremental-merkle-tree.sol/contracts/BinaryTreeTest.sol +++ b/packages/incremental-merkle-tree.sol/contracts/BinaryTreeTest.sol @@ -32,8 +32,8 @@ contract BinaryTreeTest { function removeLeaf( bytes32 _treeId, uint256 _leaf, - uint256[] memory _proofSiblings, - uint8[] memory _proofPathIndices + uint256[] calldata _proofSiblings, + uint8[] calldata _proofPathIndices ) external { require(trees[_treeId].depth != 0, "BinaryTreeTest: tree does not exist"); diff --git a/packages/incremental-merkle-tree.sol/contracts/IncrementalBinaryTree.sol b/packages/incremental-merkle-tree.sol/contracts/IncrementalBinaryTree.sol index 86bf087..ce61113 100644 --- a/packages/incremental-merkle-tree.sol/contracts/IncrementalBinaryTree.sol +++ b/packages/incremental-merkle-tree.sol/contracts/IncrementalBinaryTree.sol @@ -76,8 +76,8 @@ library IncrementalBinaryTree { function remove( IncrementalTreeData storage self, uint256 leaf, - uint256[] memory proofSiblings, - uint8[] memory proofPathIndices + uint256[] calldata proofSiblings, + uint8[] calldata proofPathIndices ) public { require(verify(self, leaf, proofSiblings, proofPathIndices), "IncrementalBinaryTree: leaf is not part of the tree"); @@ -111,8 +111,8 @@ library IncrementalBinaryTree { function verify( IncrementalTreeData storage self, uint256 leaf, - uint256[] memory proofSiblings, - uint8[] memory proofPathIndices + uint256[] calldata proofSiblings, + uint8[] calldata proofPathIndices ) private view returns (bool) { require(leaf < SNARK_SCALAR_FIELD, "IncrementalBinaryTree: leaf must be < SNARK_SCALAR_FIELD"); require( diff --git a/packages/incremental-merkle-tree.sol/contracts/IncrementalQuinTree.sol b/packages/incremental-merkle-tree.sol/contracts/IncrementalQuinTree.sol index 851896a..a49157c 100644 --- a/packages/incremental-merkle-tree.sol/contracts/IncrementalQuinTree.sol +++ b/packages/incremental-merkle-tree.sol/contracts/IncrementalQuinTree.sol @@ -86,8 +86,8 @@ library IncrementalQuinTree { function remove( IncrementalTreeData storage self, uint256 leaf, - uint256[4][] memory proofSiblings, - uint8[] memory proofPathIndices + uint256[4][] calldata proofSiblings, + uint8[] calldata proofPathIndices ) public { require(verify(self, leaf, proofSiblings, proofPathIndices), "IncrementalQuinTree: leaf is not part of the tree"); @@ -125,8 +125,8 @@ library IncrementalQuinTree { function verify( IncrementalTreeData storage self, uint256 leaf, - uint256[4][] memory proofSiblings, - uint8[] memory proofPathIndices + uint256[4][] calldata proofSiblings, + uint8[] calldata proofPathIndices ) private view returns (bool) { require(leaf < SNARK_SCALAR_FIELD, "IncrementalQuinTree: leaf must be < SNARK_SCALAR_FIELD"); require( diff --git a/packages/incremental-merkle-tree.sol/contracts/QuinTreeTest.sol b/packages/incremental-merkle-tree.sol/contracts/QuinTreeTest.sol index 4f6233a..b35eb85 100644 --- a/packages/incremental-merkle-tree.sol/contracts/QuinTreeTest.sol +++ b/packages/incremental-merkle-tree.sol/contracts/QuinTreeTest.sol @@ -32,8 +32,8 @@ contract QuinTreeTest { function removeLeaf( bytes32 _treeId, uint256 _leaf, - uint256[4][] memory _proofSiblings, - uint8[] memory _proofPathIndices + uint256[4][] calldata _proofSiblings, + uint8[] calldata _proofPathIndices ) external { require(trees[_treeId].depth != 0, "QuinTreeTest: tree does not exist");