Skip to content

What if roots achieve ROOT_HISTORY_SIZE and rewrite roots[0]? #4

Open

Description

@johnson86tw

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;
    }

Activity

  1. ChihChengLiang commented on Jun 21, 2021

    @ChihChengLiang

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions