Skip to content

Commit

Permalink
test: add test case for unsatisfiable circuit if v∈{2,3}
Browse files Browse the repository at this point in the history
  • Loading branch information
ivokub committed Oct 8, 2024
1 parent a7db0fd commit 57d378c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions std/evmprecompiles/01-ecrecover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package evmprecompiles

import (
"crypto/rand"
"errors"
"fmt"
"math/big"
"testing"
Expand Down Expand Up @@ -260,3 +261,40 @@ func TestInvalidFailureTag(t *testing.T) {
err := test.IsSolved(circuit, witness, ecc.BN254.ScalarField())
assert.Error(err)
}

func TestLargeV(t *testing.T) {
assert := test.NewAssert(t)
var pk ecdsa.PublicKey
msg := []byte("test")
var rE, sE fr.Element
r, s := new(big.Int), new(big.Int)
for _, v := range []uint{2, 3} {
for {
rE.SetRandom()
sE.SetRandom()
rE.BigInt(r)
sE.BigInt(s)
if err := pk.RecoverFrom(msg, v, r, s); errors.Is(err, ecdsa.ErrNoSqrtR) {
continue
} else {
assert.NoError(err)
break
}
}
circuit := ecrecoverCircuit{}
witness := ecrecoverCircuit{
Message: emulated.ValueOf[emulated.Secp256k1Fr](ecdsa.HashToInt(msg)),
V: v + 27, // EVM constant
R: emulated.ValueOf[emulated.Secp256k1Fr](r),
S: emulated.ValueOf[emulated.Secp256k1Fr](s),
Strict: 0,
IsFailure: 0,
Expected: sw_emulated.AffinePoint[emulated.Secp256k1Fp]{
X: emulated.ValueOf[emulated.Secp256k1Fp](pk.A.X),
Y: emulated.ValueOf[emulated.Secp256k1Fp](pk.A.Y),
},
}
err := test.IsSolved(&circuit, &witness, ecc.BLS12_377.ScalarField())
assert.Error(err)
}
}

0 comments on commit 57d378c

Please sign in to comment.