simple-tornado
simple-tornado copied to clipboard
What if roots achieve ROOT_HISTORY_SIZE and rewrite roots[0]?
When roots[] achieve ROOT_HISTORY_SIZE and rewrite roots[0], does it means if there is a deposit in the original roots[0] had not been withdraw, it may be locked in the contract forever?
function _insert(bytes32 _leaf) internal returns (uint32 index) {
uint32 currentIndex = nextIndex;
require(currentIndex < uint32(2)**levels, "Merkle tree is full. No more leaf can be added");
nextIndex += 1;
bytes32 currentLevelHash = _leaf;
bytes32 left;
bytes32 right;
for (uint32 i = 0; i < levels; i++) {
if (currentIndex % 2 == 0) {
left = currentLevelHash;
right = zeros[i];
filledSubtrees[i] = currentLevelHash;
} else {
left = filledSubtrees[i];
right = currentLevelHash;
}
currentLevelHash = hashLeftRight(left, right);
currentIndex /= 2;
}
currentRootIndex = (currentRootIndex + 1) % ROOT_HISTORY_SIZE; // this line
roots[currentRootIndex] = currentLevelHash;
return nextIndex - 1;
}
If a deposit D in the leaf index 5566 hasn't been withdrawn since roots[0], D is still in the index leaf 5566 in the latest root. D is still withdrawable and is not locked in the contract forever.