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