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.
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.