Skip to content

Commit cd568a4

Browse files
committed
test: renamings + changed hash fails verification
1 parent 7e5fd4d commit cd568a4

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

libevm/precompiles/p256verify/p256verify_test.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"crypto/ecdsa"
2121
"crypto/elliptic"
2222
"crypto/rand"
23+
"slices"
2324
"testing"
2425

2526
"github.com/holiman/uint256"
@@ -51,22 +52,22 @@ func TestPrecompile(t *testing.T) {
5152

5253
tests := []testCase{
5354
{
54-
name: "empty input",
55+
name: "empty_input",
5556
},
5657
{
57-
name: "input too short",
58+
name: "input_too_short",
5859
in: make([]byte, inputLen-1),
5960
},
6061
{
61-
name: "input too long",
62+
name: "input_too_long",
6263
in: make([]byte, inputLen+1),
6364
},
6465
{
65-
name: "pub key at infinity",
66+
name: "pub_key_at_infinity",
6667
in: make([]byte, inputLen),
6768
},
6869
{
69-
name: "pub key not on curve",
70+
name: "pub_key_not_on_curve",
7071
in: []byte{inputLen - 1: 1},
7172
},
7273
{
@@ -81,17 +82,23 @@ func TestPrecompile(t *testing.T) {
8182
require.NoError(t, err, "ecdsa.GenerateKey(elliptic.P256(), crypto/rand.Reader)")
8283

8384
for range 50 {
84-
var hash [32]byte
85-
_, err := rand.Read(hash[:])
86-
require.NoErrorf(t, err, "crypto/rand.Read(%T)", hash)
85+
var toSign [32]byte
86+
_, err := rand.Read(toSign[:])
87+
require.NoErrorf(t, err, "crypto/rand.Read(%T)", toSign)
8788

88-
in, err := Sign(priv, hash)
89-
require.NoErrorf(t, err, "Sign([P256 key], %#x)", hash)
89+
in, err := Sign(priv, toSign)
90+
require.NoErrorf(t, err, "Sign([P256 key], %#x)", toSign)
9091
tests = append(tests, testCase{
91-
name: "fuzz",
92+
name: "fuzz_valid",
9293
in: in,
9394
wantSuccess: true,
9495
})
96+
corrupt := slices.Clone(in)
97+
corrupt[0]++ // different signed hash
98+
tests = append(tests, testCase{
99+
name: "fuzz_invalid",
100+
in: corrupt,
101+
})
95102
}
96103
}
97104

0 commit comments

Comments
 (0)