Skip to content

Commit 7a1a549

Browse files
committed
test: include minimal number of test files
1 parent e8420b0 commit 7a1a549

12 files changed

+11908
-62
lines changed
Lines changed: 36 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package bls
22

33
import (
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

5966
func 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

6374
func 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

11790
func 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
}

prover/zkevm/prover/bls/module_msm_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ func testBlsMsm(t *testing.T, withCircuit bool, g group, path string, limits *Li
1616
if err != nil {
1717
t.Fatal(err)
1818
}
19-
if len(files) == 0 {
19+
switch len(files) {
20+
case 0:
2021
t.Fatal("no csv files found, please run `go generate` to generate the test data")
22+
case 1:
23+
t.Log("single CSV file found. For complete testing, generate all test files with `go generate`")
2124
}
2225
// we test all files found
2326
var cmp *wizard.CompiledIOP

prover/zkevm/prover/bls/module_pair_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ func testBlsPair(t *testing.T, withCircuit bool) {
2626
if err != nil {
2727
t.Fatal(err)
2828
}
29-
if len(files) == 0 {
29+
switch len(files) {
30+
case 0:
3031
t.Fatal("no csv files found, please run `go generate` to generate the test data")
32+
case 1:
33+
t.Log("single CSV file found. For complete testing, generate all test files with `go generate`")
3134
}
3235
// we test all files found
3336
var cmp *wizard.CompiledIOP

prover/zkevm/prover/bls/module_pointeval_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ func testPointEval(t *testing.T, withCircuit bool) {
2222
if err != nil {
2323
t.Fatal(err)
2424
}
25-
if len(files) == 0 {
25+
switch len(files) {
26+
case 0:
2627
t.Fatal("no csv files found, please run `go generate` to generate the test data")
28+
case 1:
29+
t.Log("single CSV file found. For complete testing, generate all test files with `go generate`")
2730
}
2831
// we test all files found
2932
var cmp *wizard.CompiledIOP

0 commit comments

Comments
 (0)