Support mixed depth container merkle proofs#508
Conversation
|
Here's some numbers!
|
robknight
left a comment
There was a problem hiding this comment.
lgtm. The one bug I raised is a pre-existing issue.
| OperationAux::MerkleTreeStateTransitionProofIndex(i) => { | ||
| write!(f, " merkle_tree_state_transition_proof_{:02}", i)? | ||
| OperationAux::MerkleTransitionProofIndex(size, i) => { | ||
| write!(f, " {:?}merkle_tree_state_transition_proof_{:02}", size, i)? |
There was a problem hiding this comment.
Missing underscore after {:?}?
There was a problem hiding this comment.
you're right, I'll add a Display impl so that it formats nicely as well.
| verified_proof.verifier_data_hash.elements[i], | ||
| vd_mt_proof.value.elements[i], | ||
| ) | ||
| } |
There was a problem hiding this comment.
It seems like we are not ensuring that existence is true here, so a non-existence proof would be accepted in place of an existence proof. Not a new issue, seems like it was always that way!
There was a problem hiding this comment.
oh no... you're totally right! This was a very serious bug! Great catch!
I'll switch to the circuit that only verifies existence.
| MerkleTransitionProof = 2, | ||
| CustomPredVerify = 3, | ||
| PublicKeyOf = 4, | ||
| SignedBy = 5, |
There was a problem hiding this comment.
Out of curiosity, is there any particular reason for re-numbering these?
There was a problem hiding this comment.
yes, I took this chance to change it for two reasons:
- It felt strange to have the merkle state proofs and transition proofs in non-consecutive order
- I wanted to have an order that reflects the importance of each subtable. I see merkle trees and custom predicates as very core to pod2, whereas PublicKeyOf and SignedBy seem more like nice to have.
- The renumbering here is not very important, but I also reordered the aux table (so that state and transition merkle proofs are consecutive and custom predicate verifications come next), and I wanted to be consistent with the same order everywhere.
Add support for mixed depth container merkle proofs (both for state proofs and transition proofs)
I've refactored the fields related to container merkle proofs in params for better organization.
In his PR only "small" and "medium" depths are implemented, but the code organization already lays out the foundation for adding a future "big" depth.
I've also removed the
enabledflag from all merkle proofs to save a few constraints (not many) and to simplify the circuits because our architecture doesn't really need disabling those circuits.For the small container state proofs, the circuit only verifies inclusion (which requires less constraints than inclusion+non-inclusion).
We don't have a circuit that only verifies transition updates (instead of insert+update+delete). That can be future work to remove more constraints for the small container updates. Nevertheless the implementation in this PR already assumes that the small container transitions are only updates, so that in the future we can just swap the circuit and benefit without any further change.
I didn't touch the frontend: the MultiPod builder only considers the medium proofs capacity for now, so it doesn't generate optimal scheduling. I propose adding support after #502 is merged
There are 2 TODOS in the code about a potential off-by-one error. When I consider max_depth I assume we get 2^max_depth leafs in the tree, and max_depth siblings. But I'm not sure that's actually the case. This is a pending task for me: to validate that this is the case, or else change the code.