Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for verifying compact multiproofs #153

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

rista404
Copy link

Hi! Thanks for maintaining this great library. We were using it in a (soon to be open-source) project but found ourselves missing the compact multiproof support. This PR adds the support for verifying such proofs.

You can read the spec here: ethereum/consensus-specs#3148
You can also see a full TypeScript implementation here: ChainSafe/ssz#292

I think those two PRs explain why compact proofs are useful! Lodestar, which we interact with, is already using them in production as the only format for certain proofs.

I've marked the implementation as experimental and added some very basic tests. I could do a follow-up PR that adds proof generation as well as more tests. Let me know if something needs changing!

@ralexstokes
Copy link
Owner

hi @rista404 this is great, thank you!

can you address the linter errors?

otherwise I'd generally lean to merge this soon

Copy link
Owner

@ralexstokes ralexstokes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally looks good!

I don't fully get yet how this is different from the other multiproof code, but I think I need to go check the other resources you linked in your first comment

edit: to be clear, I think we can make some of the bit munging more efficient but happy to merge this as-is and refactor later

}

pub fn verify_compact_merkle_multiproof(
nodes: &[Node],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nodes here is the leaf layer from a given merkle tree?


pub fn verify_compact_merkle_multiproof(
nodes: &[Node],
descriptor: &[u8],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about using a bitvec type here instead? then we can skip a lot of bool parsing elsewhere in this module

ssz-rs/src/merkleization/compact_multiproofs.rs Outdated Show resolved Hide resolved
}
}

fn compute_bits_from_proof_descriptor(descriptor: &[u8]) -> Result<Vec<bool>, Error> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could make this much more efficient with just some bit-level arithmetic going byte-by-byte in descriptor and can return a bitvec type that would be much more compact than Vec<bool>

fine to merge this for now and make an issue to refactor

ssz-rs/src/merkleization/multiproofs.rs Show resolved Hide resolved
ssz-rs/src/merkleization/multiproofs.rs Outdated Show resolved Hide resolved
ssz-rs/src/merkleization/multiproofs.rs Outdated Show resolved Hide resolved
ssz-rs/src/merkleization/compact_multiproofs.rs Outdated Show resolved Hide resolved
@rista404
Copy link
Author

@ralexstokes thanks for the review, I'll go back and make those changes in the same PR! I also highly recommend looking into the spec to get a better understanding of the compact multiproofs.

@rista404
Copy link
Author

@ralexstokes on a second thought, could we make an issue to refactor the code to use bitvec? I would have to see what's the best way to do that as the descriptor is a format defined in the spec, that you can for example send hex encoded over the wire etc.

Still very keen to optimise but I think I would need some more time. If the rest looks okay and you've had the time to look into the spec PR, feel free to merge 🙏🏻

Thanks again!

@rista404
Copy link
Author

@ralexstokes ping on this! anything else I can do to help get this merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants