@@ -35,6 +35,7 @@ import (
35
35
"github.com/ethereum/go-ethereum/crypto/blake2b"
36
36
"github.com/ethereum/go-ethereum/crypto/bn256"
37
37
"github.com/ethereum/go-ethereum/crypto/kzg4844"
38
+ "github.com/ethereum/go-ethereum/crypto/secp256r1"
38
39
"github.com/ethereum/go-ethereum/params"
39
40
"golang.org/x/crypto/ripemd160"
40
41
)
@@ -161,6 +162,14 @@ var PrecompiledContractsOsaka = PrecompiledContracts{
161
162
common .BytesToAddress ([]byte {0x0f }): & bls12381Pairing {},
162
163
common .BytesToAddress ([]byte {0x10 }): & bls12381MapG1 {},
163
164
common .BytesToAddress ([]byte {0x11 }): & bls12381MapG2 {},
165
+
166
+ common .BytesToAddress ([]byte {0x1 , 0x00 }): & p256Verify {},
167
+ }
168
+
169
+ // PrecompiledContractsP256Verify contains the precompiled Ethereum
170
+ // contract specified in EIP-7212. This is exported for testing purposes.
171
+ var PrecompiledContractsP256Verify = PrecompiledContracts {
172
+ common .BytesToAddress ([]byte {0x1 , 0x00 }): & p256Verify {},
164
173
}
165
174
166
175
var (
@@ -1232,3 +1241,31 @@ func kZGToVersionedHash(kzg kzg4844.Commitment) common.Hash {
1232
1241
1233
1242
return h
1234
1243
}
1244
+
1245
+ // P256VERIFY (secp256r1 signature verification)
1246
+ // implemented as a native contract
1247
+ type p256Verify struct {}
1248
+
1249
+ // RequiredGas returns the gas required to execute the precompiled contract
1250
+ func (c * p256Verify ) RequiredGas (input []byte ) uint64 {
1251
+ return params .P256VerifyGas
1252
+ }
1253
+
1254
+ // Run executes the precompiled contract with given 160 bytes of param, returning the output and the used gas
1255
+ func (c * p256Verify ) Run (input []byte ) ([]byte , error ) {
1256
+ const p256VerifyInputLength = 160
1257
+ if len (input ) != p256VerifyInputLength {
1258
+ return nil , nil
1259
+ }
1260
+
1261
+ // Extract hash, r, s, x, y from the input.
1262
+ hash := input [0 :32 ]
1263
+ r , s := new (big.Int ).SetBytes (input [32 :64 ]), new (big.Int ).SetBytes (input [64 :96 ])
1264
+ x , y := new (big.Int ).SetBytes (input [96 :128 ]), new (big.Int ).SetBytes (input [128 :160 ])
1265
+
1266
+ // Verify the signature.
1267
+ if secp256r1 .Verify (hash , r , s , x , y ) {
1268
+ return true32Byte , nil
1269
+ }
1270
+ return nil , nil
1271
+ }
0 commit comments