Giter Site home page Giter Site logo

zerokpunk / plonky2-recursion Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lagrange-labs/plonky2-recursion

1.0 0.0 0.0 43 KB

plonky2 recursion framework handling different circuits in unified way.

License: Apache License 2.0

Rust 100.00%

plonky2-recursion's Introduction

generic_recursion

Version: 0.1.0

generic_recursion is a crate that allows to easily aggregate an unlimited amount of plonky2 proofs, generated with a circuit belong to a specific set of circuits, in a single recursive proof, which can be verified with the same verifier data independently from the number of proofs being aggregated.

The main component of the crate is the AggregationScheme data structure, which implements the RecursiveCircuit trait. This data structure already provides all the methods necessary to aggregate an unlimited number of plonky2 proofs generated with a set of circuits specified as input by the user, which will be henceforth referred to as base_circuits.

All the base circuits in the set specified by the user are required to employ the same format for their public inputs, and the AggregationScheme needs to know such a format. To specify the public input format of the base circuits, and the information about them which are needed by the AggregationScheme in order to compute the public inputs of the aggregated proof from the public inputs of the proofs to be aggregated, this crate introduces the PublicInputAggregation trait. The crate already provides implementations of this trait for several public input formats, which can be found in the shared_state module.

Tests

Tests can be run with:

cargo test --release

Usage

An AggregationScheme can be instantiated with the method build_circuit, which requires the user to provide the set of circuits that define which proofs can be aggregated with the instantiated AggregationScheme. Refer to section How To Specify the Set of Circuits to learn how to specify such set of circuits.

Once an AggregationScheme is instantiated, the user can start providing proofs to be aggregated, which must be generated with a circuit belonging to the set specified when instantiating the AggregationScheme. Before being aggregated, each proof must be preprocessed by invoking the prepare_base_proof_for_aggregation method, which yields a PreparedProof; the methods of AggregationScheme that recursively aggregate proofs accept as input only PreparedProofs. Once a proof is converted to a PreparedProof, the user can add it to the set of proofs to be aggregated with the add_proofs_for_aggregation method; the final aggregated proof is then computed by invoking the aggregate_proofs_with method, where the user can also provide other PreparedProofs to be aggregated that have not been previously added to the set of proofs to be aggregated.

For a real example on how to use the AggregationScheme, users can refer to the integration test test_recursive_aggregation found in tests/integration.rs

How To Specify the Set of Circuits

To specify the set of circuits that define which proofs can be aggregated the user must implement the BaseCircuitInfo trait for the data structure representing each circuit. The main purpose of such trait is binding to each circuit the format of the public inputs, by specifying the implementation of the PublicInputAggregation trait corresponding to such format:

pub trait BaseCircuitInfo<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize>
{
    type PIScheme: PublicInputAggregation;

    fn get_verifier_circuit_data(&self) -> VerifierCircuitData<F, C, D>;
}

The constraints that all the base circuits in the set employed to construct the AggregationScheme must share the same public input format is imposed by the fact that all the circuits provided as input to the build_circuit method must implement BaseCircuitInfo trait specifying the same implementation of PublicInputAggregation as their PIScheme.

Example

For example, suppose that a user wants to aggregate proofs generated from a set of circuits with 2 base circuits, represented by data-structures BaseCircuit1 and BaseCircuit2, which employ the format for their public input specified by SimpleStatePublicInput (which is one of the implementations of PublicInputAggregation provided by this crate). To instantiate an AggregationScheme for such set of circuits, the user should do as follows:

  1. Implement BaseCircuitInfo trait for both the circuits, specifying SimpleStatePublicInput as their PIScheme:
impl<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize>
        BaseCircuitInfo<F, C, D> for BaseCircuit1
    {
        type PIScheme = SimpleStatePublicInput;

        fn get_verifier_circuit_data(&self) -> VerifierCircuitData<F, C, D> {
            // custom implementation
        }
   }

impl<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize>
BaseCircuitInfo<F, C, D> for BaseCircuit2<F, C, D>
{
    type PIScheme = SimpleStatePublicInput;

    fn get_verifier_circuit_data(&self) -> VerifierCircuitData<F, C, D> {
        // custom implementation
    }
}
  1. Given 2 instances of the BaseCircuit1 and BaseCircuit2 data-structures, called base_circuit_1 and base_circuit_2, respectively, build the set of circuits and instantiate the AggregationScheme with the build_circuit method as follows:
let circuit_set = vec![prepare_base_circuit_for_circuit_set(base_circuit_1),
    prepare_base_circuit_for_circuit_set(base_circuit_2)];

        let aggregation_scheme =
            AggregationScheme::build_circuit(
                circuit_set.into_iter(),
            )?;

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions

plonky2-recursion's People

Contributors

zerokpunk avatar nikkolasg avatar

Stargazers

DHOT Networks - Evolving Technologies... avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.