Skip to content

Commit

Permalink
parametrize circuit PublicSignals (WIP, not yet working)
Browse files Browse the repository at this point in the history
  • Loading branch information
altergui committed Nov 29, 2023
1 parent 8522259 commit 9fdb56b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
12 changes: 12 additions & 0 deletions crypto/zk/circuit/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
},
},
}

Expand Down
13 changes: 1 addition & 12 deletions crypto/zk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Check failure on line 80 in crypto/zk/utils.go

View workflow job for this annotation

GitHub Actions / job_go_test

undefined: app

Check failure on line 80 in crypto/zk/utils.go

View workflow job for this annotation

GitHub Actions / job_go_checks

undefined: app
return nil, fmt.Errorf("wrong ZkSnark prover public signals format")
}
// if not, check if the rest of the arguments are provided and try to
Expand Down

0 comments on commit 9fdb56b

Please sign in to comment.