Browse Source

Base sum gate (#7)

* initial version of base_sum_gate

* add recursive circuit benchmark files

* added step circuit data and contant gate test

* moved step testing data into gate_testing_utils

* added test case for basesum gate

* added test for arithmetic_gate
main
Kevin Jue 2 years ago
committed by GitHub
parent
commit
a0d5ad37de
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 76099 additions and 3 deletions
  1. +1
    -1
      field/quadratic_extension.go
  2. +54
    -0
      plonky2_verifier/arithmetic_gate_test.go
  3. +64
    -0
      plonky2_verifier/base_sum_gate.go
  4. +49
    -0
      plonky2_verifier/base_sum_gate_test.go
  5. +49
    -0
      plonky2_verifier/constant_gate_test.go
  6. +173
    -0
      plonky2_verifier/data/recursive/common_circuit_data.json
  7. +26194
    -0
      plonky2_verifier/data/recursive/proof_with_public_inputs.json
  8. +140
    -0
      plonky2_verifier/data/recursive/verifier_only_circuit_data.json
  9. +172
    -0
      plonky2_verifier/data/recursive_small/common_circuit_data.json
  10. +3024
    -0
      plonky2_verifier/data/recursive_small/proof_with_public_inputs.json
  11. +140
    -0
      plonky2_verifier/data/recursive_small/verifier_only_circuit_data.json
  12. +205
    -0
      plonky2_verifier/data/step/common_circuit_data.json
  13. +45430
    -0
      plonky2_verifier/data/step/proof_with_public_inputs.json
  14. +140
    -0
      plonky2_verifier/data/step/verifier_only_circuit_data.json
  15. +44
    -2
      plonky2_verifier/gate.go
  16. +220
    -0
      plonky2_verifier/gate_testing_utils.go

+ 1
- 1
field/quadratic_extension.go

@ -150,7 +150,7 @@ func (c *QuadraticExtensionAPI) Lookup2(b0 frontend.Variable, b1 frontend.Variab
func (c *QuadraticExtensionAPI) AssertIsEqual(a, b QuadraticExtension) {
for i := 0; i < 2; i++ {
c.fieldAPI.AssertIsEqual(a[0], b[0])
c.fieldAPI.AssertIsEqual(a[i], b[i])
}
}

+ 54
- 0
plonky2_verifier/arithmetic_gate_test.go

@ -0,0 +1,54 @@
package plonky2_verifier
import (
"errors"
"fmt"
. "gnark-plonky2-verifier/field"
"testing"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/test"
)
type TestArithmeticGateCircuit struct{}
func (circuit *TestArithmeticGateCircuit) Define(api frontend.API) error {
commonCircuitData := DeserializeCommonCircuitData("./data/step/common_circuit_data.json")
numSelectors := len(commonCircuitData.SelectorsInfo.groups)
fieldAPI := NewFieldAPI(api)
qeAPI := NewQuadraticExtensionAPI(fieldAPI, commonCircuitData.DegreeBits)
plonkChip := NewPlonkChip(api, qeAPI, commonCircuitData)
arithmeticGate := ArithmeticGate{numOps: 20}
vars := EvaluationVars{localConstants: localConstants[numSelectors:], localWires: localWires, publicInputsHash: publicInputsHash}
constraints := arithmeticGate.EvalUnfiltered(plonkChip, vars)
if len(constraints) != len(arithmeticGateExpectedConstraints) {
return errors.New("arithmetic gate constraints length mismatch")
}
for i := 0; i < len(constraints); i++ {
fmt.Printf("constraints[%d] = %v\n", i, constraints[i])
}
for i := 0; i < len(constraints); i++ {
qeAPI.AssertIsEqual(constraints[i], arithmeticGateExpectedConstraints[i])
}
return nil
}
func TestArithmeticGate(t *testing.T) {
assert := test.NewAssert(t)
testCase := func() {
circuit := TestArithmeticGateCircuit{}
witness := TestArithmeticGateCircuit{}
err := test.IsSolved(&circuit, &witness, TEST_CURVE.ScalarField())
assert.NoError(err)
}
testCase()
}

+ 64
- 0
plonky2_verifier/base_sum_gate.go

@ -0,0 +1,64 @@
package plonky2_verifier
import (
"fmt"
. "gnark-plonky2-verifier/field"
)
const (
WIRE_SUM = 0
START_LIMBS = 1
)
type BaseSumGate struct {
numLimbs uint64
base uint64
}
func NewBaseSumGate(numLimbs uint64, base uint64) *BaseSumGate {
return &BaseSumGate{
numLimbs: numLimbs,
base: base,
}
}
func (g *BaseSumGate) Id() string {
return fmt.Sprintf("BaseSumGate { num_ops: %d } + Base: %d", g.numLimbs, g.base)
}
func (g *BaseSumGate) limbs() []uint64 {
limbIndices := make([]uint64, g.numLimbs)
for i := uint64(0); i < g.numLimbs; i++ {
limbIndices[i] = uint64(START_LIMBS + i)
}
return limbIndices
}
func (g *BaseSumGate) EvalUnfiltered(p *PlonkChip, vars EvaluationVars) []QuadraticExtension {
sum := vars.localWires[WIRE_SUM]
limbs := make([]QuadraticExtension, g.numLimbs)
limbIndices := g.limbs()
for i, limbIdx := range limbIndices {
limbs[i] = vars.localWires[limbIdx]
}
base_qe := p.qeAPI.FieldToQE(NewFieldElement(g.base))
computedSum := p.qeAPI.ReduceWithPowers(
limbs,
base_qe,
)
var constraints []QuadraticExtension
constraints = append(constraints, p.qeAPI.SubExtension(computedSum, sum))
for _, limb := range limbs {
acc := p.qeAPI.ONE_QE
for i := uint64(0); i < g.base; i++ {
difference := p.qeAPI.SubExtension(limb, p.qeAPI.FieldToQE(NewFieldElement(i)))
acc = p.qeAPI.MulExtension(acc, difference)
}
constraints = append(constraints, acc)
}
return constraints
}

+ 49
- 0
plonky2_verifier/base_sum_gate_test.go

@ -0,0 +1,49 @@
package plonky2_verifier
import (
"errors"
. "gnark-plonky2-verifier/field"
"testing"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/test"
)
type TestBaseSumGateCircuit struct{}
func (circuit *TestBaseSumGateCircuit) Define(api frontend.API) error {
commonCircuitData := DeserializeCommonCircuitData("./data/step/common_circuit_data.json")
numSelectors := len(commonCircuitData.SelectorsInfo.groups)
fieldAPI := NewFieldAPI(api)
qeAPI := NewQuadraticExtensionAPI(fieldAPI, commonCircuitData.DegreeBits)
plonkChip := NewPlonkChip(api, qeAPI, commonCircuitData)
baseSumGate := BaseSumGate{numLimbs: 32, base: 2}
vars := EvaluationVars{localConstants: localConstants[numSelectors:], localWires: localWires, publicInputsHash: publicInputsHash}
constraints := baseSumGate.EvalUnfiltered(plonkChip, vars)
if len(constraints) != len(baseSumGateExpectedConstraints) {
return errors.New("constant gate constraints length mismatch")
}
for i := 0; i < len(constraints); i++ {
qeAPI.AssertIsEqual(constraints[i], baseSumGateExpectedConstraints[i])
}
return nil
}
func TestBaseSumGate(t *testing.T) {
assert := test.NewAssert(t)
testCase := func() {
circuit := TestBaseSumGateCircuit{}
witness := TestBaseSumGateCircuit{}
err := test.IsSolved(&circuit, &witness, TEST_CURVE.ScalarField())
assert.NoError(err)
}
testCase()
}

+ 49
- 0
plonky2_verifier/constant_gate_test.go

@ -0,0 +1,49 @@
package plonky2_verifier
import (
"errors"
. "gnark-plonky2-verifier/field"
"testing"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/test"
)
type TestConstantGateCircuit struct{}
func (circuit *TestConstantGateCircuit) Define(api frontend.API) error {
commonCircuitData := DeserializeCommonCircuitData("./data/step/common_circuit_data.json")
numSelectors := len(commonCircuitData.SelectorsInfo.groups)
fieldAPI := NewFieldAPI(api)
qeAPI := NewQuadraticExtensionAPI(fieldAPI, commonCircuitData.DegreeBits)
plonkChip := NewPlonkChip(api, qeAPI, commonCircuitData)
constantGate := ConstantGate{numConsts: 2}
vars := EvaluationVars{localConstants: localConstants[numSelectors:], localWires: localWires, publicInputsHash: publicInputsHash}
constraints := constantGate.EvalUnfiltered(plonkChip, vars)
if len(constraints) != len(constantGateExpectedConstraints) {
return errors.New("constant gate constraints length mismatch")
}
for i := 0; i < len(constraints); i++ {
qeAPI.AssertIsEqual(constraints[i], constantGateExpectedConstraints[i])
}
return nil
}
func TestConstantGate(t *testing.T) {
assert := test.NewAssert(t)
testCase := func() {
circuit := TestConstantGateCircuit{}
witness := TestConstantGateCircuit{}
err := test.IsSolved(&circuit, &witness, TEST_CURVE.ScalarField())
assert.NoError(err)
}
testCase()
}

+ 173
- 0
plonky2_verifier/data/recursive/common_circuit_data.json

@ -0,0 +1,173 @@
{
"config": {
"num_wires": 135,
"num_routed_wires": 80,
"num_constants": 2,
"use_base_arithmetic_gate": true,
"security_bits": 100,
"num_challenges": 2,
"zero_knowledge": false,
"max_quotient_degree_factor": 8,
"fri_config": {
"rate_bits": 3,
"cap_height": 4,
"proof_of_work_bits": 16,
"reduction_strategy": {
"ConstantArityBits": [
4,
5
]
},
"num_query_rounds": 28
}
},
"fri_params": {
"config": {
"rate_bits": 3,
"cap_height": 4,
"proof_of_work_bits": 16,
"reduction_strategy": {
"ConstantArityBits": [
4,
5
]
},
"num_query_rounds": 28
},
"hiding": false,
"degree_bits": 12,
"reduction_arity_bits": [
4,
4
]
},
"gates": [
"NoopGate",
"PublicInputGate",
"BaseSumGate { num_limbs: 63 } + Base: 2",
"ReducingExtensionGate { num_coeffs: 32 }",
"ReducingGate { num_coeffs: 43 }",
"ArithmeticExtensionGate { num_ops: 10 }",
"ArithmeticGate { num_ops: 20 }",
"MulExtensionGate { num_ops: 13 }",
"RandomAccessGate { bits: 4, num_copies: 4, num_extra_constants: 2, _phantom: PhantomData<plonky2_field::goldilocks_field::GoldilocksField> }<D=2>",
"CosetInterpolationGate { subgroup_bits: 4, degree: 6, barycentric_weights: [17293822565076172801, 18374686475376656385, 18446744069413535745, 281474976645120, 17592186044416, 256, 18446744000695107601, 18446744065119617025, 1152921504338411520, 72057594037927936, 1048576, 18446462594437939201, 18446726477228539905, 18446744069414584065, 68719476720, 4294967296], _phantom: PhantomData<plonky2_field::goldilocks_field::GoldilocksField> }<D=2>",
"PoseidonGate(PhantomData<plonky2_field::goldilocks_field::GoldilocksField>)<WIDTH=12>"
],
"selectors_info": {
"selector_indices": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
2,
2
],
"groups": [
{
"start": 0,
"end": 6
},
{
"start": 6,
"end": 9
},
{
"start": 9,
"end": 11
}
]
},
"quotient_degree_factor": 8,
"num_gate_constraints": 123,
"num_constants": 5,
"num_public_inputs": 0,
"k_is": [
1,
7,
49,
343,
2401,
16807,
117649,
823543,
5764801,
40353607,
282475249,
1977326743,
13841287201,
96889010407,
678223072849,
4747561509943,
33232930569601,
232630513987207,
1628413597910449,
11398895185373143,
79792266297612001,
558545864083284007,
3909821048582988049,
8922003270666332022,
7113790686420571191,
12903046666114829695,
16534350385145470581,
5059988279530788141,
16973173887300932666,
8131752794619022736,
1582037354089406189,
11074261478625843323,
3732854072722565977,
7683234439643377518,
16889152938674473984,
7543606154233811962,
15911754940807515092,
701820169165099718,
4912741184155698026,
15942444219675301861,
916645121239607101,
6416515848677249707,
8022122801911579307,
814627405137302186,
5702391835961115302,
3023254712898638472,
2716038920875884983,
565528376716610560,
3958698637016273920,
9264146389699333119,
9508792519651578870,
11221315429317299127,
4762231727562756605,
14888878023524711914,
11988425817600061793,
10132004445542095267,
15583798910550913906,
16852872026783475737,
7289639770996824233,
14133990258148600989,
6704211459967285318,
10035992080941828584,
14911712358349047125,
12148266161370408270,
11250886851934520606,
4969231685883306958,
16337877731768564385,
3684679705892444769,
7346013871832529062,
14528608963998534792,
9466542400916821939,
10925564598174000610,
2691975909559666986,
397087297503084581,
2779611082521592067,
1010533508236560148,
7073734557655921036,
12622653764762278610,
14571600075677612986,
9767480182670369297
],
"num_partial_products": 9
}

+ 26194
- 0
plonky2_verifier/data/recursive/proof_with_public_inputs.json
File diff suppressed because it is too large
View File


+ 140
- 0
plonky2_verifier/data/recursive/verifier_only_circuit_data.json

@ -0,0 +1,140 @@
{
"constants_sigmas_cap": [
{
"elements": [
5792880812518408658,
2007865592137458435,
5118679776640867091,
13069431186724985571
]
},
{
"elements": [
620745627896223750,
11689482378865345226,
515625484560203909,
6594700411046985771
]
},
{
"elements": [
4288547219194413000,
13137436527356415412,
12622945773280822587,
650627082873761457
]
},
{
"elements": [
13506996103707830465,
8679821128676565111,
4223042913738287628,
9099197279443824593
]
},
{
"elements": [
14449575924890308633,
8733833351673036584,
16541374894852431819,
9332074455551145433
]
},
{
"elements": [
10076928807302913775,
3821138534617469739,
1717959071597020718,
17760656161674093717
]
},
{
"elements": [
2599426417611084017,
13871968726722310950,
1516291378797220061,
13799666340648349967
]
},
{
"elements": [
12663813165492321869,
14876506856106059016,
1242723042851988831,
2875934737469787816
]
},
{
"elements": [
17378423119286703930,
11222598627075744078,
9488528583590922099,
14157718813638267686
]
},
{
"elements": [
1071412395592558182,
18101728088624707784,
3182026360229291426,
14227530413232734538
]
},
{
"elements": [
726974142246132532,
15153315199262507247,
17940113059510197877,
16772587044853202303
]
},
{
"elements": [
12231534358502296703,
10511512947619127431,
16590010230992836643,
12522924984185338479
]
},
{
"elements": [
8037124124878150231,
7299067373190351508,
6928393757878692343,
14665216450327743533
]
},
{
"elements": [
8476349181260794151,
2992858515573144844,
12544833538408559347,
12322593314271890822
]
},
{
"elements": [
17452538538131258483,
16559982778748471691,
7832234514212696397,
7687737265950783860
]
},
{
"elements": [
5386649132465675374,
15880918294706587722,
12305658309516685089,
1973473830101720437
]
}
],
"circuit_digest": {
"elements": [
7986243079228529757,
6431975618990554147,
3826625528654889031,
10807866526356205171
]
}
}

+ 172
- 0
plonky2_verifier/data/recursive_small/common_circuit_data.json

@ -0,0 +1,172 @@
{
"config": {
"num_wires": 135,
"num_routed_wires": 80,
"num_constants": 2,
"use_base_arithmetic_gate": true,
"security_bits": 100,
"num_challenges": 2,
"zero_knowledge": false,
"max_quotient_degree_factor": 8,
"fri_config": {
"rate_bits": 3,
"cap_height": 4,
"proof_of_work_bits": 16,
"reduction_strategy": {
"ConstantArityBits": [
4,
5
]
},
"num_query_rounds": 2
}
},
"fri_params": {
"config": {
"rate_bits": 3,
"cap_height": 4,
"proof_of_work_bits": 16,
"reduction_strategy": {
"ConstantArityBits": [
4,
5
]
},
"num_query_rounds": 2
},
"hiding": false,
"degree_bits": 9,
"reduction_arity_bits": [
4
]
},
"gates": [
"NoopGate",
"ConstantGate { num_consts: 2 }",
"PublicInputGate",
"BaseSumGate { num_limbs: 63 } + Base: 2",
"ReducingExtensionGate { num_coeffs: 32 }",
"ReducingGate { num_coeffs: 43 }",
"ArithmeticExtensionGate { num_ops: 10 }",
"ArithmeticGate { num_ops: 20 }",
"MulExtensionGate { num_ops: 13 }",
"RandomAccessGate { bits: 4, num_copies: 4, num_extra_constants: 2, _phantom: PhantomData<plonky2_field::goldilocks_field::GoldilocksField> }<D=2>",
"PoseidonGate(PhantomData<plonky2_field::goldilocks_field::GoldilocksField>)<WIDTH=12>"
],
"selectors_info": {
"selector_indices": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1,
2
],
"groups": [
{
"start": 0,
"end": 6
},
{
"start": 6,
"end": 10
},
{
"start": 10,
"end": 11
}
]
},
"quotient_degree_factor": 8,
"num_gate_constraints": 123,
"num_constants": 5,
"num_public_inputs": 0,
"k_is": [
1,
7,
49,
343,
2401,
16807,
117649,
823543,
5764801,
40353607,
282475249,
1977326743,
13841287201,
96889010407,
678223072849,
4747561509943,
33232930569601,
232630513987207,
1628413597910449,
11398895185373143,
79792266297612001,
558545864083284007,
3909821048582988049,
8922003270666332022,
7113790686420571191,
12903046666114829695,
16534350385145470581,
5059988279530788141,
16973173887300932666,
8131752794619022736,
1582037354089406189,
11074261478625843323,
3732854072722565977,
7683234439643377518,
16889152938674473984,
7543606154233811962,
15911754940807515092,
701820169165099718,
4912741184155698026,
15942444219675301861,
916645121239607101,
6416515848677249707,
8022122801911579307,
814627405137302186,
5702391835961115302,
3023254712898638472,
2716038920875884983,
565528376716610560,
3958698637016273920,
9264146389699333119,
9508792519651578870,
11221315429317299127,
4762231727562756605,
14888878023524711914,
11988425817600061793,
10132004445542095267,
15583798910550913906,
16852872026783475737,
7289639770996824233,
14133990258148600989,
6704211459967285318,
10035992080941828584,
14911712358349047125,
12148266161370408270,
11250886851934520606,
4969231685883306958,
16337877731768564385,
3684679705892444769,
7346013871832529062,
14528608963998534792,
9466542400916821939,
10925564598174000610,
2691975909559666986,
397087297503084581,
2779611082521592067,
1010533508236560148,
7073734557655921036,
12622653764762278610,
14571600075677612986,
9767480182670369297
],
"num_partial_products": 9
}

+ 3024
- 0
plonky2_verifier/data/recursive_small/proof_with_public_inputs.json
File diff suppressed because it is too large
View File


+ 140
- 0
plonky2_verifier/data/recursive_small/verifier_only_circuit_data.json

@ -0,0 +1,140 @@
{
"constants_sigmas_cap": [
{
"elements": [
158845205314874220,
9668380905015929998,
1411954196422652535,
16261560315091018602
]
},
{
"elements": [
10819768878069205512,
10806329121382974236,
4449962652936030991,
3437130958683867731
]
},
{
"elements": [
13409308832792573752,
5142428395608775971,
8304804561534366563,
3333782371953158323
]
},
{
"elements": [
18228625912291347825,
10166925566614695203,
18158685652491144528,
5812383934966268838
]
},
{
"elements": [
9826807818157299303,
16982355347088639655,
9164194217012055587,
2807644941373961188
]
},
{
"elements": [
14310741273297755831,
12981827714166111968,
4530737992662289685,
18335773668219568846
]
},
{
"elements": [
7917966912899515534,
17667717333057450416,
952641997971486450,
428804504796282154
]
},
{
"elements": [
6150969121154358920,
8533162538572915310,
13902780732405127329,
10048329503515769882
]
},
{
"elements": [
17799006350046251788,
10571037994954145577,
16382491710544403234,
8887053452984223370
]
},
{
"elements": [
3963886065503765705,
2739764768577488879,
5343505536176223500,
9151432391854309795
]
},
{
"elements": [
4165310799113686308,
10915634867031695254,
5813235613342911366,
17907275021812350449
]
},
{
"elements": [
12954911538188629834,
6738667513261916639,
12025960525821021496,
3765915660295958137
]
},
{
"elements": [
15699732256890621800,
14355912053969064032,
9559845752177194786,
6008684051170164157
]
},
{
"elements": [
5973104887002336129,
15822297470108300955,
1285855046140391788,
8567304882129939594
]
},
{
"elements": [
531701086966465293,
13988001761158611208,
10640541520023034000,
12368315472470450606
]
},
{
"elements": [
16726108137472169650,
9400941780708454743,
2656080070909638220,
10262921538692249992
]
}
],
"circuit_digest": {
"elements": [
7291397556757192596,
149044718719699113,
14214393601687894808,
15901190186686913364
]
}
}

+ 205
- 0
plonky2_verifier/data/step/common_circuit_data.json

@ -0,0 +1,205 @@
{
"config": {
"num_wires": 136,
"num_routed_wires": 80,
"num_constants": 2,
"use_base_arithmetic_gate": true,
"security_bits": 100,
"num_challenges": 2,
"zero_knowledge": false,
"max_quotient_degree_factor": 8,
"fri_config": {
"rate_bits": 3,
"cap_height": 4,
"proof_of_work_bits": 16,
"reduction_strategy": {
"ConstantArityBits": [
4,
5
]
},
"num_query_rounds": 28
}
},
"fri_params": {
"config": {
"rate_bits": 3,
"cap_height": 4,
"proof_of_work_bits": 16,
"reduction_strategy": {
"ConstantArityBits": [
4,
5
]
},
"num_query_rounds": 28
},
"hiding": false,
"degree_bits": 21,
"reduction_arity_bits": [
4,
4,
4,
4
]
},
"gates": [
"NoopGate",
"ConstantGate { num_consts: 2 }",
"PublicInputGate",
"BaseSumGate { num_limbs: 32 } + Base: 2",
"BaseSumGate { num_limbs: 63 } + Base: 2",
"ArithmeticGate { num_ops: 20 }",
"RandomAccessGate { bits: 2, num_copies: 13, num_extra_constants: 2, _phantom: PhantomData<plonky2_field::goldilocks_field::GoldilocksField> }<D=2>",
"XOR3Gate { num_xors: 16 }",
"BaseSumGate { num_limbs: 16 } + Base: 4",
"ComparisonGate { num_bits: 32, num_chunks: 16, _phantom: PhantomData<plonky2_field::goldilocks_field::GoldilocksField> }<D=2>",
"U32AddManyGate { num_addends: 11, num_ops: 4, _phantom: PhantomData<plonky2_field::goldilocks_field::GoldilocksField> }",
"U32AddManyGate { num_addends: 13, num_ops: 4, _phantom: PhantomData<plonky2_field::goldilocks_field::GoldilocksField> }",
"U32AddManyGate { num_addends: 15, num_ops: 3, _phantom: PhantomData<plonky2_field::goldilocks_field::GoldilocksField> }",
"U32AddManyGate { num_addends: 16, num_ops: 3, _phantom: PhantomData<plonky2_field::goldilocks_field::GoldilocksField> }",
"U32AddManyGate { num_addends: 3, num_ops: 5, _phantom: PhantomData<plonky2_field::goldilocks_field::GoldilocksField> }",
"U32AddManyGate { num_addends: 5, num_ops: 5, _phantom: PhantomData<plonky2_field::goldilocks_field::GoldilocksField> }",
"U32AddManyGate { num_addends: 7, num_ops: 4, _phantom: PhantomData<plonky2_field::goldilocks_field::GoldilocksField> }",
"U32AddManyGate { num_addends: 9, num_ops: 4, _phantom: PhantomData<plonky2_field::goldilocks_field::GoldilocksField> }",
"U32ArithmeticGate { num_ops: 3, _phantom: PhantomData<plonky2_field::goldilocks_field::GoldilocksField> }",
"U32RangeCheckGate { num_input_limbs: 8, _phantom: PhantomData<plonky2_field::goldilocks_field::GoldilocksField> }",
"U32SubtractionGate { num_ops: 6, _phantom: PhantomData<plonky2_field::goldilocks_field::GoldilocksField> }",
"RandomAccessGate { bits: 4, num_copies: 4, num_extra_constants: 2, _phantom: PhantomData<plonky2_field::goldilocks_field::GoldilocksField> }<D=2>"
],
"selectors_info": {
"selector_indices": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1,
1,
2,
2,
2,
2,
2,
3,
3,
3,
3,
3,
4
],
"groups": [
{
"start": 0,
"end": 6
},
{
"start": 6,
"end": 11
},
{
"start": 11,
"end": 16
},
{
"start": 16,
"end": 21
},
{
"start": 21,
"end": 22
}
]
},
"quotient_degree_factor": 8,
"num_gate_constraints": 136,
"num_constants": 7,
"num_public_inputs": 0,
"k_is": [
1,
7,
49,
343,
2401,
16807,
117649,
823543,
5764801,
40353607,
282475249,
1977326743,
13841287201,
96889010407,
678223072849,
4747561509943,
33232930569601,
232630513987207,
1628413597910449,
11398895185373143,
79792266297612001,
558545864083284007,
3909821048582988049,
8922003270666332022,
7113790686420571191,
12903046666114829695,
16534350385145470581,
5059988279530788141,
16973173887300932666,
8131752794619022736,
1582037354089406189,
11074261478625843323,
3732854072722565977,
7683234439643377518,
16889152938674473984,
7543606154233811962,
15911754940807515092,
701820169165099718,
4912741184155698026,
15942444219675301861,
916645121239607101,
6416515848677249707,
8022122801911579307,
814627405137302186,
5702391835961115302,
3023254712898638472,
2716038920875884983,
565528376716610560,
3958698637016273920,
9264146389699333119,
9508792519651578870,
11221315429317299127,
4762231727562756605,
14888878023524711914,
11988425817600061793,
10132004445542095267,
15583798910550913906,
16852872026783475737,
7289639770996824233,
14133990258148600989,
6704211459967285318,
10035992080941828584,
14911712358349047125,
12148266161370408270,
11250886851934520606,
4969231685883306958,
16337877731768564385,
3684679705892444769,
7346013871832529062,
14528608963998534792,
9466542400916821939,
10925564598174000610,
2691975909559666986,
397087297503084581,
2779611082521592067,
1010533508236560148,
7073734557655921036,
12622653764762278610,
14571600075677612986,
9767480182670369297
],
"num_partial_products": 9
}

+ 45430
- 0
plonky2_verifier/data/step/proof_with_public_inputs.json
File diff suppressed because it is too large
View File


+ 140
- 0
plonky2_verifier/data/step/verifier_only_circuit_data.json

@ -0,0 +1,140 @@
{
"constants_sigmas_cap": [
{
"elements": [
9037422181318074482,
13844553280258601189,
14013690396566737561,
14600533186953608428
]
},
{
"elements": [
3891365497285560518,
6785071445101560305,
7146616719154245281,
8484433928946731576
]
},
{
"elements": [
15935467950899360740,
1041659913562170406,
11898906592313038819,
7940456224436700998
]
},
{
"elements": [
17420135248456983,
10686061014804565544,
17782021355470763205,
12726022340820773339
]
},
{
"elements": [
13322967402317526249,
12119892482906381301,
1483851501277040422,
17519911664522741561
]
},
{
"elements": [
3901474702590233137,
16494478574194405372,
3644962804006307872,
7967195830112920768
]
},
{
"elements": [
15532816309418050992,
11198055639421810456,
7449000032233257165,
6080646728225911938
]
},
{
"elements": [
7944791944524511304,
15470849481646525511,
11102721978231118523,
10011467322465036320
]
},
{
"elements": [
14679375199524381062,
9219647684485300612,
8902882543708912876,
6737676211275058717
]
},
{
"elements": [
15215848762718399329,
9538467614418882672,
7337952705707955964,
17932579689749986997
]
},
{
"elements": [
3111383469397480110,
17276616486884637185,
10511216595022742027,
3343575652946909638
]
},
{
"elements": [
2417848701164748156,
7846191940051381446,
4363725272084187306,
3143323624098735830
]
},
{
"elements": [
7639597922146523429,
14015537888097194053,
10449936634441844342,
3897071524048579556
]
},
{
"elements": [
12445360068819311840,
4910166437012489060,
9670875686931891121,
5569206524147441284
]
},
{
"elements": [
6965775890897127688,
14853930701622190781,
2643689027677976461,
1883768007952536249
]
},
{
"elements": [
6771363979354677578,
6567107174924251028,
15758449129319031800,
6619880945043941329
]
}
],
"circuit_digest": {
"elements": [
8574090053162898339,
2808971464690312489,
14807704193989191909,
14951686172889873386
]
}
}

+ 44
- 2
plonky2_verifier/gate.go

@ -1,8 +1,8 @@
package plonky2_verifier
import (
"fmt"
. "gnark-plonky2-verifier/field"
"regexp"
"strconv"
"strings"
)
@ -47,7 +47,49 @@ func GateInstanceFromId(gateId string) gate {
return NewPoseidonGate()
}
panic(fmt.Sprintf("Unknown gate ID %s", gateId))
if strings.HasPrefix(gateId, "BaseSumGate") {
// Has the format "BaseSumGate { num_limbs: 32 } + Base: 2"
regEx := "BaseSumGate { num_limbs: (?P<numLimbs>[0-9]+) } \\+ Base: (?P<base>[0-9]+)"
r, err := regexp.Compile(regEx)
if err != nil {
panic("Invalid BaseSumGate regular expression")
}
matches := getRegExMatches(r, gateId)
numLimbsStr, hasNumLimbs := matches["numLimbs"]
baseStr, hasBase := matches["base"]
if !hasNumLimbs || !hasBase {
panic("Invalid BaseSumGate ID")
}
numLimbs, err := strconv.Atoi(numLimbsStr)
if err != nil {
panic("Invalid BaseSumGate ID: " + err.Error())
}
base, err := strconv.Atoi(baseStr)
if err != nil {
panic("Invalid BaseSumGate ID: " + err.Error())
}
return NewBaseSumGate(uint64(numLimbs), uint64(base))
}
return nil
//panic(fmt.Sprintf("Unknown gate ID %s", gateId))
}
func getRegExMatches(r *regexp.Regexp, gateId string) map[string]string {
matches := r.FindStringSubmatch(gateId)
result := make(map[string]string)
for i, name := range r.SubexpNames() {
if i != 0 && name != "" {
result[name] = matches[i]
}
}
return result
}
func (p *PlonkChip) computeFilter(

+ 220
- 0
plonky2_verifier/gate_testing_utils.go

@ -0,0 +1,220 @@
package plonky2_verifier
import (
. "gnark-plonky2-verifier/field"
)
var localConstants = []QuadraticExtension{
{NewFieldElement(14938388220067017512), NewFieldElement(6893617978345561255)},
{NewFieldElement(2858278997849927318), NewFieldElement(14613858972289114497)},
{NewFieldElement(12010705804054043554), NewFieldElement(17734088886423096402)},
{NewFieldElement(6471692081681050808), NewFieldElement(18106394403447308154)},
{NewFieldElement(12558554458272921972), NewFieldElement(2216637096996035026)},
{NewFieldElement(2742311400964131460), NewFieldElement(9282906066726805869)},
{NewFieldElement(6596410029573254275), NewFieldElement(10257498171037842553)},
}
var localWires = []QuadraticExtension{
{NewFieldElement(2324480063341987239), NewFieldElement(988591962437064919)},
{NewFieldElement(14688677982646642822), NewFieldElement(8146247054257470414)},
{NewFieldElement(17333596212120632616), NewFieldElement(8229773878724567671)},
{NewFieldElement(16821804945910820925), NewFieldElement(12343335221440433490)},
{NewFieldElement(2756227950103887825), NewFieldElement(343560939592426117)},
{NewFieldElement(16596623007682686427), NewFieldElement(16182492379544649001)},
{NewFieldElement(11316887259286577994), NewFieldElement(5467115228713222299)},
{NewFieldElement(1582490957227381752), NewFieldElement(6925101494868390621)},
{NewFieldElement(17935248409332290352), NewFieldElement(12534157394828412916)},
{NewFieldElement(1232026497545098356), NewFieldElement(14048694225063532055)},
{NewFieldElement(11979806059027179452), NewFieldElement(17007628877389084459)},
{NewFieldElement(6185211824111055171), NewFieldElement(11113325383534952676)},
{NewFieldElement(5285260129504523793), NewFieldElement(2234312045539869327)},
{NewFieldElement(5097097637012137260), NewFieldElement(6201025554481621574)},
{NewFieldElement(6037242957330965254), NewFieldElement(8600833538151893000)},
{NewFieldElement(1840669856531831838), NewFieldElement(15065652255235975922)},
{NewFieldElement(12697827657439264676), NewFieldElement(8513261715427030745)},
{NewFieldElement(17293199904676005799), NewFieldElement(3250033655198439882)},
{NewFieldElement(15670279238000114139), NewFieldElement(2873593865532946130)},
{NewFieldElement(8233044221496845350), NewFieldElement(7769536024141251466)},
{NewFieldElement(7276958187322513627), NewFieldElement(1860660389845587459)},
{NewFieldElement(9589532469937976759), NewFieldElement(7590567423994010364)},
{NewFieldElement(16188252206420308967), NewFieldElement(1215332132961798729)},
{NewFieldElement(4284385291851770933), NewFieldElement(8054708369354118180)},
{NewFieldElement(951064484118793750), NewFieldElement(14928634967654532194)},
{NewFieldElement(5756940583948879782), NewFieldElement(16919129773187566805)},
{NewFieldElement(14616825313554663172), NewFieldElement(14608067953510361893)},
{NewFieldElement(2218969368435230247), NewFieldElement(8314107073610762130)},
{NewFieldElement(2846464114111699115), NewFieldElement(1739645682168118162)},
{NewFieldElement(9428678995108626933), NewFieldElement(18300292734756419913)},
{NewFieldElement(17837447932135148748), NewFieldElement(16963062756757640776)},
{NewFieldElement(15769972692897111778), NewFieldElement(11937356836123640190)},
{NewFieldElement(8427612563992716672), NewFieldElement(6338936101976157422)},
{NewFieldElement(8087028861430760589), NewFieldElement(15904493721713953322)},
{NewFieldElement(16852312552899313453), NewFieldElement(12703698940483431753)},
{NewFieldElement(9385581021480003680), NewFieldElement(16428288666295194603)},
{NewFieldElement(17228209431960982877), NewFieldElement(7918190884273718559)},
{NewFieldElement(3132939554659874022), NewFieldElement(14065724777617623144)},
{NewFieldElement(1997749289316112361), NewFieldElement(9278657719821874692)},
{NewFieldElement(11261631966308838097), NewFieldElement(17864868364492856478)},
{NewFieldElement(6870413790049792873), NewFieldElement(7958529866191467568)},
{NewFieldElement(3285486169947371103), NewFieldElement(13432787563835021279)},
{NewFieldElement(15050449752793271273), NewFieldElement(18354035013159256035)},
{NewFieldElement(13156406563219393216), NewFieldElement(2811064537112579464)},
{NewFieldElement(152960041933474907), NewFieldElement(1638753743319968389)},
{NewFieldElement(319825484888354934), NewFieldElement(9316401211755928943)},
{NewFieldElement(16408408071810237531), NewFieldElement(18410352386107353801)},
{NewFieldElement(11721234235617526034), NewFieldElement(15999840912099509122)},
{NewFieldElement(6334230580789589688), NewFieldElement(14426162209351753421)},
{NewFieldElement(958567038590387846), NewFieldElement(8029518124072166613)},
{NewFieldElement(14177438370769025330), NewFieldElement(16473317446385361345)},
{NewFieldElement(15581189373117842086), NewFieldElement(5900338653012073386)},
{NewFieldElement(8240400515986653624), NewFieldElement(14185121622736441262)},
{NewFieldElement(6679588999186450167), NewFieldElement(7128455250623622155)},
{NewFieldElement(16252662677474545634), NewFieldElement(11498423056076196888)},
{NewFieldElement(15806801790824973416), NewFieldElement(2139294885746295937)},
{NewFieldElement(2686237135450455588), NewFieldElement(11560495253516227160)},
{NewFieldElement(10794154831626450247), NewFieldElement(14846136074280133457)},
{NewFieldElement(10904017069956482237), NewFieldElement(16678728929164911588)},
{NewFieldElement(77097765992419633), NewFieldElement(6037802885211793535)},
{NewFieldElement(2948949654471962353), NewFieldElement(2821197372203299784)},
{NewFieldElement(11058031646382030618), NewFieldElement(14661594862905661700)},
{NewFieldElement(12154711323908739968), NewFieldElement(16167190320499561302)},
{NewFieldElement(7860977505669195590), NewFieldElement(13935954304018092783)},
{NewFieldElement(18189874348209070279), NewFieldElement(11538053105967940289)},
{NewFieldElement(11425397866380016050), NewFieldElement(3629278068857786221)},
{NewFieldElement(14222050824749623144), NewFieldElement(15140845573600227476)},
{NewFieldElement(11344695042959853614), NewFieldElement(2169085408567386370)},
{NewFieldElement(1382814149657132134), NewFieldElement(1236079356280021064)},
{NewFieldElement(17447449634981200877), NewFieldElement(4036324561038142974)},
{NewFieldElement(11667566735027246199), NewFieldElement(7504612499562579295)},
{NewFieldElement(8096661641373469320), NewFieldElement(17495789134569173932)},
{NewFieldElement(9772815018478920866), NewFieldElement(6155533504741603890)},
{NewFieldElement(4680980484631369987), NewFieldElement(12005731930547792380)},
{NewFieldElement(6030057570246380244), NewFieldElement(1574605083038813985)},
{NewFieldElement(6754716419760683051), NewFieldElement(9739266036232852396)},
{NewFieldElement(3724513823179248054), NewFieldElement(13013306109228123804)},
{NewFieldElement(11890451292401098866), NewFieldElement(16486773210504598590)},
{NewFieldElement(15585701182352051988), NewFieldElement(11720999619266399739)},
{NewFieldElement(7485278618867936600), NewFieldElement(11145589513887907261)},
{NewFieldElement(14193072368816296635), NewFieldElement(7323345281142640608)},
{NewFieldElement(17524516352488247889), NewFieldElement(15683878140283813020)},
{NewFieldElement(12837567742060157665), NewFieldElement(4718676941458713108)},
{NewFieldElement(6217075579383787974), NewFieldElement(6370591763549375649)},
{NewFieldElement(8359486437738096506), NewFieldElement(10778994345307569722)},
{NewFieldElement(4952581951776675799), NewFieldElement(17817948246329576635)},
{NewFieldElement(3976052009388288681), NewFieldElement(17849902626188930996)},
{NewFieldElement(17810794672545767939), NewFieldElement(1041595632469164526)},
{NewFieldElement(14280479506185077398), NewFieldElement(9432275670660632521)},
{NewFieldElement(16096793441725012598), NewFieldElement(14080357378312550361)},
{NewFieldElement(2808358450883300976), NewFieldElement(18155683068497079023)},
{NewFieldElement(12506615906620507426), NewFieldElement(13547702647793093771)},
{NewFieldElement(543665817978834688), NewFieldElement(11749575935793871460)},
{NewFieldElement(14472836352047062696), NewFieldElement(12745333723416264174)},
{NewFieldElement(12981918713322309538), NewFieldElement(12274815259004888156)},
{NewFieldElement(8926153023959879624), NewFieldElement(15612804752658609157)},
{NewFieldElement(15470343302949437595), NewFieldElement(11164995109470525521)},
{NewFieldElement(10520929231082168869), NewFieldElement(16888496821066277493)},
{NewFieldElement(1028056151721181243), NewFieldElement(8120934238589042033)},
{NewFieldElement(1810007995141850479), NewFieldElement(2490559022189551873)},
{NewFieldElement(1867732552988682347), NewFieldElement(8352749138289783478)},
{NewFieldElement(1772251986087179577), NewFieldElement(1151343330961505549)},
{NewFieldElement(14295941257654230218), NewFieldElement(8638985198387420860)},
{NewFieldElement(582917963870113299), NewFieldElement(13301360102508097820)},
{NewFieldElement(18438694801095657876), NewFieldElement(2953322262478232169)},
{NewFieldElement(7603887573063566422), NewFieldElement(6091524026276266924)},
{NewFieldElement(7184877376568353020), NewFieldElement(5312277526863426709)},
{NewFieldElement(4845801136589914168), NewFieldElement(1561342471733565936)},
{NewFieldElement(13089468615522535612), NewFieldElement(4057681051840817565)},
{NewFieldElement(14153633198781966944), NewFieldElement(11670642633718804558)},
{NewFieldElement(16238871251946995480), NewFieldElement(9879378414393071037)},
{NewFieldElement(407815114363153064), NewFieldElement(18417737282937069683)},
{NewFieldElement(10314092695875136843), NewFieldElement(17129917118418209854)},
{NewFieldElement(14435763837662532097), NewFieldElement(4319511190642832713)},
{NewFieldElement(11747855857520646712), NewFieldElement(7041602666708225251)},
{NewFieldElement(9175192383987399327), NewFieldElement(4409574583823547850)},
{NewFieldElement(9548913170337855226), NewFieldElement(4160834878925069440)},
{NewFieldElement(965944482423049129), NewFieldElement(14015844569022395350)},
{NewFieldElement(17244878179047663844), NewFieldElement(925516683252056953)},
{NewFieldElement(11530194255376349088), NewFieldElement(3004909091927990154)},
{NewFieldElement(5197253289126122309), NewFieldElement(4693726439926432566)},
{NewFieldElement(16039381979512237027), NewFieldElement(8603041366636528085)},
{NewFieldElement(6094270808101390314), NewFieldElement(13412584619695658458)},
{NewFieldElement(300463888721818101), NewFieldElement(1345726875223674416)},
{NewFieldElement(15941208658209056668), NewFieldElement(9615553092932888024)},
{NewFieldElement(12935711669717280950), NewFieldElement(1779981135440026594)},
{NewFieldElement(1903849940544955596), NewFieldElement(3220793888228552075)},
{NewFieldElement(17009281029954729848), NewFieldElement(12717382096012389232)},
{NewFieldElement(8308499022107883215), NewFieldElement(7238839475668369173)},
{NewFieldElement(4681909377350889716), NewFieldElement(9121889619872786537)},
{NewFieldElement(16745334188484332040), NewFieldElement(13880192213923952919)},
{NewFieldElement(8275654896887061920), NewFieldElement(5378310777055483996)},
{NewFieldElement(2877567868802486135), NewFieldElement(3737222674819658170)},
{NewFieldElement(7662876313147287437), NewFieldElement(15849146076823477077)},
{NewFieldElement(15996655521860650011), NewFieldElement(10796039480722311424)},
{NewFieldElement(3451129575094269729), NewFieldElement(9506170035703226854)},
}
var publicInputsHash = Hash{ZERO_F, ZERO_F, ZERO_F, ZERO_F}
var constantGateExpectedConstraints = []QuadraticExtension{
{NewFieldElement(417831337622144221), NewFieldElement(8294314104289740950)},
{NewFieldElement(10354476116341195774), NewFieldElement(2111251116780372139)},
}
var baseSumGateExpectedConstraints = []QuadraticExtension{
{NewFieldElement(13342375419378862774), NewFieldElement(2280369543228400622)},
{NewFieldElement(4343016273263963301), NewFieldElement(8670112296843354731)},
{NewFieldElement(16450085172304373435), NewFieldElement(9474921066378691247)},
{NewFieldElement(10825438813181866983), NewFieldElement(4721788102061048468)},
{NewFieldElement(2653358151822415377), NewFieldElement(16941658162630334598)},
{NewFieldElement(16109827603357243766), NewFieldElement(2469723755597001985)},
{NewFieldElement(16092509697995123079), NewFieldElement(15792545805376063500)},
{NewFieldElement(18220570683647205186), NewFieldElement(15344882637457318583)},
{NewFieldElement(11198665856327480684), NewFieldElement(5553903935302684834)},
{NewFieldElement(10482437897580882341), NewFieldElement(8685229612947119045)},
{NewFieldElement(4559642503814598145), NewFieldElement(10753102667902815825)},
{NewFieldElement(622804064827561260), NewFieldElement(581766069302707440)},
{NewFieldElement(18211909441470681488), NewFieldElement(9918892113105798061)},
{NewFieldElement(17690944039562025874), NewFieldElement(10477359595782407734)},
{NewFieldElement(10779840836031384949), NewFieldElement(5788395352825863117)},
{NewFieldElement(16642771945619329948), NewFieldElement(16143638493085149246)},
{NewFieldElement(4736242245615047143), NewFieldElement(8163893235093339079)},
{NewFieldElement(1094576462017674831), NewFieldElement(174501253315632830)},
{NewFieldElement(13301388104345214501), NewFieldElement(10119526634662127335)},
{NewFieldElement(8813857633984933142), NewFieldElement(3166911591676225444)},
{NewFieldElement(4484502504021732255), NewFieldElement(1409252568845542666)},
{NewFieldElement(1370941442659786223), NewFieldElement(17296588456662108571)},
{NewFieldElement(4569099382027624816), NewFieldElement(17912433869630853419)},
{NewFieldElement(14131075703244612804), NewFieldElement(3689236699393284763)},
{NewFieldElement(18110259573622113024), NewFieldElement(6304531968860732013)},
{NewFieldElement(8367598931797559807), NewFieldElement(15403657336885577186)},
{NewFieldElement(14940830541973671114), NewFieldElement(7321434648394309094)},
{NewFieldElement(4391132182759374634), NewFieldElement(5732898826353006639)},
{NewFieldElement(7456591484914201025), NewFieldElement(18109528517204812723)},
{NewFieldElement(17161771796959903109), NewFieldElement(13156261145684066101)},
{NewFieldElement(13536084388374414797), NewFieldElement(2054701847843415519)},
{NewFieldElement(14910161626746342494), NewFieldElement(16386413929249303239)},
{NewFieldElement(135663282453455528), NewFieldElement(7326002312332878726)},
}
var arithmeticGateExpectedConstraints = []QuadraticExtension{
{NewFieldElement(9603520691216808695), NewFieldElement(4690376779053831127)},
{NewFieldElement(5966866800636406163), NewFieldElement(6497324789933336132)},
{NewFieldElement(6878826495788308741), NewFieldElement(6127451825087650238)},
{NewFieldElement(6678434778566461093), NewFieldElement(4026425239249050845)},
{NewFieldElement(12356209889502117742), NewFieldElement(2848290571099391070)},
{NewFieldElement(7541992239029108782), NewFieldElement(17950940401537766942)},
{NewFieldElement(8908708207493246100), NewFieldElement(7160028060821122527)},
{NewFieldElement(409323751734912343), NewFieldElement(24526598513461753)},
{NewFieldElement(10095343333078580948), NewFieldElement(9161015237592230075)},
{NewFieldElement(11010535831715159243), NewFieldElement(15218713219737909314)},
{NewFieldElement(1130027067868936767), NewFieldElement(348988747125952834)},
{NewFieldElement(4887152687323312043), NewFieldElement(2858818833929316587)},
{NewFieldElement(2026398252660761898), NewFieldElement(14463964653784091512)},
{NewFieldElement(11677435047184556805), NewFieldElement(14702888148318045748)},
{NewFieldElement(2582432912602788354), NewFieldElement(6113339395054066192)},
{NewFieldElement(6676401481409103862), NewFieldElement(423414056716918306)},
{NewFieldElement(10348954695605340465), NewFieldElement(9794647822577644958)},
{NewFieldElement(15581055079466977733), NewFieldElement(2184227200414011915)},
{NewFieldElement(16837665759306664052), NewFieldElement(13229282844806523763)},
{NewFieldElement(15646775329525033386), NewFieldElement(7893047165846868816)},
}

Loading…
Cancel
Save