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

zkSNARK Plonk #454

Merged
merged 3 commits into from
Jun 17, 2021
Merged

zkSNARK Plonk #454

merged 3 commits into from
Jun 17, 2021

Conversation

ashWhiteHat
Copy link
Contributor

@ashWhiteHat ashWhiteHat commented Jun 14, 2021

Grant Application Checklist

  • The application template has been copied, renamed ( project_name.md) and updated.
  • A BTC or Ethereum (DAI) address for the payment of the milestones is provided inside the application.
  • I have read and acknowledged the Terms and Conditions.
  • The software delivered for this grant will be released under an open-source license specified in the application.
  • The total funding amount of the project is below USD $30k for initial grant applications and $100k for follow-up grants.
  • The initial PR contains only one commit (squash if needed before submitting your PR).
  • The grant will only be announced once the first milestone has been accepted.

Copy link
Collaborator

@Noc2 Noc2 left a comment

Choose a reason for hiding this comment

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

Thanks for the application. I think in general we are highly interested in this. Are you going to use the Pure Rust implementation by dusk-network? What exactly do you need to do as part of deliverables in order to implement this into substrate? 4 months seems to be a lot for this. Are you also planning to audit the implementation?

@Noc2 Noc2 added the changes requested The team needs to clarify a few things first. label Jun 14, 2021
@ashWhiteHat
Copy link
Contributor Author

@Noc2
Thank you for the questions 😎

I think in general we are highly interested in this.

Thank you.
I am really honored.

Are you going to use the Pure Rust implementation by dusk-network?

Exactly.

What exactly do you need to do as part of deliverables in order to implement this into substrate?

The dusk-network plonk is compatible with no-std so we are going to change some attributes according to parity-codec to be compatible and modify Rng to be compatible with wasm.
After that step, we are going to implement plonk as a pallet.

4 months seems to be a lot for this.

Okay.
I will buy a new keyboard to type fast and it reduces a month so it takes 3 months totally.

Are you also planning to audit the implementation?

Absolutely!

Please feel free to ask any questions.
Thank you!

@Noc2
Copy link
Collaborator

Noc2 commented Jun 15, 2021

Thanks for the quick reply. Could you update the application accordingly (concrete deliverables, potentially the audit, etc)?

@ashWhiteHat
Copy link
Contributor Author

Hi @Noc2
I updated it according to your review 😎
Please confirm.
Thank you!

@ashWhiteHat ashWhiteHat requested a review from Noc2 June 16, 2021 04:09
Noc2
Noc2 previously approved these changes Jun 16, 2021
Copy link
Collaborator

@Noc2 Noc2 left a comment

Choose a reason for hiding this comment

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

Looks good to me. I will share it with the rest of the team. Also let me know if we should help you with the audit and potentially try to find a company, etc.

@Noc2 Noc2 added ready for review The project is ready to be reviewed by the committee members. and removed changes requested The team needs to clarify a few things first. labels Jun 16, 2021
Copy link
Contributor

@mmagician mmagician left a comment

Choose a reason for hiding this comment

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

This is a promising project! There are a few points that I'd like to get clarification on:


modify attributes according to parity-codec and Rng to be compatible with Substrate environment.

I would like to understand a little bit better what you mean by the above.


allow a developer to build their own circuit

Did I understand correctly that you want to provide the ability to both creating the proofs as well as verifying them from your pallet? As far as I can remember, the other team providing similar functionality (ZeroPool, built for groth16) only had verification on-chain. Please expand on this point as well, to explain how you envision developers building their own circuits.


Lastly, could you provide a list of extrinsics that would be callable via your pallet? This would later allow us to better evaluate your delivery against the original contract.


I would like to kindly ask you to include the requested information in your application.

@ashWhiteHat
Copy link
Contributor Author

Hi @mmagician
Thank you for the questions.

modify attributes according to parity-codec and Rng to be compatible with Substrate environment.
I would like to understand a little bit better what you mean by the above.

In order for the pallet to work on resource-constrained execution environments like Substrate runtime, attributes should be modified in accordance with the SCALE codec.
The parity-codec is a high-performance encoding and decoding data library.
In terms of Rng, there are some versions of Rng that can’t be compiled to wasm so we need to research and make it stable if it needs.

Did I understand correctly that you want to provide the ability to both creating the proofs as well as verifying them from your pallet?

