HarryR / ethsnarks

A toolkit for viable zk-SNARKS on Ethereum, Web, Mobile and Desktop
GNU Lesser General Public License v3.0
241 stars 57 forks source link

Add ability to insert last leaf to the tree #136

Closed 3q-coder closed 5 years ago

3q-coder commented 5 years ago

It looks like it is necessary to replace MAX_LEAF_COUNT - 1 with MAX_LEAF_COUNT. Because it is impossible to insert the last leaf in the current implementation.

HarryR commented 5 years ago

You are correct, thank you for spotting that :D

For example, MAX_LEAF_COUNT = 4

You try to insert 4 times, incrementing self._cur which starts at zero, which represents the index of the next leaf which will be inserted.

So last item will fail to insert.