cartesi / rollups-contracts

Smart Contracts for Cartesi Rollups
https://cartesi.github.io/rollups-contracts/
Apache License 2.0
18 stars 38 forks source link

Fix proof verification for Output Unification #266

Closed guidanoli closed 5 months ago

guidanoli commented 5 months ago

📚 Context

As of SDK v1, the epoch hash calculation was grounded on the memory space of the machine, which has 8-byte words. For SDK v2, the Merkle trees will be constructed on top of 32-byte words, namely the output hashes. This means that we need to update the on-chain proof verification algorithm to work under these new premises.

Merkle proofs are currently done by the MerkleV2 library from solidity-util, which has several optimizations for working with 8-byte leaves, such as pre-computed pristine hashes. This library, however, is not suitable for our needs.

✔️ Solution

We need to develop a new library for working with Merkle trees with 32-byte leaves. We should thoroughly test this library with concrete and fuzzy tests. For Output Unification Part 1, we'll use this library but not MerkleV2. As for Output Unification Part 2, we'll use this library AND MerkleV2. It will be necessary then to use MerkleV2 because the epoch hash will be equal to the machine state hash, and we'll have to prove that the output Merkle tree root hash is contained in the memory space of the machine, which contains 8-byte words.