@@ -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
)
@@ -1135,3 +1136,31 @@ func kZGToVersionedHash(kzg kzg4844.Commitment) common.Hash {
1135
1136
1136
1137
return h
1137
1138
}
1139
+
1140
+ // P256VERIFY (secp256r1 signature verification)
1141
+ // implemented as a native contract
1142
+ type p256Verify struct {}
1143
+
1144
+ // RequiredGas returns the gas required to execute the precompiled contract
1145
+ func (c * p256Verify ) RequiredGas (input []byte ) uint64 {
1146
+ return params .P256VerifyGas
1147
+ }
1148
+
1149
+ // Run executes the precompiled contract with given 160 bytes of param, returning the output and the used gas
1150
+ func (c * p256Verify ) Run (input []byte ) ([]byte , error ) {
1151
+ const p256VerifyInputLength = 160
1152
+ if len (input ) != p256VerifyInputLength {
1153
+ return nil , nil
1154
+ }
1155
+
1156
+ // Extract hash, r, s, x, y from the input.
1157
+ hash := input [0 :32 ]
1158
+ r , s := new (big.Int ).SetBytes (input [32 :64 ]), new (big.Int ).SetBytes (input [64 :96 ])
1159
+ x , y := new (big.Int ).SetBytes (input [96 :128 ]), new (big.Int ).SetBytes (input [128 :160 ])
1160
+
1161
+ // Verify the signature.
1162
+ if secp256r1 .Verify (hash , r , s , x , y ) {
1163
+ return true32Byte , nil
1164
+ }
1165
+ return nil , nil
1166
+ }
0 commit comments