Skip to content

optimization with nodes to keep track the most recent nodes does not work with duplicated nodes #41

@0xDatapunk

Description

@0xDatapunk

https://github.com/privacy-scaling-explorations/zk-kit.solidity/blob/a4e7136d6771456d0118729f3f5fe3dc9f7a4148/packages/imt/contracts/InternalQuinaryIMT.sol#L147-L149

when the updated node is on a path different from the more recently inserted path, which is recorded in self.lastSubtrees, we still might get (nodes[0] == self.lastSubtrees[i][0] || nodes[4] == self.lastSubtrees[i][4])==True, so self.lastSubtrees may be updated in

https://github.com/privacy-scaling-explorations/zk-kit.solidity/blob/a4e7136d6771456d0118729f3f5fe3dc9f7a4148/packages/imt/contracts/InternalQuinaryIMT.sol#L147-L149

However, _insert would be using wrong values in
https://github.com/privacy-scaling-explorations/zk-kit.solidity/blob/a4e7136d6771456d0118729f3f5fe3dc9f7a4148/packages/imt/contracts/InternalQuinaryIMT.sol#L93

This optimization with nodes to keep track the most recent nodes does not work even if the tree does not allow for duplicated values, since update/delete may result in duplicated zero values. Also there is no mechanism to enforce always adding unique leaves, if that is the intention.

Metadata

Metadata

Assignees

No one assigned

    Labels

    audit 🔍This issue is related to an audit.bug 🐛Something isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions