From 9fdb56b44c433691f893de87f484641b24ab25c5 Mon Sep 17 00:00:00 2001 From: Gui Iribarren Date: Wed, 29 Nov 2023 14:11:47 +0100 Subject: [PATCH] parametrize circuit PublicSignals (WIP, not yet working) --- crypto/zk/circuit/config.go | 12 ++++++++++++ crypto/zk/utils.go | 13 +------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/crypto/zk/circuit/config.go b/crypto/zk/circuit/config.go index 26af960fd..1f2d51fa9 100644 --- a/crypto/zk/circuit/config.go +++ b/crypto/zk/circuit/config.go @@ -37,6 +37,8 @@ type ZkCircuitConfig struct { // FilenameWasm defines the name of the file of the circuit wasm compiled // version WasmFilename string `json:"wasmFilename"` // circuit.wasm + // PublicSignals maps public signal indexes to their contents + PublicSignals map[int]string // maxCensusSize contains a precomputed max size of a census for the // circuit, which is defined by the expresion: // maxCensusSize = 2^circuitLevels @@ -106,6 +108,16 @@ var CircuitsConfigurations = map[string]*ZkCircuitConfig{ VerificationKeyFilename: "census_verification_key.json", WasmHash: hexToBytes("0xc98133cf4d84ced677549e0d848739f4e80ddf78af678cbc8b95377247a92773"), WasmFilename: "census.wasm", + PublicSignals: map[int]string{ + 0: electionId[0], + 1: electionId[1], + 2: nullifier, + 3: voteWeight, + 4: voteHash[0], + 5: voteHash[1], + 6: sikRoot, + 7: censusRoot, + }, }, } diff --git a/crypto/zk/utils.go b/crypto/zk/utils.go index e70ec1615..4773a8c27 100644 --- a/crypto/zk/utils.go +++ b/crypto/zk/utils.go @@ -18,16 +18,6 @@ import ( // A: [3]bigint, // B: [3][2]bigint, // C: [3]bigint, -// PublicSignals: [8]bigint{ -// 0: electionId[0], -// 1: electionId[1], -// 2: nullifier, -// 3: voteHash[0], -// 4: voteHash[1], -// 5: sikRoot, -// 6: censusRoot -// 7: voteWeight, -// } // } // Default length of each proof parameters @@ -36,7 +26,6 @@ const ( proofBLen = 6 // flatted proofBEncLen = 3 // matrix proofCLen = 3 - publicSigLen = 8 ) // bn254BaseField contains the Base Field of the twisted Edwards curve, whose @@ -88,7 +77,7 @@ func ProverProofToProtobufZKProof(p *prover.Proof, electionId, sikRoot, // if public signals are provided, check their format proof.PublicInputs = p.PubSignals - if p.PubSignals != nil && len(p.PubSignals) != publicSigLen { + if p.PubSignals != nil && len(p.PubSignals) != len(app.TransactionHandler.ZkCircuit().Config.PublicSignals) { // of course this won't work because app is totally out of scope of zk package return nil, fmt.Errorf("wrong ZkSnark prover public signals format") } // if not, check if the rest of the arguments are provided and try to