Skip to content

Commit f8e7de2

Browse files
committed
update P256Verify
1 parent 6d84403 commit f8e7de2

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

core/vm/contracts_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,7 @@ func BenchmarkPrecompiledP256Verify(bench *testing.B) {
412412
Expected: "0000000000000000000000000000000000000000000000000000000000000001",
413413
Name: "p256Verify",
414414
}
415-
benchmarkPrecompiled("100", t, bench)
415+
benchmarkPrecompiled("0b", t, bench)
416416
}
417417

418-
func TestPrecompiledP256Verify(t *testing.T) {
419-
testJson("p256Verify", "100", t)
420-
}
418+
func TestPrecompiledP256Verify(t *testing.T) { testJson("p256Verify", "0b", t) }

crypto/secp256r1/verifier.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,15 @@ package secp256r1
22

33
import (
44
"crypto/ecdsa"
5+
"crypto/elliptic"
56
"math/big"
67
)
78

8-
// Verify verifies the given signature (r, s) for the given hash and public key (x, y).
9-
// It returns true if the signature is valid, false otherwise.
9+
// Verify checks the given signature (r, s) for the given hash and public key (x, y).
1010
func Verify(hash []byte, r, s, x, y *big.Int) bool {
11-
// Create the public key format
12-
publicKey := newPublicKey(x, y)
13-
14-
// Check if they are invalid public key coordinates
15-
if publicKey == nil {
11+
if x == nil || y == nil || !elliptic.P256().IsOnCurve(x, y) {
1612
return false
1713
}
18-
19-
// Verify the signature with the public key,
20-
// then return true if it's valid, false otherwise
21-
return ecdsa.Verify(publicKey, hash, r, s)
14+
pk := &ecdsa.PublicKey{Curve: elliptic.P256(), X: x, Y: y}
15+
return ecdsa.Verify(pk, hash, r, s)
2216
}

params/protocol_params.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ const (
162162
Bls12381MapG1Gas uint64 = 5500 // Gas price for BLS12-381 mapping field element to G1 operation
163163
Bls12381MapG2Gas uint64 = 110000 // Gas price for BLS12-381 mapping field element to G2 operation
164164

165-
P256VerifyGas uint64 = 3450 // secp256r1 elliptic curve signature verifier gas price
165+
P256VerifyGas uint64 = 6900 // secp256r1 elliptic curve signature verifier gas price
166166

167167
// The Refund Quotient is the cap on how much of the used gas can be refunded. Before EIP-3529,
168168
// up to half the consumed gas could be refunded. Redefined as 1/5th in EIP-3529

0 commit comments

Comments
 (0)