You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the global array "leaves" is defined dynamically as "bytes32[] leaves", and then explicitly set to size nbLeaves in the constructor. The entries of leaves are also manually initialized to their null value using a for loop in the constructor. This explicit initialization increases the gas cost of deployment by a non-trivial amount (especially for deep trees).
An alternative approach is to define a local array of fixed size nbLeaves, that is automatically initialized to its null value, in the constructor and then set the global array equal to this fixed-length array. E.g.
contract MerkleTreeSha256 {
...
bytes32[] leaves
constructor(uint treeDepth) public {
...
bytes32[] memory leavesBuilder = new bytes32[](nbLeaves);
leaves = leavesBuilder;
}
...
}
Remix tests indicate that this reduces the cost of deployment.
The text was updated successfully, but these errors were encountered:
Currently, the global array "leaves" is defined dynamically as "bytes32[] leaves", and then explicitly set to size nbLeaves in the constructor. The entries of leaves are also manually initialized to their null value using a for loop in the constructor. This explicit initialization increases the gas cost of deployment by a non-trivial amount (especially for deep trees).
An alternative approach is to define a local array of fixed size nbLeaves, that is automatically initialized to its null value, in the constructor and then set the global array equal to this fixed-length array. E.g.
contract MerkleTreeSha256 {
...
bytes32[] leaves
}
Remix tests indicate that this reduces the cost of deployment.
The text was updated successfully, but these errors were encountered: