Skip to content

Commit cc9e427

Browse files
Merge remote-tracking branch 'origin' into HEAD
2 parents 64ea2d1 + 41e40f1 commit cc9e427

File tree

12 files changed

+5594
-4
lines changed

12 files changed

+5594
-4
lines changed

accounts/abi/abi_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,8 +1087,7 @@ func TestABI_ErrorByID(t *testing.T) {
10871087
}
10881088
for name, m := range abi.Errors {
10891089
a := fmt.Sprintf("%v", &m)
1090-
var id [4]byte
1091-
copy(id[:], m.ID[:4])
1090+
id := [4]byte(m.ID.Bytes())
10921091
m2, err := abi.ErrorByID(id)
10931092
if err != nil {
10941093
t.Fatalf("Failed to look up ABI error: %v", err)

core/vm/contracts.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/ethereum/go-ethereum/crypto/bls12381"
3131
"github.com/ethereum/go-ethereum/crypto/bn256"
3232
"github.com/ethereum/go-ethereum/crypto/kzg4844"
33+
"github.com/ethereum/go-ethereum/crypto/secp256r1"
3334
"github.com/ethereum/go-ethereum/params"
3435
"golang.org/x/crypto/ripemd160"
3536
)
@@ -107,6 +108,12 @@ var PrecompiledContractsCancun = map[common.Address]PrecompiledContract{
107108
common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{},
108109
}
109110

111+
// PrecompiledContractsP256Verify contains the precompiled Ethereum
112+
// contract specified in EIP-7212.
113+
var PrecompiledContractsP256Verify = map[common.Address]PrecompiledContract{
114+
common.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{},
115+
}
116+
110117
// PrecompiledContractsBLS contains the set of pre-compiled Ethereum
111118
// contracts specified in EIP-2537. These are exported for testing purposes.
112119
var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{
@@ -151,6 +158,9 @@ func init() {
151158
func ActivePrecompiles(rules params.Rules) []common.Address {
152159
switch {
153160
case rules.IsArbitrum:
161+
if rules.ArbOSVersion >= 30 {
162+
return PrecompiledAddressesArbOS30
163+
}
154164
return PrecompiledAddressesArbitrum
155165
case rules.IsCancun:
156166
return PrecompiledAddressesCancun
@@ -1155,3 +1165,36 @@ func kZGToVersionedHash(kzg kzg4844.Commitment) common.Hash {
11551165

11561166
return h
11571167
}
1168+
1169+
// P256VERIFY (secp256r1 signature verification)
1170+
// implemented as a native contract.
1171+
type p256Verify struct{}
1172+
1173+
// RequiredGas returns the gas required to execute the precompiled contract.
1174+
func (c *p256Verify) RequiredGas(input []byte) uint64 {
1175+
return params.P256VerifyGas
1176+
}
1177+
1178+
// Run executes the precompiled contract with given 160 bytes of param, returning the output and the used gas.
1179+
func (c *p256Verify) Run(input []byte) ([]byte, error) {
1180+
// Required input length is 160 bytes.
1181+
const p256VerifyInputLength = 160
1182+
// Check the input length.
1183+
if len(input) != p256VerifyInputLength {
1184+
// Input length is invalid.
1185+
return nil, nil
1186+
}
1187+
1188+
// Extract the hash, r, s, x, y from the input.
1189+
hash := input[0:32]
1190+
r, s := new(big.Int).SetBytes(input[32:64]), new(big.Int).SetBytes(input[64:96])
1191+
x, y := new(big.Int).SetBytes(input[96:128]), new(big.Int).SetBytes(input[128:160])
1192+
1193+
// Verify the secp256r1 signature.
1194+
if secp256r1.Verify(hash, r, s, x, y) {
1195+
// Signature is valid
1196+
return common.LeftPadBytes(common.Big1.Bytes(), 32), nil
1197+
}
1198+
// Signature is invalid.
1199+
return nil, nil
1200+
}

core/vm/contracts_arbitrum.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ import "github.com/ethereum/go-ethereum/common"
55
var (
66
PrecompiledContractsArbitrum = make(map[common.Address]PrecompiledContract)
77
PrecompiledAddressesArbitrum []common.Address
8+
PrecompiledContractsArbOS30 = make(map[common.Address]PrecompiledContract)
9+
PrecompiledAddressesArbOS30 []common.Address
810
)

core/vm/contracts_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ var allPrecompiles = map[common.Address]PrecompiledContract{
5858
common.BytesToAddress([]byte{9}): &blake2F{},
5959
common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{},
6060

61+
common.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{},
62+
6163
common.BytesToAddress([]byte{0x0f, 0x0a}): &bls12381G1Add{},
6264
common.BytesToAddress([]byte{0x0f, 0x0b}): &bls12381G1Mul{},
6365
common.BytesToAddress([]byte{0x0f, 0x0c}): &bls12381G1MultiExp{},
@@ -395,3 +397,15 @@ func BenchmarkPrecompiledBLS12381G2MultiExpWorstCase(b *testing.B) {
395397
}
396398
benchmarkPrecompiled("0f", testcase, b)
397399
}
400+
401+
// Benchmarks the sample inputs from the P256VERIFY precompile.
402+
func BenchmarkPrecompiledP256Verify(bench *testing.B) {
403+
t := precompiledTest{
404+
Input: "4cee90eb86eaa050036147a12d49004b6b9c72bd725d39d4785011fe190f0b4da73bd4903f0ce3b639bbbf6e8e80d16931ff4bcf5993d58468e8fb19086e8cac36dbcd03009df8c59286b162af3bd7fcc0450c9aa81be5d10d312af6c66b1d604aebd3099c618202fcfe16ae7770b0c49ab5eadf74b754204a3bb6060e44eff37618b065f9832de4ca6ca971a7a1adc826d0f7c00181a5fb2ddf79ae00b4e10e",
405+
Expected: "0000000000000000000000000000000000000000000000000000000000000001",
406+
Name: "p256Verify",
407+
}
408+
benchmarkPrecompiled("100", t, bench)
409+
}
410+
411+
func TestPrecompiledP256Verify(t *testing.T) { testJson("p256Verify", "100", t) }

core/vm/evm.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) {
4242
var precompiles map[common.Address]PrecompiledContract
4343
switch {
4444
case evm.chainRules.IsArbitrum:
45+
if evm.chainRules.ArbOSVersion >= 30 {
46+
precompiles = PrecompiledContractsArbOS30
47+
break
48+
}
4549
precompiles = PrecompiledContractsArbitrum
4650
case evm.chainRules.IsCancun:
4751
precompiles = PrecompiledContractsCancun

0 commit comments

Comments
 (0)