@@ -36,6 +36,7 @@ import (
3636 "github.com/CortexFoundation/CortexTheseus/crypto/blake2b"
3737 "github.com/CortexFoundation/CortexTheseus/crypto/bn256"
3838 "github.com/CortexFoundation/CortexTheseus/crypto/kzg4844"
39+ "github.com/CortexFoundation/CortexTheseus/crypto/secp256r1"
3940 "github.com/CortexFoundation/CortexTheseus/params"
4041)
4142
@@ -141,6 +142,38 @@ var PrecompiledContractsPrague = map[common.Address]PrecompiledContract{
141142
142143var PrecompiledContractsBLS = PrecompiledContractsPrague
143144
145+ var PrecompiledContractsVerkle = PrecompiledContractsBerlin
146+
147+ // PrecompiledContractsOsaka contains the set of pre-compiled Ethereum
148+ // contracts used in the Osaka release.
149+ var PrecompiledContractsOsaka = PrecompiledContracts {
150+ common .BytesToAddress ([]byte {0x01 }): & ecrecover {},
151+ common .BytesToAddress ([]byte {0x02 }): & sha256hash {},
152+ common .BytesToAddress ([]byte {0x03 }): & ripemd160hash {},
153+ common .BytesToAddress ([]byte {0x04 }): & dataCopy {},
154+ common .BytesToAddress ([]byte {0x05 }): & bigModExp {eip2565 : true , eip7823 : true , eip7883 : true },
155+ common .BytesToAddress ([]byte {0x06 }): & bn256AddIstanbul {},
156+ common .BytesToAddress ([]byte {0x07 }): & bn256ScalarMulIstanbul {},
157+ common .BytesToAddress ([]byte {0x08 }): & bn256PairingIstanbul {},
158+ common .BytesToAddress ([]byte {0x09 }): & blake2F {},
159+ common .BytesToAddress ([]byte {0x0a }): & kzgPointEvaluation {},
160+ common .BytesToAddress ([]byte {0x0b }): & bls12381G1Add {},
161+ common .BytesToAddress ([]byte {0x0c }): & bls12381G1MultiExp {},
162+ common .BytesToAddress ([]byte {0x0d }): & bls12381G2Add {},
163+ common .BytesToAddress ([]byte {0x0e }): & bls12381G2MultiExp {},
164+ common .BytesToAddress ([]byte {0x0f }): & bls12381Pairing {},
165+ common .BytesToAddress ([]byte {0x10 }): & bls12381MapG1 {},
166+ common .BytesToAddress ([]byte {0x11 }): & bls12381MapG2 {},
167+
168+ common .BytesToAddress ([]byte {0x1 , 0x00 }): & p256Verify {},
169+ }
170+
171+ // PrecompiledContractsP256Verify contains the precompiled Ethereum
172+ // contract specified in EIP-7212. This is exported for testing purposes.
173+ var PrecompiledContractsP256Verify = PrecompiledContracts {
174+ common .BytesToAddress ([]byte {0x1 , 0x00 }): & p256Verify {},
175+ }
176+
144177var (
145178 PrecompiledAddressesPrague []common.Address
146179 PrecompiledAddressesCancun []common.Address
@@ -293,6 +326,8 @@ func (c *dataCopy) Run(in []byte) ([]byte, error) {
293326// bigModExp implements a native big integer exponential modular operation.
294327type bigModExp struct {
295328 eip2565 bool
329+ eip7823 bool
330+ eip7883 bool
296331}
297332
298333var (
@@ -1151,3 +1186,31 @@ func kZGToVersionedHash(kzg kzg4844.Commitment) common.Hash {
11511186
11521187 return h
11531188}
1189+
1190+ // P256VERIFY (secp256r1 signature verification)
1191+ // implemented as a native contract
1192+ type p256Verify struct {}
1193+
1194+ // RequiredGas returns the gas required to execute the precompiled contract
1195+ func (c * p256Verify ) RequiredGas (input []byte ) uint64 {
1196+ return params .P256VerifyGas
1197+ }
1198+
1199+ // Run executes the precompiled contract with given 160 bytes of param, returning the output and the used gas
1200+ func (c * p256Verify ) Run (input []byte ) ([]byte , error ) {
1201+ const p256VerifyInputLength = 160
1202+ if len (input ) != p256VerifyInputLength {
1203+ return nil , nil
1204+ }
1205+
1206+ // Extract hash, r, s, x, y from the input.
1207+ hash := input [0 :32 ]
1208+ r , s := new (big.Int ).SetBytes (input [32 :64 ]), new (big.Int ).SetBytes (input [64 :96 ])
1209+ x , y := new (big.Int ).SetBytes (input [96 :128 ]), new (big.Int ).SetBytes (input [128 :160 ])
1210+
1211+ // Verify the signature.
1212+ if secp256r1 .Verify (hash , r , s , x , y ) {
1213+ return true32Byte , nil
1214+ }
1215+ return nil , nil
1216+ }
0 commit comments