Skip to content

Commit 566ab38

Browse files
committed
feat(forks): use ethereum_test_addresses
1 parent 3bc17be commit 566ab38

File tree

1 file changed

+38
-27
lines changed

1 file changed

+38
-27
lines changed

src/ethereum_test_forks/forks/forks.py

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from semver import Version
1111

12+
from ethereum_test_addresses import Precompile, SystemContract
1213
from ethereum_test_base_types import Address
1314
from ethereum_test_vm import EVMCodeType, Opcodes
1415

@@ -385,9 +386,12 @@ def precompiles(cls, block_number: int = 0, timestamp: int = 0) -> List[Address]
385386
"""
386387
At Homestead, EC-recover, SHA256, RIPEMD160, and Identity pre-compiles are introduced
387388
"""
388-
return list(Address(i) for i in range(1, 5)) + super(Homestead, cls).precompiles(
389-
block_number, timestamp
390-
)
389+
return [
390+
Precompile.EC_RECOVER,
391+
Precompile.SHA256,
392+
Precompile.RIPEMD_160,
393+
Precompile.IDENTITY,
394+
] + super(Homestead, cls).precompiles(block_number, timestamp)
391395

392396
@classmethod
393397
def call_opcodes(
@@ -430,9 +434,12 @@ def precompiles(cls, block_number: int = 0, timestamp: int = 0) -> List[Address]
430434
multiplication on elliptic curve alt_bn128, and optimal ate pairing check on
431435
elliptic curve alt_bn128 are introduced
432436
"""
433-
return list(Address(i) for i in range(5, 9)) + super(Byzantium, cls).precompiles(
434-
block_number, timestamp
435-
)
437+
return [
438+
Precompile.BIG_INT_MOD_EXP,
439+
Precompile.ALT_BN_128_ADD,
440+
Precompile.ALT_BN_128_MUL,
441+
Precompile.ALT_BN_128_PAIRING,
442+
] + super(Byzantium, cls).precompiles(block_number, timestamp)
436443

437444
@classmethod
438445
def call_opcodes(
@@ -513,7 +520,7 @@ def precompiles(cls, block_number: int = 0, timestamp: int = 0) -> List[Address]
513520
"""
514521
At Istanbul, pre-compile for blake2 compression is introduced
515522
"""
516-
return [Address(9)] + super(Istanbul, cls).precompiles(block_number, timestamp)
523+
return [Precompile.BLAKE2_F] + super(Istanbul, cls).precompiles(block_number, timestamp)
517524

518525
@classmethod
519526
def valid_opcodes(
@@ -730,14 +737,16 @@ def precompiles(cls, block_number: int = 0, timestamp: int = 0) -> List[Address]
730737
"""
731738
At Cancun, pre-compile for kzg point evaluation is introduced
732739
"""
733-
return [Address(0xA)] + super(Cancun, cls).precompiles(block_number, timestamp)
740+
return [Precompile.KZG_POINT_EVALUATION] + super(Cancun, cls).precompiles(
741+
block_number, timestamp
742+
)
734743

735744
@classmethod
736745
def system_contracts(cls, block_number: int = 0, timestamp: int = 0) -> List[Address]:
737746
"""
738747
Cancun introduces the system contract for EIP-4788
739748
"""
740-
return [Address(0x000F3DF6D732807EF1319FB7B8BB8522D0BEAC02)]
749+
return [SystemContract.BEACON_ROOT_HISTORY_CONTRACT]
741750

742751
@classmethod
743752
def pre_allocation_blockchain(cls) -> Mapping:
@@ -746,7 +755,7 @@ def pre_allocation_blockchain(cls) -> Mapping:
746755
type tests
747756
"""
748757
new_allocation = {
749-
0x000F3DF6D732807EF1319FB7B8BB8522D0BEAC02: {
758+
SystemContract.BEACON_ROOT_HISTORY_CONTRACT: {
750759
"nonce": 1,
751760
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5f"
752761
"fd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f"
@@ -794,12 +803,6 @@ def valid_opcodes(
794803
] + super(Cancun, cls).valid_opcodes()
795804

796805

797-
BLOCK_HISTORY_CONTRACT = Address(0x0AAE40965E6800CD9B1F4B05FF21581047E3F91E)
798-
BEACON_DEPOSIT_CONTRACT = Address(0x00000000219AB540356CBB839CBE05303D7705FA)
799-
WITHDRAWAL_REQUESTS_CONTRACT = Address(0x0000B595F2A73542E60B811C3EB8A231CA3CAAAA)
800-
CONSOLIDATION_REQUESTS_CONTRACT = Address(0x000B0CBBCB4A622B212A4C8BF81A3614CEAABBBB)
801-
802-
803806
class Prague(Cancun):
804807
"""
805808
Prague fork
@@ -835,20 +838,28 @@ def precompiles(cls, block_number: int = 0, timestamp: int = 0) -> List[Address]
835838
MAP_FP_TO_G1 = 0x12
836839
MAP_FP2_TO_G2 = 0x13
837840
"""
838-
return list(Address(i) for i in range(0xB, 0x13 + 1)) + super(Prague, cls).precompiles(
839-
block_number, timestamp
840-
)
841+
return [
842+
Precompile.BLS_12_381_G1_ADD,
843+
Precompile.BLS_12_381_G1_MUL,
844+
Precompile.BLS_12_381_G1_MULTIEXP,
845+
Precompile.BLS_12_381_G2_ADD,
846+
Precompile.BLS_12_381_G2_MUL,
847+
Precompile.BLS_12_381_G2_MULTIEXP,
848+
Precompile.BLS_12_381_PAIRING,
849+
Precompile.BLS_12_381_MAP_FP_TO_G1,
850+
Precompile.BLS_12_381_MAP_FP2_TO_G2,
851+
] + super(Prague, cls).precompiles(block_number, timestamp)
841852

842853
@classmethod
843854
def system_contracts(cls, block_number: int = 0, timestamp: int = 0) -> List[Address]:
844855
"""
845856
Prague introduces the system contracts for EIP-6110, EIP-7002, EIP-7251 and EIP-2935
846857
"""
847858
return [
848-
BEACON_DEPOSIT_CONTRACT,
849-
WITHDRAWAL_REQUESTS_CONTRACT,
850-
CONSOLIDATION_REQUESTS_CONTRACT,
851-
BLOCK_HISTORY_CONTRACT,
859+
SystemContract.BEACON_DEPOSIT_CONTRACT,
860+
SystemContract.WITHDRAWAL_REQUESTS_CONTRACT,
861+
SystemContract.CONSOLIDATION_REQUESTS_CONTRACT,
862+
SystemContract.BLOCK_HISTORY_CONTRACT,
852863
] + super(Prague, cls).system_contracts(block_number, timestamp)
853864

854865
@classmethod
@@ -870,7 +881,7 @@ def pre_allocation_blockchain(cls) -> Mapping:
870881
with open(CURRENT_FOLDER / "contracts" / "deposit_contract.bin", mode="rb") as f:
871882
new_allocation.update(
872883
{
873-
BEACON_DEPOSIT_CONTRACT: {
884+
SystemContract.BEACON_DEPOSIT_CONTRACT: {
874885
"nonce": 1,
875886
"code": f.read(),
876887
"storage": storage,
@@ -882,7 +893,7 @@ def pre_allocation_blockchain(cls) -> Mapping:
882893
with open(CURRENT_FOLDER / "contracts" / "withdrawal_request.bin", mode="rb") as f:
883894
new_allocation.update(
884895
{
885-
WITHDRAWAL_REQUESTS_CONTRACT: {
896+
SystemContract.WITHDRAWAL_REQUESTS_CONTRACT: {
886897
"nonce": 1,
887898
"code": f.read(),
888899
},
@@ -893,7 +904,7 @@ def pre_allocation_blockchain(cls) -> Mapping:
893904
with open(CURRENT_FOLDER / "contracts" / "consolidation_request.bin", mode="rb") as f:
894905
new_allocation.update(
895906
{
896-
CONSOLIDATION_REQUESTS_CONTRACT: {
907+
SystemContract.CONSOLIDATION_REQUESTS_CONTRACT: {
897908
"nonce": 1,
898909
"code": f.read(),
899910
},
@@ -904,7 +915,7 @@ def pre_allocation_blockchain(cls) -> Mapping:
904915
with open(CURRENT_FOLDER / "contracts" / "history_contract.bin", mode="rb") as f:
905916
new_allocation.update(
906917
{
907-
BLOCK_HISTORY_CONTRACT: {
918+
SystemContract.BLOCK_HISTORY_CONTRACT: {
908919
"nonce": 1,
909920
"code": f.read(),
910921
}

0 commit comments

Comments
 (0)