Skip to content

Commit

Permalink
fix gas loop optimization in MerkleProof.sol | caching length (OpenZe…
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonCase committed May 9, 2024
1 parent c9b7c9b commit 9e2ba99
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions contracts/utils/cryptography/MerkleProof.sol
Expand Up @@ -50,7 +50,8 @@ library MerkleProof {
*/
function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i; i < proof.length; ) {
uint256 len = proof.length;
for (uint256 i; i < len; ) {
computedHash = Hashes.commutativeKeccak256(computedHash, proof[i]);
unchecked {
++i;
Expand All @@ -64,7 +65,8 @@ library MerkleProof {
*/
function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i; i < proof.length; ) {
uint256 len = proof.length;
for (uint256 i; i < len; ) {
computedHash = Hashes.commutativeKeccak256(computedHash, proof[i]);
unchecked {
++i;
Expand Down

0 comments on commit 9e2ba99

Please sign in to comment.