11package bls
22
33import (
4+ "errors"
45 "os"
56 "testing"
67
@@ -10,33 +11,39 @@ import (
1011 "github.com/consensys/linea-monorepo/prover/utils/csvtraces"
1112)
1213
13- func testBlsG1Map (t * testing.T , withCircuit bool ) {
14- limits := & Limits {
15- NbG1MapToInputInstances : 16 ,
16- NbG1MapToCircuitInstances : 1 ,
14+ func testBlsMap (t * testing.T , withCircuit bool , g group , path string , limits * Limits ) {
15+ f , err := os . Open ( path )
16+ if errors . Is ( err , os . ErrNotExist ) {
17+ t . Fatal ( "csv file does not exist, please run `go generate` to generate the test data" )
1718 }
18- f , err := os .Open ("testdata/bls_g1_map_inputs.csv" )
1919 if err != nil {
20- t .Fatal (err )
20+ t .Fatal ("failed to open csv file" , err )
2121 }
2222 defer f .Close ()
2323 ct , err := csvtraces .NewCsvTrace (f )
2424 if err != nil {
2525 t .Fatal ("failed to create csv trace" , err )
2626 }
27+ var mapString string
28+ if g == G1 {
29+ mapString = "MAP_FP_TO_G1"
30+ } else {
31+ mapString = "MAP_FP2_TO_G2"
32+ }
2733 var blsMap * BlsMap
34+ var blsMapSource * blsMapDataSource
2835 cmp := wizard .Compile (
2936 func (b * wizard.Builder ) {
30- blsMapSource : = & blsMapDataSource {
37+ blsMapSource = & blsMapDataSource {
3138 ID : ct .GetCommit (b , "ID" ),
32- CsMap : ct .GetCommit (b , "CIRCUIT_SELECTOR_MAP_FP_TO_G1" ),
39+ CsMap : ct .GetCommit (b , "CIRCUIT_SELECTOR_" + mapString ),
3340 Index : ct .GetCommit (b , "INDEX" ),
3441 Counter : ct .GetCommit (b , "CT" ),
3542 Limb : ct .GetCommit (b , "LIMB" ),
36- IsData : ct .GetCommit (b , "DATA_MAP_FP_TO_G1" ),
37- IsRes : ct .GetCommit (b , "RSLT_MAP_FP_TO_G1" ),
43+ IsData : ct .GetCommit (b , "DATA_" + mapString ),
44+ IsRes : ct .GetCommit (b , "RSLT_" + mapString ),
3845 }
39- blsMap = newMap (b .CompiledIOP , G1 , limits , blsMapSource )
46+ blsMap = newMap (b .CompiledIOP , g , limits , blsMapSource )
4047 if withCircuit {
4148 blsMap = blsMap .WithMapCircuit (b .CompiledIOP , query .PlonkRangeCheckOption (16 , 6 , true ))
4249 }
@@ -46,7 +53,7 @@ func testBlsG1Map(t *testing.T, withCircuit bool) {
4653
4754 proof := wizard .Prove (cmp ,
4855 func (run * wizard.ProverRuntime ) {
49- ct .Assign (run , "ID" , "CIRCUIT_SELECTOR_MAP_FP_TO_G1" , "INDEX" , "CT" , "LIMB" , "DATA_MAP_FP_TO_G1" , "RSLT_MAP_FP_TO_G1" )
56+ ct .Assign (run , "ID" , "CIRCUIT_SELECTOR_" + mapString , "INDEX" , "CT" , "LIMB" , "DATA_" + mapString , "RSLT_" + mapString )
5057 blsMap .Assign (run )
5158 })
5259
@@ -57,63 +64,33 @@ func testBlsG1Map(t *testing.T, withCircuit bool) {
5764}
5865
5966func TestBlsMapG1NoCircuit (t * testing.T ) {
60- testBlsG1Map (t , false )
67+ limits := & Limits {
68+ NbG1MapToInputInstances : 16 ,
69+ NbG1MapToCircuitInstances : 1 ,
70+ }
71+ testBlsMap (t , false , G1 , "testdata/bls_g1_map_inputs.csv" , limits )
6172}
6273
6374func TestBlsMapG1WithCircuit (t * testing.T ) {
64- testBlsG1Map (t , true )
75+ limits := & Limits {
76+ NbG1MapToInputInstances : 16 ,
77+ NbG1MapToCircuitInstances : 1 ,
78+ }
79+ testBlsMap (t , true , G1 , "testdata/bls_g1_map_inputs.csv" , limits )
6580}
6681
67- func testBlsG2Map (t * testing.T , withCircuit bool ) {
82+ func TestBlsMapG2NoCircuit (t * testing.T ) {
6883 limits := & Limits {
6984 NbG2MapToInputInstances : 4 ,
7085 NbG2MapToCircuitInstances : 1 ,
7186 }
72- f , err := os .Open ("testdata/bls_g2_map_inputs.csv" )
73- if err != nil {
74- t .Fatal (err )
75- }
76- defer f .Close ()
77- ct , err := csvtraces .NewCsvTrace (f )
78- if err != nil {
79- t .Fatal ("failed to create csv trace" , err )
80- }
81- var blsMap * BlsMap
82- cmp := wizard .Compile (
83- func (b * wizard.Builder ) {
84- blsMapSource := & blsMapDataSource {
85- ID : ct .GetCommit (b , "ID" ),
86- CsMap : ct .GetCommit (b , "CIRCUIT_SELECTOR_MAP_FP2_TO_G2" ),
87- Index : ct .GetCommit (b , "INDEX" ),
88- Counter : ct .GetCommit (b , "CT" ),
89- Limb : ct .GetCommit (b , "LIMB" ),
90- IsData : ct .GetCommit (b , "DATA_MAP_FP2_TO_G2" ),
91- IsRes : ct .GetCommit (b , "RSLT_MAP_FP2_TO_G2" ),
92- }
93- blsMap = newMap (b .CompiledIOP , G2 , limits , blsMapSource )
94- if withCircuit {
95- blsMap = blsMap .WithMapCircuit (b .CompiledIOP , query .PlonkRangeCheckOption (16 , 6 , true ))
96- }
97- },
98- dummy .Compile ,
99- )
100-
101- proof := wizard .Prove (cmp ,
102- func (run * wizard.ProverRuntime ) {
103- ct .Assign (run , "ID" , "CIRCUIT_SELECTOR_MAP_FP2_TO_G2" , "INDEX" , "CT" , "LIMB" , "DATA_MAP_FP2_TO_G2" , "RSLT_MAP_FP2_TO_G2" )
104- blsMap .Assign (run )
105- })
106-
107- if err := wizard .Verify (cmp , proof ); err != nil {
108- t .Fatal ("proof failed" , err )
109- }
110- t .Log ("proof succeeded" )
111- }
112-
113- func TestBlsMapG2NoCircuit (t * testing.T ) {
114- testBlsG2Map (t , false )
87+ testBlsMap (t , false , G2 , "testdata/bls_g2_map_inputs.csv" , limits )
11588}
11689
11790func TestBlsMapG2WithCircuit (t * testing.T ) {
118- testBlsG2Map (t , true )
91+ limits := & Limits {
92+ NbG2MapToInputInstances : 4 ,
93+ NbG2MapToCircuitInstances : 1 ,
94+ }
95+ testBlsMap (t , true , G2 , "testdata/bls_g2_map_inputs.csv" , limits )
11996}
0 commit comments