onflow / cadence

Cadence, the resource-oriented smart contract programming language 🏃‍♂️
https://developers.flow.com/cadence
Apache License 2.0
532 stars 139 forks source link

Enhancing Cadence/Flow with Expanded Elliptic Curve Operations Support for Zero-Knowledge Proofs #2576

Open highskore opened 1 year ago

highskore commented 1 year ago

Issue to be solved

I've been thinking about the possibility of expanding our support for elliptic curve operations in Cadence/Flow. From my perspective, it seems there's a strong need for zero-knowledge proofs in the blockchain context, which appears to be somewhat absent in Flow currently.

I think it would be good to have a conversation about whether adding zero-knowledge proof verification could be possible and useful for our ecosystem. This could be a meaningful improvement for us in the future.

Suggested Solution

There's a pertinent Ethereum Improvement Proposal (EIP), specifically EIP-2537, that seeks to establish BLS12-381 curve operations for executing BLS signature and SNARK verifications:

EIP-2537 Link

Given its potential, it may be highly beneficial to consider incorporating the same operational framework into the Flow protocol. The EIP provides a detailed description of each function, which could be quite insightful for our purposes:

The objective is to enable snark-based proof verification through a Cadence smart contract. I believe this could be achieved by integrating these "precompiles" into the Flow Protocol. However, I'm curious about potential computational limitations we may encounter during proof verification.

Here is an example of a zksnark verifier contract in Solidity:

https://gist.github.com/leonardoalt/bd8db502d620c16506eca81d85ff468c

As you can see, it involves quite a bit of mathematical computations and also uses precompiles. I'm interested in hearing everyone's thoughts on whether the computational limit could hinder our ability to verify proofs.

turbolent commented 10 months ago

Would we also need addmod and mulmod equivalents?

tarakby commented 10 months ago

@turbolent, Not necessarily. The tools listed above are elliptic curve group operations, and they use prime field operations under the hood (like the modular addition and multiplication you mentioned). If we extend the elliptic curve operations properly (beyond the list above), we may not need the modular operations. For performance reasons, my preference is to keep the modular operations under the hood (I spare you the technical details here, but happy to talk about them) unless really necessary by the SNARK scheme.

You may be asking because you've seen modular operation being used in the example contract. It seems to me that they are all used as building blocks in elliptic curve operations (which I am proposing to export directly on Cadence).