Skip to content

Commit 259be59

Browse files
committed
test: mock arithmetization and use full test vector set
1 parent 2423768 commit 259be59

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

std/evmprecompiles/256-p256verify_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,51 @@ func TestP256VerifyCircuitWithEIPVectors(t *testing.T) {
120120
}
121121
}
122122

123+
func TestP256VerifyMockedArithmetization(t *testing.T) {
124+
assert := test.NewAssert(t)
125+
data, err := os.ReadFile("test_vectors/p256verify_vectors.json")
126+
// data, err := os.ReadFile("test_vectors/p256_failing.json")
127+
128+
assert.NoError(err, "read vectors.json")
129+
130+
var vecs []vector
131+
err = json.Unmarshal(data, &vecs)
132+
assert.NoError(err, "unmarshal vectors")
133+
for _, v := range vecs {
134+
assert.Run(func(assert *test.Assert) {
135+
isValid, h, r, s, qx, qy, err := mockedArithmetization(&v)
136+
// this means that the arithmetization detected an error.
137+
// lets compare that the test case also assumed an error
138+
tcVerified := expectedBool(v.Expected)
139+
if err != nil && tcVerified {
140+
// arithmetization said test case failed, but test case indicates success
141+
assert.Fail("supposed successful verification but arithmetization failed: %v", err)
142+
}
143+
assert.Equal(isValid, tcVerified, "mismatch between arithmetization and test case")
144+
if err != nil {
145+
return
146+
}
147+
// this means that the arithmetization has filtered the input. We won't be calling the circuit
148+
// in this case.
149+
expectedRes := 0
150+
if isValid {
151+
expectedRes = 1
152+
}
153+
witness := p256verifyCircuit{
154+
MsgHash: emulated.ValueOf[emulated.P256Fr](*h),
155+
R: emulated.ValueOf[emulated.P256Fr](*r),
156+
S: emulated.ValueOf[emulated.P256Fr](*s),
157+
Qx: emulated.ValueOf[emulated.P256Fp](*qx),
158+
Qy: emulated.ValueOf[emulated.P256Fp](*qy),
159+
Expected: expectedRes,
160+
}
161+
err = test.IsSolved(&p256verifyCircuit{}, &witness, ecc.BN254.ScalarField())
162+
assert.NoError(err)
163+
164+
}, v.Name)
165+
}
166+
}
167+
123168
// --- utils
124169
type vector struct {
125170
Name string `json:"Name,omitempty"`

0 commit comments

Comments
 (0)