Creating the proofs is done off-chain because it needs secret input and it shouldn’t be public, and that process consumes a bunch of computation.
Proofs are created off-chain and verify them on-chain through our verifying pallet.

Lastly, could you provide a list of extrinsics that would be callable via your pallet? This would later allow us to better evaluate your delivery against the original contract.

This pallet allows us to do building circuits, creating proofs, and verifying proofs.

I would like to kindly ask you to include the requested information in your application.

I updated accordingly.
Please confirm.
Thank you!

| 1. | make plonk compatible | The dusk-network plonk is compatible with `no-std` so we are going to modify attributes according to [parity-codec](https://github.com/paritytech/parity-scale-codec) and `Rng` to be compatible with Substrate environment. |
| 2. | implement zkSNARK plonk pallet | We will create a set of plonk-based zkSNARK libraries that allow a developer to build their own circuit and a user to prove their computation validity. |
| 1. | make plonk compatible | The dusk-network plonk is compatible with `no-std` so we are going to modify attributes according to [parity-codec](https://github.com/paritytech/parity-scale-codec) and `Rng` to be compatible with Substrate environment. This step allows this pallet to work on resource-constrained execution environments like Substrate runtime, attributes should be modified in accordance with SCALE codec and some versions of Rng can’t be compiled to wasm so we need to research and make it stable as necessary. |
| 2. | implement zkSNARK plonk pallet | We will create a set of plonk-based zkSNARK libraries that allow a developer to build their own circuit and a user to prove their computation validity. Verifying proofs are done by on-chain. Creating the proofs are done by off-chain. |
Copy link
Contributor

Choose a reason for hiding this comment

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

off chain - meaning off-chain worker? or a separate tool?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Creating the proofs is done by an off-chain worker.


This zkSNARK plonk is based on [dusk-network plonk](https://github.com/dusk-network/plonk) library.
This zkSNARK plonk pallet provides us following function.
- Building circuits
Copy link
Contributor

Choose a reason for hiding this comment

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

You're planning to build circuits through your pallet? This sounds like you're planning to make it interactive, which doesn't make much sense to me, since circuits needed to be programmed by the user. As far as I'm aware, this involves writing code with the help of some tools (like circom, or dusk-plonk would be the fit here I guess) that is later compiled. Please expand on how your pallet would support building circuits

Copy link
Contributor Author

@ashWhiteHat ashWhiteHat Jun 17, 2021

Choose a reason for hiding this comment

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

Hi @mmagician
Thank you for asking me for details.

You're planning to build circuits through your pallet? This sounds like you're planning to make it interactive, which doesn't make much sense to me, since circuits needed to be programmed by the user.

Yes, the user(Substrate developer) can build their own programmable circuit.

If they want to build a circuit of privacy transfer, following sequence they need.

  1. Build their own circuit on-chain(Substrate node) that checks the validity of transactions
  2. Customize off-chain worker library corresponding to the on-chain circuit
  3. Deploy the Substrate node
  4. The transactor creates proofs and sends transactions through the off-chain worker.

It's a similar structure with circom which deploys verifier contract and this is the verify pallet of this project.
The circom creates proof using the off-chain library and this is the create proof off-chain worker of this project.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you don't mind I'll lean on the example from circom again. From this tutorial section 2.1, a user needs to write code in order to build their circuit.

So what you're saying is that if a developer wants to build their own circuit, they need to have a separate pallet with the logic for their own circuit? Because, as far as I understand, each circuit will be customised for the developer's own purpose and it's difficult to make it generic.

I could imagine that if there is a common interface, an off-chain worker could be called to build the circuit from whatever code the user has written. Could it be generic enough?

Well if that's the case and I understood your last comment, then the building of the circuit will not happen in your pallet, but rather each developer has to do it independently. And then they can call your pallet's create proof method (assuming there is some standard interface in place) to take whatever circuit they built, supply the secret inputs, and compute the proof. Is my understanding correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the questions.

If you don't mind I'll lean on the example from circom again. From this tutorial section 2.1, a user needs to write code in order to build their circuit.

This plonk pallet provides a circuit template library.
A user writes code on the provided circuit template library so it doesn't have to have a separate library by itself in the same way as a circom user doesn't need to implement any kind of library just defining constraint.

they need to have a separate pallet with the logic for their own circuit?

No, because this plonk pallet provides a circuit template library.

each circuit will be customised for the developer's own purpose and it's difficult to make it generic.

Each circuit will be customized using a circuit template library and a user define the constraint themselves.

I could imagine that if there is a common interface, an off-chain worker could be called to build the circuit from whatever code the user has written.

Sorry I couldn't understand this.
The circuit can't be added after a developer deploys the Substrate node.

the building of the circuit will not happen in your pallet

The building of the circuit will happen in this plonk pallet using a circuit template library.
A user defines the circuit as following through the plonk pallet.

impl Circuit for TestCircuit {
    const CIRCUIT_ID: [u8; 32] = [0xff; 32];
    fn gadget(
        &mut self,
        composer: &mut StandardComposer,
    ) -> Result<(), Error> {
        let a = composer.add_input(self.a);
        let b = composer.add_input(self.b);
        // Make first constraint a + b = c
        composer.poly_gate(
            a,
            b,
            composer.zero_var(),
            BlsScalar::zero(),
            BlsScalar::one(),
            BlsScalar::one(),
            BlsScalar::zero(),
            BlsScalar::zero(),
            Some(-self.c),
        );
        // Check that a and b are in range
        composer.range_gate(a, 1 << 6);
        composer.range_gate(b, 1 << 5);
        // Make second constraint a * b = d
        composer.poly_gate(
            a,
            b,
            composer.zero_var(),
            BlsScalar::one(),
            BlsScalar::zero(),
            BlsScalar::zero(),
            BlsScalar::one(),
            BlsScalar::zero(),
            Some(-self.d),
        );

        let e = composer.add_input(self.e.into());
        let scalar_mul_result = composer
            .fixed_base_scalar_mul(e, dusk_jubjub::GENERATOR_EXTENDED);
        // Apply the constrain
        composer.assert_equal_public_point(scalar_mul_result, self.f);
        Ok(())
    }
    fn padded_circuit_size(&self) -> usize {
        1 << 11
    }
}

A user circuit is TestCircuit and the Circuit struct is from this pallet.
A user can build a circuit by extending provided Circuit struct and this is a generic circuit template library.
And from the next line, a user defines the constraint.
I hope this example helps you to understand well.
Sorry that was such a long comment 🙇‍♂️

Copy link
Contributor

@mmagician mmagician left a comment

Choose a reason for hiding this comment

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

Okay, that indeed clarifies the idea for me. Thanks a lot for the explanation!

@mmagician mmagician requested a review from Noc2 June 17, 2021 10:41
@ashWhiteHat
Copy link
Contributor Author

Hi @Noc2

Also let me know if we should help you with the audit and potentially try to find a company, etc.

I'd like to know what kind of help you provide about the audit.

@Noc2 Noc2 merged commit f5edf7d into w3f:master Jun 17, 2021
@github-actions
Copy link
Contributor

Congratulations! As part of the Open Grants Program, we want to help winning teams acknowledge their grants publicly. To that end, we’ve created a badge for projects that successfully delivered their first milestone. Please observe the foundation’s guidelines when making any announcements; in particular, don’t announce the grant publicly before you've completed at least the first milestone of the project.

At that point, we will be happy to collaborate on an announcement about the work you’re doing. Please get in touch with us at grantspr@web3.foundation in case you're interested (at least two weeks notice is preferred).

@Noc2
Copy link
Collaborator

Noc2 commented Jun 17, 2021

Hi @Noc2

Also let me know if we should help you with the audit and potentially try to find a company, etc.

I'd like to know what kind of help you provide about the audit.

We could potentially help you to find a company. It’s currently pretty difficult to find good audit companies.

alxs pushed a commit that referenced this pull request Jul 20, 2021
Update the status of RFPs
chrisli30 pushed a commit to AvaProtocol/W3F-Grants-Fork that referenced this pull request Oct 8, 2021
* create zkSNARK plonk

* trusted setup

* toxic waste
@alxs
Copy link
Contributor

alxs commented Nov 30, 2021

@noctrlz any updates, are you still interested in working on this?

@ashWhiteHat
Copy link
Contributor Author

Hi @alxs
It's almost completed.
https://github.com/PlasmNetwork/plonk
The prover, circuit builder and setup, verify functions work correctly!
https://github.com/PlasmNetwork/plonk/blob/master/src/tests.rs#L207
I am working on tutorial and documentation so I will deliver with in 2 weeks.
Sorry for late.

@ashWhiteHat
Copy link
Contributor Author

Hi there
I created the delivery PR following!
Please confirm!
w3f/Grant-Milestone-Delivery#326
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review The project is ready to be reviewed by the committee members.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants