@@ -30,6 +30,7 @@ import (
3030 "github.com/ava-labs/libevm/crypto/bls12381"
3131 "github.com/ava-labs/libevm/crypto/bn256"
3232 "github.com/ava-labs/libevm/crypto/kzg4844"
33+ "github.com/ava-labs/libevm/crypto/secp256r1"
3334 "github.com/ava-labs/libevm/params"
3435 "golang.org/x/crypto/ripemd160"
3536)
@@ -121,6 +122,12 @@ var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{
121122 common .BytesToAddress ([]byte {18 }): & bls12381MapG2 {},
122123}
123124
125+ // PrecompiledContractsP256Verify contains the precompiled Ethereum
126+ // contract specified in EIP-7212. This is exported for testing purposes.
127+ var PrecompiledContractsP256Verify = map [common.Address ]PrecompiledContract {
128+ common .BytesToAddress ([]byte {0x1 , 0x00 }): & p256Verify {},
129+ }
130+
124131var (
125132 PrecompiledAddressesCancun []common.Address
126133 PrecompiledAddressesBerlin []common.Address
@@ -1135,3 +1142,31 @@ func kZGToVersionedHash(kzg kzg4844.Commitment) common.Hash {
11351142
11361143 return h
11371144}
1145+
1146+ // P256VERIFY (secp256r1 signature verification)
1147+ // implemented as a native contract
1148+ type p256Verify struct {}
1149+
1150+ // RequiredGas returns the gas required to execute the precompiled contract
1151+ func (c * p256Verify ) RequiredGas (input []byte ) uint64 {
1152+ return params .P256VerifyGas
1153+ }
1154+
1155+ // Run executes the precompiled contract with given 160 bytes of param, returning the output and the used gas
1156+ func (c * p256Verify ) Run (input []byte ) ([]byte , error ) {
1157+ const p256VerifyInputLength = 160
1158+ if len (input ) != p256VerifyInputLength {
1159+ return nil , nil
1160+ }
1161+
1162+ // Extract hash, r, s, x, y from the input.
1163+ hash := input [0 :32 ]
1164+ r , s := new (big.Int ).SetBytes (input [32 :64 ]), new (big.Int ).SetBytes (input [64 :96 ])
1165+ x , y := new (big.Int ).SetBytes (input [96 :128 ]), new (big.Int ).SetBytes (input [128 :160 ])
1166+
1167+ // Verify the signature.
1168+ if secp256r1 .Verify (hash , r , s , x , y ) {
1169+ return true32Byte , nil
1170+ }
1171+ return nil , nil
1172+ }
0 commit comments