@@ -20,6 +20,7 @@ import (
2020 "crypto/sha256"
2121 "encoding/binary"
2222 "errors"
23+ "maps"
2324 "math"
2425 "math/big"
2526
@@ -41,9 +42,12 @@ type PrecompiledContract interface {
4142 Run (input []byte ) ([]byte , error ) // Run runs the precompiled contract
4243}
4344
45+ // PrecompiledContracts contains the precompiled contracts supported at the given fork.
46+ type PrecompiledContracts map [common.Address ]PrecompiledContract
47+
4448// PrecompiledContractsHomestead contains the default set of pre-compiled Ethereum
4549// contracts used in the Frontier and Homestead releases.
46- var PrecompiledContractsHomestead = map [common. Address ] PrecompiledContract {
50+ var PrecompiledContractsHomestead = PrecompiledContracts {
4751 common .BytesToAddress ([]byte {1 }): & ecrecover {},
4852 common .BytesToAddress ([]byte {2 }): & sha256hash {},
4953 common .BytesToAddress ([]byte {3 }): & ripemd160hash {},
@@ -52,7 +56,7 @@ var PrecompiledContractsHomestead = map[common.Address]PrecompiledContract{
5256
5357// PrecompiledContractsByzantium contains the default set of pre-compiled Ethereum
5458// contracts used in the Byzantium release.
55- var PrecompiledContractsByzantium = map [common. Address ] PrecompiledContract {
59+ var PrecompiledContractsByzantium = PrecompiledContracts {
5660 common .BytesToAddress ([]byte {1 }): & ecrecover {},
5761 common .BytesToAddress ([]byte {2 }): & sha256hash {},
5862 common .BytesToAddress ([]byte {3 }): & ripemd160hash {},
@@ -69,7 +73,7 @@ var PrecompiledContractsByzantium = map[common.Address]PrecompiledContract{
6973
7074// PrecompiledContractsIstanbul contains the default set of pre-compiled Ethereum
7175// contracts used in the Istanbul release.
72- var PrecompiledContractsIstanbul = map [common. Address ] PrecompiledContract {
76+ var PrecompiledContractsIstanbul = PrecompiledContracts {
7377 common .BytesToAddress ([]byte {1 }): & ecrecover {},
7478 common .BytesToAddress ([]byte {2 }): & sha256hash {},
7579 common .BytesToAddress ([]byte {3 }): & ripemd160hash {},
@@ -85,7 +89,7 @@ var PrecompiledContractsIstanbul = map[common.Address]PrecompiledContract{
8589 common .BytesToAddress ([]byte {42 }): & XDCxEpochPrice {},
8690}
8791
88- var PrecompiledContractsXDCv2 = map [common. Address ] PrecompiledContract {
92+ var PrecompiledContractsXDCv2 = PrecompiledContracts {
8993 common .BytesToAddress ([]byte {1 }): & ecrecover {},
9094 common .BytesToAddress ([]byte {2 }): & sha256hash {},
9195 common .BytesToAddress ([]byte {3 }): & ripemd160hash {},
@@ -97,7 +101,7 @@ var PrecompiledContractsXDCv2 = map[common.Address]PrecompiledContract{
97101 common .BytesToAddress ([]byte {9 }): & blake2F {},
98102}
99103
100- var PrecompiledContractsEIP1559 = map [common. Address ] PrecompiledContract {
104+ var PrecompiledContractsEIP1559 = PrecompiledContracts {
101105 common .BytesToAddress ([]byte {1 }): & ecrecover {},
102106 common .BytesToAddress ([]byte {2 }): & sha256hash {},
103107 common .BytesToAddress ([]byte {3 }): & ripemd160hash {},
@@ -135,7 +139,27 @@ func init() {
135139 }
136140}
137141
138- // ActivePrecompiles returns the precompiles enabled with the current configuration.
142+ func activePrecompiledContracts (rules params.Rules ) PrecompiledContracts {
143+ switch {
144+ case rules .IsEIP1559 :
145+ return PrecompiledContractsEIP1559
146+ case rules .IsXDCxDisable :
147+ return PrecompiledContractsXDCv2
148+ case rules .IsIstanbul :
149+ return PrecompiledContractsIstanbul
150+ case rules .IsByzantium :
151+ return PrecompiledContractsByzantium
152+ default :
153+ return PrecompiledContractsHomestead
154+ }
155+ }
156+
157+ // ActivePrecompiledContracts returns a copy of precompiled contracts enabled with the current configuration.
158+ func ActivePrecompiledContracts (rules params.Rules ) PrecompiledContracts {
159+ return maps .Clone (activePrecompiledContracts (rules ))
160+ }
161+
162+ // ActivePrecompiles returns the precompile addresses enabled with the current configuration.
139163func ActivePrecompiles (rules params.Rules ) []common.Address {
140164 switch {
141165 case rules .IsEIP1559 :
0 commit comments