mirror of
https://github.com/tornadocash/tornado-core.git
synced 2025-08-02 20:06:06 -04:00
off-by-one fix and tests
This commit is contained in:
parent
234fb8940e
commit
5c16e02c90
3 changed files with 107 additions and 12 deletions
|
@ -84,7 +84,7 @@ contract MerkleTreeWithHistory {
|
|||
}
|
||||
// search most recent first
|
||||
uint256 i;
|
||||
for(i = current_root; i >= 0; i--) {
|
||||
for(i = current_root; i < 2**256 - 1; i--) {
|
||||
if (root == _roots[i]) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ contract IVerifier {
|
|||
contract Mixer is MerkleTreeWithHistory {
|
||||
uint256 public transferValue;
|
||||
mapping(uint256 => bool) public nullifiers;
|
||||
// we store all commitments just to prevent accidental deposits with the same commitment
|
||||
mapping(uint256 => bool) public commitments;
|
||||
IVerifier verifier;
|
||||
|
||||
event Deposit(address from, uint256 commitment);
|
||||
|
@ -35,7 +37,9 @@ contract Mixer is MerkleTreeWithHistory {
|
|||
*/
|
||||
function deposit(uint256 commitment) public payable {
|
||||
require(msg.value == transferValue, "Please send `transferValue` ETH along with transaction");
|
||||
require(!commitments[commitment], "The commitment has been submitted");
|
||||
_insert(commitment);
|
||||
commitments[commitment] = true;
|
||||
emit Deposit(msg.sender, commitment);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue