clearmatics/zeth

Optimization of batch insertion and related Merkle tree update

AntoineRondelet opened this issue · 0 comments

While integrating Zeth with Zecale, it is required to support batch insertions and updates of the Zeth Merkle Tree. While the current approach is compatible with that (all the new leaves are added to the leaves set, and only then, the root is computed (as opposed to the dummy approach consisting in updating the Merkle paths for each newly inserted leaf)), it may be interesting to see how to optimize this operation by targeting a closer integration into Autonity and adding extra precompiled contracts.
The most trivial approach consists in adding precompiled contracts for MiMC in order to have a cheaper Merkle tree computation from the leaves set. Nevertheless, it may be possible to go a step further and have a precompiled for the whole Merkle tree batch insertion routine (like we could have a precompiled for the Groth Verifier). This requires to access the Zeth contract state within the precompiled contract however (which is obviously possible). Having such a routine in the client would allow for a multi-threaded merkle tree computation function, but that would come at the expense of navigating the smart contract state in the Storage trie which would introduce overhead. More data is needed to see if that would be helpful (i.e. we need to PoC and benchmark).