diff --git a/contracts/MerkleTreeWithHistory.sol b/contracts/MerkleTreeWithHistory.sol index 9d2f189..39145b9 100644 --- a/contracts/MerkleTreeWithHistory.sol +++ b/contracts/MerkleTreeWithHistory.sol @@ -56,7 +56,7 @@ contract MerkleTreeWithHistory { hash = R; } - function _insert(uint256 leaf) internal { + function _insert(uint256 leaf) internal returns(uint256 index) { uint32 current_index = next_index; require(current_index != 2**levels, "Merkle tree is full. No more leafs can be added"); next_index += 1; @@ -82,6 +82,7 @@ contract MerkleTreeWithHistory { current_root = (current_root + 1) % ROOT_HISTORY_SIZE; _roots[current_root] = current_level_hash; + return next_index - 1; } function isKnownRoot(uint256 root) public view returns(bool) { diff --git a/contracts/Mixer.sol b/contracts/Mixer.sol index 4f273ad..8da900e 100644 --- a/contracts/Mixer.sol +++ b/contracts/Mixer.sol @@ -65,11 +65,11 @@ contract Mixer is MerkleTreeWithHistory { function deposit(uint256 commitment) public payable { require(isDepositsEnabled, "deposits are disabled"); require(!commitments[commitment], "The commitment has been submitted"); - _insert(commitment); + uint256 insertedIndex = _insert(commitment); commitments[commitment] = true; _processDeposit(); - emit Deposit(commitment, next_index - 1, block.timestamp); + emit Deposit(commitment, insertedIndex, block.timestamp); } /** @dev this function is defined in a child contract */