Skip to content

Commit 65f824d

Browse files
committed
prevent variable shadowing and unassigned variable warnings
1 parent c322b5a commit 65f824d

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

contracts/data/IncrementalMerkleTree.sol

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ library IncrementalMerkleTree {
1212
/**
1313
* @notice query number of elements contained in tree
1414
* @param t Tree struct storage reference
15-
* @return size of tree
15+
* @return treeSize size of tree
1616
*/
17-
function size(Tree storage t) internal view returns (uint256) {
17+
function size(Tree storage t) internal view returns (uint256 treeSize) {
1818
if (t.height() > 0) {
19-
return t.nodes[0].length;
19+
treeSize = t.nodes[0].length;
2020
}
2121
}
2222

@@ -33,14 +33,14 @@ library IncrementalMerkleTree {
3333
/**
3434
* @notice query Merkle root
3535
* @param t Tree struct storage reference
36-
* @return root hash
36+
* @return hash root hash
3737
*/
38-
function root(Tree storage t) internal view returns (bytes32) {
39-
uint256 height = t.height();
38+
function root(Tree storage t) internal view returns (bytes32 hash) {
39+
uint256 treeHeight = t.height();
4040

41-
if (height > 0) {
41+
if (treeHeight > 0) {
4242
unchecked {
43-
return t.nodes[height - 1][0];
43+
hash = t.nodes[treeHeight - 1][0];
4444
}
4545
}
4646
}
@@ -52,30 +52,30 @@ library IncrementalMerkleTree {
5252
*/
5353
function push(Tree storage t, bytes32 hash) internal {
5454
unchecked {
55-
uint256 height = t.height();
56-
uint256 size = t.size();
55+
uint256 treeHeight = t.height();
56+
uint256 treeSize = t.size();
5757

5858
// add new layer if tree is at capacity
5959

60-
if (size == (1 << height) >> 1) {
60+
if (treeSize == (1 << treeHeight) >> 1) {
6161
t.nodes.push();
62-
height++;
62+
treeHeight++;
6363
}
6464

6565
// add new columns if rows are full
6666

6767
uint256 row;
68-
uint256 col = size;
68+
uint256 col = treeSize;
6969

70-
while (row < height && t.nodes[row].length <= col) {
70+
while (row < treeHeight && t.nodes[row].length <= col) {
7171
t.nodes[row].push();
7272
row++;
7373
col >>= 1;
7474
}
7575

7676
// add hash to tree
7777

78-
t.set(size, hash);
78+
t.set(treeSize, hash);
7979
}
8080
}
8181

0 commit comments

Comments
 (0)