Skip to content

Commit

Permalink
Merge pull request #176 from testinprod-io/pcw109550/fjord/secp256r1
Browse files Browse the repository at this point in the history
[Fjord] Secp256r1 curve support (RIP-7212)
  • Loading branch information
pcw109550 authored May 27, 2024
2 parents 2a13415 + 9efedb9 commit 1e5297e
Show file tree
Hide file tree
Showing 5 changed files with 5,499 additions and 1 deletion.
22 changes: 22 additions & 0 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ var PrecompiledContractsCancun = map[libcommon.Address]PrecompiledContract{
libcommon.BytesToAddress([]byte{0x0a}): &pointEvaluation{},
}

// PrecompiledContractsFjord contains the default set of pre-compiled Ethereum
// contracts used in the Fjord release.
var PrecompiledContractsFjord = map[libcommon.Address]PrecompiledContract{
libcommon.BytesToAddress([]byte{1}): &ecrecover{},
libcommon.BytesToAddress([]byte{2}): &sha256hash{},
libcommon.BytesToAddress([]byte{3}): &ripemd160hash{},
libcommon.BytesToAddress([]byte{4}): &dataCopy{},
libcommon.BytesToAddress([]byte{5}): &bigModExp{eip2565: true},
libcommon.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
libcommon.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
libcommon.BytesToAddress([]byte{8}): &bn256PairingIstanbul{},
libcommon.BytesToAddress([]byte{9}): &blake2F{},
libcommon.BytesToAddress([]byte{0x0a}): &pointEvaluation{},
libcommon.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{},
}

var PrecompiledContractsNapoli = map[libcommon.Address]PrecompiledContract{
libcommon.BytesToAddress([]byte{0x01}): &ecrecover{},
libcommon.BytesToAddress([]byte{0x02}): &sha256hash{},
Expand Down Expand Up @@ -151,6 +167,7 @@ var PrecompiledContractsPrague = map[libcommon.Address]PrecompiledContract{
}

var (
PrecompiledAddressesFjord []libcommon.Address
PrecompiledAddressesPrague []libcommon.Address
PrecompiledAddressesNapoli []libcommon.Address
PrecompiledAddressesCancun []libcommon.Address
Expand All @@ -176,6 +193,9 @@ func init() {
for k := range PrecompiledContractsCancun {
PrecompiledAddressesCancun = append(PrecompiledAddressesCancun, k)
}
for k := range PrecompiledContractsFjord {
PrecompiledAddressesFjord = append(PrecompiledAddressesFjord, k)
}
for k := range PrecompiledContractsNapoli {
PrecompiledAddressesNapoli = append(PrecompiledAddressesNapoli, k)
}
Expand All @@ -187,6 +207,8 @@ func init() {
// ActivePrecompiles returns the precompiles enabled with the current configuration.
func ActivePrecompiles(rules *chain.Rules) []libcommon.Address {
switch {
case rules.IsOptimismFjord:
return PrecompiledAddressesFjord
case rules.IsPrague:
return PrecompiledAddressesPrague
case rules.IsNapoli:
Expand Down
3 changes: 3 additions & 0 deletions core/vm/contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,5 +415,8 @@ func BenchmarkPrecompiledP256Verify(b *testing.B) {
func TestPrecompiledP256Verify(t *testing.T) {
t.Parallel()

// test case from Polygon Napoli erigon
testJson("p256Verify", "100", t)
// test case from OP Stack Fjord geth
testJson("p256Verify2", "100", t)
}
2 changes: 2 additions & 0 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var emptyCodeHash = crypto.Keccak256Hash(nil)
func (evm *EVM) precompile(addr libcommon.Address) (PrecompiledContract, bool) {
var precompiles map[libcommon.Address]PrecompiledContract
switch {
case evm.chainRules.IsOptimismFjord:
precompiles = PrecompiledContractsFjord
case evm.chainRules.IsPrague:
precompiles = PrecompiledContractsPrague
case evm.chainRules.IsNapoli:
Expand Down
Loading

0 comments on commit 1e5297e

Please sign in to comment.