circuit output in proof.PublicSignals for proof verification

This commit is contained in:
arnaucube
2019-01-01 22:55:03 +01:00
parent 33de628a91
commit a7454213a0
8 changed files with 57 additions and 44 deletions

View File

@@ -10,14 +10,15 @@ import (
// Circuit is the data structure of the compiled circuit
type Circuit struct {
NVars int
NPublic int
NSignals int
Inputs []string
Signals []string
Witness []*big.Int
Constraints []Constraint
R1CS struct {
NVars int
NPublic int
NSignals int
Inputs []string
Signals []string
PublicSignals []string
Witness []*big.Int
Constraints []Constraint
R1CS struct {
A [][]*big.Int
B [][]*big.Int
C [][]*big.Int
@@ -151,7 +152,7 @@ func (circ *Circuit) CalculateWitness(inputs []*big.Int) ([]*big.Int, error) {
w := r1csqap.ArrayOfBigZeros(len(circ.Signals))
w[0] = big.NewInt(int64(1))
for i, input := range inputs {
w[i+1] = input
w[i+2] = input
}
for _, constraint := range circ.Constraints {
if constraint.Op == "in" {

View File

@@ -50,14 +50,14 @@ func TestCircuitParser(t *testing.T) {
b1 := big.NewInt(int64(1))
b5 := big.NewInt(int64(5))
aExpected := [][]*big.Int{
[]*big.Int{b0, b1, b0, b0, b0, b0},
[]*big.Int{b0, b0, b1, b0, b0, b0},
[]*big.Int{b0, b0, b0, b1, b0, b0},
[]*big.Int{b0, b1, b0, b0, b1, b0},
[]*big.Int{b0, b0, b1, b0, b1, b0},
[]*big.Int{b5, b0, b0, b0, b0, b1},
}
bExpected := [][]*big.Int{
[]*big.Int{b0, b1, b0, b0, b0, b0},
[]*big.Int{b0, b1, b0, b0, b0, b0},
[]*big.Int{b0, b0, b1, b0, b0, b0},
[]*big.Int{b0, b0, b1, b0, b0, b0},
[]*big.Int{b1, b0, b0, b0, b0, b0},
[]*big.Int{b1, b0, b0, b0, b0, b0},
}
@@ -65,7 +65,7 @@ func TestCircuitParser(t *testing.T) {
[]*big.Int{b0, b0, b0, b1, b0, b0},
[]*big.Int{b0, b0, b0, b0, b1, b0},
[]*big.Int{b0, b0, b0, b0, b0, b1},
[]*big.Int{b0, b0, b1, b0, b0, b0},
[]*big.Int{b0, b1, b0, b0, b0, b0},
}
assert.Equal(t, aExpected, a)

View File

@@ -147,14 +147,16 @@ func (p *Parser) Parse() (*Circuit, error) {
circuit.Signals = addToArrayIfNotExist(circuit.Signals, constraint.V2)
}
if constraint.Out == "out" {
// if Out is "out", put it after the inputs
// if Out is "out", put it after first value (one) and before the inputs
if !existInArray(circuit.Signals, constraint.Out) {
signalsCopy := copyArray(circuit.Signals)
var auxSignals []string
auxSignals = append(auxSignals, signalsCopy[0:nInputs+1]...)
auxSignals = append(auxSignals, signalsCopy[0])
auxSignals = append(auxSignals, constraint.Out)
auxSignals = append(auxSignals, signalsCopy[nInputs+1:]...)
auxSignals = append(auxSignals, signalsCopy[1:]...)
circuit.Signals = auxSignals
circuit.PublicSignals = append(circuit.PublicSignals, constraint.Out)
circuit.NPublic++
}
} else {
circuit.Signals = addToArrayIfNotExist(circuit.Signals, constraint.Out)
@@ -162,7 +164,6 @@ func (p *Parser) Parse() (*Circuit, error) {
}
circuit.NVars = len(circuit.Signals)
circuit.NSignals = len(circuit.Signals)
circuit.NPublic = 0
return circuit, nil
}
func copyArray(in []string) []string { // tmp