Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Cache keccak hashes with their corresponding Poseidon hash #97

Open
Brechtpd opened this issue May 21, 2023 · 0 comments
Open

Cache keccak hashes with their corresponding Poseidon hash #97

Brechtpd opened this issue May 21, 2023 · 0 comments

Comments

@Brechtpd
Copy link

This idea is nothing new. Especially for codehash and MPT doing this could be very useful.

The idea is very simple, each time a keccak hash is calculated we also calculate the corresponding poseidon hash. The key value pair (poseidon_hash, keccak_hash) is stored in a leaf in a relatively small helper Merkle tree (~64 bits). Whenever we have to calculate a keccak hash we already calculated before, we can simply calculate the poseidon hash instead and look up the corresponding keccak hash in the helper Merkle tree.

For the MPT, each keccak hash will already be cached for reads so no keccak hashing necessary, for writes only for the updated nodes do the keccak hashes still have to be calculated. Storage reads cost a lot less gas than writes so the worst case prover cost is still improved significantly.

Node changes are kept relatively small, there is just an extra caching step when keccak hashes are calculated (can be done incrementally) and these are stored in a new tree.

Another approach that only tries to speed up the MPT is to have a mirrored Merkle tree that uses Poseidon hashes instead (and optionally just uses a simple Sparse Merkle tree format). For reads this more optimized tree is used, for writes the normal MPT logic still has to be executed to calculate the latest MPT state root. This however requires a full new state backend implementation in the node.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: No status
Development

No branches or pull requests

1 participant