diff --git a/contracts/MerkleTreeWithHistory.sol b/contracts/MerkleTreeWithHistory.sol index a374bff..74a4bc3 100644 --- a/contracts/MerkleTreeWithHistory.sol +++ b/contracts/MerkleTreeWithHistory.sol @@ -58,7 +58,7 @@ contract MerkleTreeWithHistory { function _insert(uint256 leaf) internal { uint32 current_index = next_index; - require(current_index != 2**(levels - 1), "Merkle tree is full"); + require(current_index != 2**levels, "Merkle tree is full"); next_index += 1; uint256 current_level_hash = leaf; uint256 left; diff --git a/test/MerkleTreeWithHistory.test.js b/test/MerkleTreeWithHistory.test.js index 742c00c..730c25c 100644 --- a/test/MerkleTreeWithHistory.test.js +++ b/test/MerkleTreeWithHistory.test.js @@ -180,7 +180,7 @@ contract('MerkleTreeWithHistory', accounts => { zeroValue = 1337 merkleTreeWithHistory = await MerkleTreeWithHistory.new(levels, zeroValue) - for (let i = 0; i < 2**(levels - 1); i++) { + for (let i = 0; i < 2**levels; i++) { await merkleTreeWithHistory.insert(i+42).should.be.fulfilled }