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

Circuit builder initial ideas impl #303

Merged
merged 13 commits into from
Sep 21, 2020
Merged

Circuit builder initial ideas impl #303

merged 13 commits into from
Sep 21, 2020

Conversation

CPerezz
Copy link
Contributor

@CPerezz CPerezz commented Sep 15, 2020

This is the initial idea on how to treat generically the circuits build using PLONK in order to be able to do the most common operations with them in foreign libraries in a structured and efficient way.

CPerezz added 2 commits September 15, 2020 09:37
We need a way to treat the circuits on a generic way
which allows us to serialize the preprocessed circuits
as well as operate with them as gadgets to fill composers.

This is a first a approach with some ideas on how to do it.
@CPerezz CPerezz added API-design area:cryptography anything related to cryptographic primitives, hashing and ZKP type:feature implementing a new feature labels Sep 15, 2020
@CPerezz CPerezz self-assigned this Sep 15, 2020
@CPerezz CPerezz marked this pull request as ready for review September 17, 2020 18:26
Copy link
Contributor

@vlopes11 vlopes11 left a comment

Choose a reason for hiding this comment

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

LGTM, a small set of observations

Self: Sized + Default,
{
/// Gadget implementation used to fill the composer.
fn gadget(
Copy link
Contributor

Choose a reason for hiding this comment

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

I see the gadgets as components of the circuit, and the circuit a composition of gadgets combined into a specific logic.

Seems more logical to me to name this function as circuit or implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure. A gadget for me is the same as a circuit, the only difference is that is not meant to be used as a circuit.


/// Circuit representation for a gadget with all of the tools that it
/// should implement.
pub trait Circuit<'a>
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be a method size or capacity defined as Fn() -> usize that will return the capacity of the circuit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. OMW

) -> Result<(Vec<PublicInput>, usize), Error>;
/// Compiles the circuit by using a function that returns a `Result`
/// with the `ProverKey`, `VerifierKey` and the circuit size.
fn compile(
Copy link
Contributor

Choose a reason for hiding this comment

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

The compilation should have a standard implementation that will validate important things such as the size being a power of 2.

This implementation will rarely differ between different circuits, that's why it should be standard

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The size doesn't have t obe a pow of two. The padded one will be. but the padding is done in the preprocessing and proving stages. So that's not a problem for now.

pub_params: &PublicParameters,
prover_key: &ProverKey,
inputs: CircuitInputs,
transcript_initialisation: Option<&'static [u8]>,
Copy link
Contributor

Choose a reason for hiding this comment

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

The transcript is mandatory for Plonk. If we leave an Option there, there will be the impression it is not mandatory when internally we set a default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

kk I'll change that

pub_params: &PublicParameters,
verifier_key: &VerifierKey,
inputs: CircuitInputs,
transcript_initialisation: Option<&'static [u8]>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

fn gadget(
composer: &mut StandardComposer,
inputs: CircuitInputs,
) -> Result<(Vec<PublicInput>, usize), Error>;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should return only the [PublicInput] since the circuit size can be trivially obtained by the consumer via the mutated composer.

This way we simplify the documentation and the signature

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea is that you, as a user never interact with the composer at all. So therefore we need to return this.


/// Public Input
#[derive(Debug, Copy, Clone)]
pub enum PublicInput {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should have mechanisms to serialize/deserialize a combination of PublicInput so these can be trivially broadcasted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If they are public there should be no need to broadcast them no?

Copy link
Contributor

Choose a reason for hiding this comment

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

They must always be stored on the chain or sent via the network with the proof.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ye but they aren't sent like that. You should just send the values. not the positions that they occupy inside the PI vector.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:cryptography anything related to cryptographic primitives, hashing and ZKP type:feature implementing a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants