mirror of
https://github.com/logos-storage/nim-groth16.git
synced 2026-01-03 22:23:08 +00:00
move things around and add results support
This commit is contained in:
parent
4b8487b0df
commit
c583af0755
@ -1,11 +1,16 @@
|
||||
import pkg/groth16
|
||||
|
||||
import ../tests/test_proof
|
||||
import ../src/export_json
|
||||
import pkg/results
|
||||
import ../groth16
|
||||
|
||||
let zkey_fname : string = "./build/product.zkey"
|
||||
let wtns_fname : string = "./build/product.wtns"
|
||||
let proof = testProveAndVerify( zkey_fname, wtns_fname)
|
||||
proc main(): Result[void, cstring] =
|
||||
let zkey_fname : string = "./build/product.zkey"
|
||||
let wtns_fname : string = "./build/product.wtns"
|
||||
let proof = ? proveAndVerify( zkey_fname, wtns_fname)
|
||||
|
||||
exportPublicIO( "./build/nim_public.json" , proof )
|
||||
exportProof( "./build/nim_proof.json" , proof )
|
||||
exportPublicIO( "./build/nim_public.json" , proof )
|
||||
exportProof( "./build/nim_proof.json" , proof )
|
||||
|
||||
ok()
|
||||
|
||||
if main().isErr:
|
||||
raiseAssert "Error verifying proof"
|
||||
|
||||
29
groth16.nim
Normal file
29
groth16.nim
Normal file
@ -0,0 +1,29 @@
|
||||
import pkg/results
|
||||
|
||||
import pkg/groth16
|
||||
import pkg/witness
|
||||
import pkg/zkey
|
||||
import pkg/zkey_types
|
||||
import pkg/export_json
|
||||
|
||||
export groth16, witness, zkey, zkey_types, export_json
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
proc proveAndVerify*( zkey_fname, wtns_fname: string): Result[Proof, cstring] =
|
||||
debugEcho("parsing witness & zkey files...")
|
||||
let witness = parseWitness( wtns_fname)
|
||||
let zkey = parseZKey( zkey_fname)
|
||||
|
||||
debugEcho("generating proof...")
|
||||
let vkey = extractVKey( zkey)
|
||||
let proof = generateProof( zkey, witness )
|
||||
|
||||
debugEcho("verifying the proof...")
|
||||
if verifyProof( vkey, proof):
|
||||
debugEcho("verification succeeded")
|
||||
ok proof
|
||||
else:
|
||||
err "verification failed"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -1,49 +0,0 @@
|
||||
|
||||
import pkg/groth16
|
||||
import pkg/witness
|
||||
import pkg/zkey
|
||||
import pkg/zkey_types
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
proc testProveAndVerify*( zkey_fname, wtns_fname: string): Proof =
|
||||
|
||||
echo("parsing witness & zkey files...")
|
||||
let witness = parseWitness( wtns_fname)
|
||||
let zkey = parseZKey( zkey_fname)
|
||||
|
||||
# printCoeffs(zkey.coeffs)
|
||||
|
||||
echo("generating proof...")
|
||||
let vkey = extractVKey( zkey)
|
||||
let proof = generateProof( zkey, witness )
|
||||
|
||||
echo("verifying the proof...")
|
||||
let ok = verifyProof( vkey, proof )
|
||||
echo("verification succeeded = ",ok)
|
||||
|
||||
return proof
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
proc testFakeSetupAndVerify*( r1cs_fname, wtns_fname: string, flavour=Snarkjs): Proof =
|
||||
echo("trusted setup flavour = ",flavour)
|
||||
|
||||
echo("parsing witness & r1cs files...")
|
||||
let witness = parseWitness( wtns_fname)
|
||||
let r1cs = parseR1CS( r1cs_fname)
|
||||
|
||||
echo("performing fake trusted setup...")
|
||||
let zkey = createFakeCircuitSetup( r1cs, flavour=flavour )
|
||||
|
||||
# printCoeffs(zkey.coeffs)
|
||||
|
||||
echo("generating proof...")
|
||||
let vkey = extractVKey( zkey)
|
||||
let proof = generateProof( zkey, witness )
|
||||
|
||||
echo("verifying the proof...")
|
||||
let ok = verifyProof( vkey, proof )
|
||||
echo("verification succeeded = ",ok)
|
||||
|
||||
return proof
|
||||
Loading…
x
Reference in New Issue
Block a user