some zero knowledge circuit implementations using Gnark framework
- cosmos-sdk supports secp256k1 curve ecdsa signature scheme
- gnark also has an implementation of the same but there is no way to generate gnark PrivateKey from sdk private key so use this fork instead, https://github.com/Teja2045/gnark-crypto
-
An inclusion proof verification circuit
-
Data (index of data segment to be proven, IS THERE A WAY TO VERIFY IF THE LEAF DATA MATCHES DATA SEGMENT AT INDEX??), merkleProof as inputs
merkle.verify(data, merkleproof)
-
A simple Mimc Hash function verifier with BN254 curve
Hash(data) == Expected Hash
-
An eddsa signature verfication that checks if a digital signature is valid or not pubkey.verify(data, signature)
-
data is private input and pubkey, signature are public inputs
Note: Signature circuit is refactored to have separate prover and verifier. It could be used as a complete example flow.
- A circuit which requests an endpoint for some data and uses that data for some operations
- For this to work as expected, the api needs to DETERMINISTIC (an endpoint should return same reponse no matter how many times it's called) !
- It's like a pure function
- If the endpoint returns different response, it will lead inconsistency error when compiling the circuit
- Tried to check hashing compatibility of gnark sha2 implementation with crypto/256. Failed!
- To check if we can directly compare circuit variables without using assert. Failed!
- A Zk circuit doesn't support if statement, but we can use api.Select{} for somewhat similar effect
// this is equivalent to toAdd1 := circuit.A_Support == 1 ? circuit.A : 0
toAdd1 := api.Select(circuit.A_Support, circuit.A, 0)
-
A simple circuit that check cube of a number
x^3 == y
-
X is the private input and y is the public input