mirror of
https://github.com/tornadocash/tornado-core.git
synced 2025-12-15 08:29:13 -05:00
refactor isKnownRoot, add test
This commit is contained in:
parent
e710b243d7
commit
f783b45559
2 changed files with 38 additions and 16 deletions
|
|
@ -97,20 +97,16 @@ contract MerkleTreeWithHistory {
|
|||
if (_root == 0) {
|
||||
return false;
|
||||
}
|
||||
// search most recent first
|
||||
uint256 i;
|
||||
for(i = currentRootIndex; i < 2**256 - 1; i--) {
|
||||
if (_root == roots[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// process the rest of roots
|
||||
for(i = ROOT_HISTORY_SIZE - 1; i > currentRootIndex; i--) {
|
||||
if (_root == roots[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
uint256 i = currentRootIndex;
|
||||
do {
|
||||
if (_root == roots[i]) {
|
||||
return true;
|
||||
}
|
||||
if (i == 0) {
|
||||
i = ROOT_HISTORY_SIZE;
|
||||
}
|
||||
i--;
|
||||
} while (i != currentRootIndex);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue