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

zkvm: encapsulate bulletproofs dependencies #223

Closed
wants to merge 4 commits into from

Conversation

vickiniu
Copy link
Contributor

@vickiniu vickiniu commented Mar 14, 2019

Fixes #210 - uses capacity of 256 for bulletprooofs generator.

@@ -79,10 +79,11 @@ impl<'a, 'b> Delegate<r1cs::Verifier<'a, 'b>> for Verifier<'a, 'b> {
impl<'a, 'b> Verifier<'a, 'b> {
/// Verifies the `Tx` object by executing the VM and returns the `VerifiedTx`.
/// Returns an error if the program is malformed or any of the proofs are not valid.
pub fn verify_tx<'g>(tx: Tx, bp_gens: &'g BulletproofGens) -> Result<VerifiedTx, VMError> {
pub fn verify_tx(tx: Tx) -> Result<VerifiedTx, VMError> {
let bp_gens = BulletproofGens::new(256, 1);
Copy link
Contributor

@oleganza oleganza Mar 14, 2019

Choose a reason for hiding this comment

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

We cannot hardcode this for two reasons:

  1. Bigger txs will have larger circuits and more than 256 multipliers, failing the verification if 256 is hardcoded.
  2. Computing generators is expensive. Validator would want to precompute them and use over its whole lifetime to validate arbitrary amount of transactions, so we need to pass it in.

Note: each rangeproof is 64 multipliers, each "lane" of Cloak is roughly 8+64=72 multipliers (8 for shuffles and mixes, 64 for output rangeproof). So the 10-input/output tx would use ≈720 multipliers. Plus custom contracts may allocate a few here and there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, so on the prover we'd want to calculate the capacity that we need?

If the verifier might want to precompute generators, would we need to keep bp_gens as a parameter on verify_tx?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that's why this discussion was prompted: https://dalek-cryptography.slack.com/archives/CBKMRC8DN/p1552425846018800

Copy link
Contributor

Choose a reason for hiding this comment

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

As of exposing BP API, we could re-export only BulletproofGens in the lib.rs to allow user precompute them and pass into verifier. This way if they don't care about other parts of R1CS, they can avoid explicitly linking with bulletproofs crate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it, that makes sense! reading slack thread now :)

@oleganza
Copy link
Contributor

We should probably simply do pub use bulletproofs; in the lib.rs to allow users pick various bulletproofs types (such as generators) directly via zkvm::bulletproofs::... to avoid adding BP as a dependency.

@oleganza oleganza closed this Apr 26, 2019
@oleganza oleganza deleted the vicki/encapsulate-bulletproofs branch July 11, 2019 10:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

zkvm: remove bulletproofs dependency from API
2 participants