From fe74e9bdf9092e18097ae140de706198b2c8ffd0 Mon Sep 17 00:00:00 2001 From: voith Date: Thu, 19 Sep 2019 04:03:23 +0530 Subject: [PATCH 1/9] update upstream tests for Istanbul --- eth/chains/mainnet/__init__.py | 4 ++++ eth/chains/mainnet/constants.py | 6 ++++++ eth/tools/fixtures/helpers.py | 5 +++++ fixtures | 2 +- tests/core/chain-object/test_contract_call.py | 11 +++++++++++ tests/core/tester/test_generate_vm_configuration.py | 7 +++++-- tests/json-fixtures/test_transactions.py | 4 ++-- tox.ini | 3 ++- 8 files changed, 36 insertions(+), 6 deletions(-) diff --git a/eth/chains/mainnet/__init__.py b/eth/chains/mainnet/__init__.py index 80b97db7bd..34cdd3906a 100644 --- a/eth/chains/mainnet/__init__.py +++ b/eth/chains/mainnet/__init__.py @@ -14,6 +14,7 @@ MAINNET_CHAIN_ID, BYZANTIUM_MAINNET_BLOCK, PETERSBURG_MAINNET_BLOCK, + ISTANBUL_MAINNET_BLOCK, TANGERINE_WHISTLE_MAINNET_BLOCK, HOMESTEAD_MAINNET_BLOCK, SPURIOUS_DRAGON_MAINNET_BLOCK, @@ -34,6 +35,7 @@ ByzantiumVM, FrontierVM, HomesteadVM, + IstanbulVM, PetersburgVM, SpuriousDragonVM, TangerineWhistleVM, @@ -84,6 +86,7 @@ class MainnetHomesteadVM(MainnetDAOValidatorVM): SPURIOUS_DRAGON_MAINNET_BLOCK, BYZANTIUM_MAINNET_BLOCK, PETERSBURG_MAINNET_BLOCK, + ISTANBUL_MAINNET_BLOCK, ) MAINNET_VMS = ( FrontierVM, @@ -92,6 +95,7 @@ class MainnetHomesteadVM(MainnetDAOValidatorVM): SpuriousDragonVM, ByzantiumVM, PetersburgVM, + IstanbulVM, ) MAINNET_VM_CONFIGURATION = tuple(zip(MAINNET_FORK_BLOCKS, MAINNET_VMS)) diff --git a/eth/chains/mainnet/constants.py b/eth/chains/mainnet/constants.py index 669d895ca9..bc6b7bc964 100644 --- a/eth/chains/mainnet/constants.py +++ b/eth/chains/mainnet/constants.py @@ -42,3 +42,9 @@ # Petersburg Block # PETERSBURG_MAINNET_BLOCK = BlockNumber(7280000) + +# +# Istanbul Block +# +# FIXME: Replace this with the correct blocknumber when it's decided +ISTANBUL_MAINNET_BLOCK = BlockNumber(7280728) diff --git a/eth/tools/fixtures/helpers.py b/eth/tools/fixtures/helpers.py index 524c8b2bb6..e24498e545 100644 --- a/eth/tools/fixtures/helpers.py +++ b/eth/tools/fixtures/helpers.py @@ -45,6 +45,7 @@ FrontierVM, HomesteadVM as BaseHomesteadVM, SpuriousDragonVM, + IstanbulVM, ) @@ -131,6 +132,10 @@ def chain_vm_configuration(fixture: Dict[str, Any]) -> Iterable[Tuple[int, Type[ return ( (0, PetersburgVM), ) + elif network == 'Istanbul': + return ( + (0, IstanbulVM), + ) elif network == 'FrontierToHomesteadAt5': HomesteadVM = BaseHomesteadVM.configure(support_dao_fork=False) return ( diff --git a/fixtures b/fixtures index 6b85703b56..d4f86ecf4a 160000 --- a/fixtures +++ b/fixtures @@ -1 +1 @@ -Subproject commit 6b85703b568f4456582a00665d8a3e5c3b20b484 +Subproject commit d4f86ecf4aa7c44a40bc0c972fd3e25d63ef5d92 diff --git a/tests/core/chain-object/test_contract_call.py b/tests/core/chain-object/test_contract_call.py index 8e056a2856..f3ec5c3cce 100644 --- a/tests/core/chain-object/test_contract_call.py +++ b/tests/core/chain-object/test_contract_call.py @@ -27,6 +27,7 @@ ByzantiumVM, ConstantinopleVM, PetersburgVM, + IstanbulVM, ) @@ -213,6 +214,16 @@ def test_get_transaction_result( 'useLotsOfGas()', OutOfGas, ), + ( + IstanbulVM, + 'doRevert()', + Revert, + ), + ( + IstanbulVM, + 'useLotsOfGas()', + OutOfGas, + ), ), ) def test_get_transaction_result_revert( diff --git a/tests/core/tester/test_generate_vm_configuration.py b/tests/core/tester/test_generate_vm_configuration.py index 57ef011a5f..f59567e9ae 100644 --- a/tests/core/tester/test_generate_vm_configuration.py +++ b/tests/core/tester/test_generate_vm_configuration.py @@ -17,6 +17,7 @@ class Forks(enum.Enum): Byzantium = 'Byzantium' Constantinople = 'Constantinople' Petersburg = 'Petersburg' + Istanbul = 'Istanbul' class CustomFrontierVM(FrontierVM): @@ -29,7 +30,7 @@ class CustomFrontierVM(FrontierVM): ( tuple(), {}, - ((0, Forks.Petersburg),), + ((0, Forks.Istanbul),), ), ( ((0, 'tangerine-whistle'), (1, 'spurious-dragon')), @@ -116,7 +117,8 @@ class CustomFrontierVM(FrontierVM): (1, 'homestead'), (2, 'tangerine-whistle'), (3, 'byzantium'), - (5, 'petersburg') + (5, 'petersburg'), + (6, 'istanbul'), ), {}, ( @@ -125,6 +127,7 @@ class CustomFrontierVM(FrontierVM): (2, Forks.TangerineWhistle), (3, Forks.Byzantium), (5, Forks.Petersburg), + (6, Forks.Istanbul) ), ), ), diff --git a/tests/json-fixtures/test_transactions.py b/tests/json-fixtures/test_transactions.py index eb8349c338..53f37d4b98 100644 --- a/tests/json-fixtures/test_transactions.py +++ b/tests/json-fixtures/test_transactions.py @@ -102,9 +102,9 @@ def fixture_transaction_class(fixture_data): return ByzantiumTransaction elif fork_name == ForkName.Constantinople: return ConstantinopleTransaction - elif fork_name == "Petersburg": + elif fork_name == "ConstantinopleFix": return PetersburgTransaction - elif fork_name == ForkName.Istanbul: + elif fork_name == "Istanbul": return IstanbulTransaction elif fork_name == ForkName.Metropolis: pytest.skip("Metropolis Transaction class has not been implemented") diff --git a/tox.ini b/tox.ini index df6c5651bb..457a62af46 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,7 @@ envlist= py{36,37}-{core,database,transactions,vm} py36-benchmark - py36-native-blockchain-{frontier,homestead,tangerine_whistle,spurious_dragon,byzantium,constantinople,petersburg,metropolis,transition} + py36-native-blockchain-{frontier,homestead,tangerine_whistle,spurious_dragon,byzantium,constantinople,petersburg,istanbul,metropolis,transition} py{36,37}-lint py36-docs @@ -28,6 +28,7 @@ commands= native-blockchain-byzantium: pytest {posargs:tests/json-fixtures/test_blockchain.py --fork Byzantium} native-blockchain-constantinople: pytest {posargs:tests/json-fixtures/test_blockchain.py --fork Constantinople} native-blockchain-petersburg: pytest {posargs:tests/json-fixtures/test_blockchain.py --fork ConstantinopleFix} + native-blockchain-istanbul: pytest {posargs:tests/json-fixtures/test_blockchain.py --fork Istanbul} native-blockchain-metropolis: pytest {posargs:tests/json-fixtures/test_blockchain.py --fork Metropolis} native-blockchain-transition: pytest {posargs:tests/json-fixtures/test_blockchain.py -k BlockchainTests/TransitionTests} lint: flake8 {toxinidir}/eth {toxinidir}/tests {toxinidir}/scripts From c02314438f07d1feeb54d8c09eeb6755f5841197 Mon Sep 17 00:00:00 2001 From: voith Date: Sun, 22 Sep 2019 20:40:24 +0530 Subject: [PATCH 2/9] updated fixtures and handle case when postState is a string --- eth/tools/_utils/normalization.py | 31 +++++++++++++++++++------------ fixtures | 2 +- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/eth/tools/_utils/normalization.py b/eth/tools/_utils/normalization.py index 58ba072d69..263e18c858 100644 --- a/eth/tools/_utils/normalization.py +++ b/eth/tools/_utils/normalization.py @@ -362,18 +362,25 @@ def normalize_unsigned_transaction(transaction: TransactionDict, FixtureAccountState = Dict[Address, FixtureAccountDetails] -def normalize_account_state(account_state: FixtureAccountState) -> AccountState: - return { - to_canonical_address(address): { - 'balance': to_int(state['balance']), - 'code': decode_hex(state['code']), - 'nonce': to_int(state['nonce']), - 'storage': { - to_int(slot): big_endian_to_int(decode_hex(value)) - for slot, value in state['storage'].items() - }, - } for address, state in account_state.items() - } +def normalize_account_state(account_state: FixtureAccountState) -> Union[AccountState, str]: + if isinstance(account_state, dict): + return { + to_canonical_address(address): { + 'balance': to_int(state['balance']), + 'code': decode_hex(state['code']), + 'nonce': to_int(state['nonce']), + 'storage': { + to_int(slot): big_endian_to_int(decode_hex(value)) + for slot, value in state['storage'].items() + }, + } for address, state in account_state.items() + } + elif isinstance(account_state, str): + # https://github.com/ethereum/tests/issues/637#issuecomment-532234905 + # some fixtures have postState as a string instead of map + return account_state + else: + raise Exception('Invariant') @to_dict diff --git a/fixtures b/fixtures index d4f86ecf4a..52d5247fe4 160000 --- a/fixtures +++ b/fixtures @@ -1 +1 @@ -Subproject commit d4f86ecf4aa7c44a40bc0c972fd3e25d63ef5d92 +Subproject commit 52d5247fe41f489c274e4254b151520bc3f20cc7 From d1b657e2a4abcbed953a210ac70a0441378676d6 Mon Sep 17 00:00:00 2001 From: voith Date: Sun, 22 Sep 2019 21:22:50 +0530 Subject: [PATCH 3/9] add more gas for sstore_uint64 tests --- scripts/benchmark/checks/deploy_dos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/benchmark/checks/deploy_dos.py b/scripts/benchmark/checks/deploy_dos.py index 9402ee825d..ab483f23a3 100644 --- a/scripts/benchmark/checks/deploy_dos.py +++ b/scripts/benchmark/checks/deploy_dos.py @@ -43,7 +43,7 @@ ) FIRST_TX_GAS_LIMIT = 367724 -SECOND_TX_GAS_LIMIT = 62050 +SECOND_TX_GAS_LIMIT = 63042 THIRD_TX_GAS_LIMIT = 104789 FORTH_TX_GAS_LIMIT = 21272 FIFTH_TX_GAS_LIMIT = 21272 From b3eb09cae49e8180647e098aa0bdd94e1a9235c6 Mon Sep 17 00:00:00 2001 From: voith Date: Sun, 22 Sep 2019 21:25:25 +0530 Subject: [PATCH 4/9] change ByzantiumToConstantinopleAt5 to ByzantiumToConstantinopleFixAt5 --- eth/tools/fixtures/helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth/tools/fixtures/helpers.py b/eth/tools/fixtures/helpers.py index e24498e545..fc413ffcce 100644 --- a/eth/tools/fixtures/helpers.py +++ b/eth/tools/fixtures/helpers.py @@ -161,7 +161,7 @@ def chain_vm_configuration(fixture: Dict[str, Any]) -> Iterable[Tuple[int, Type[ (0, SpuriousDragonVM), (5, ByzantiumVM), ) - elif network == 'ByzantiumToConstantinopleAt5': + elif network == 'ByzantiumToConstantinopleFixAt5': return ( (0, ByzantiumVM), (5, ConstantinopleVM), From b413fa9baac811222dbee09108c73aaac1ab1477 Mon Sep 17 00:00:00 2001 From: voith Date: Sun, 22 Sep 2019 21:38:21 +0530 Subject: [PATCH 5/9] update gas for create_empty_contract --- scripts/benchmark/checks/deploy_dos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/benchmark/checks/deploy_dos.py b/scripts/benchmark/checks/deploy_dos.py index ab483f23a3..e8827a6f10 100644 --- a/scripts/benchmark/checks/deploy_dos.py +++ b/scripts/benchmark/checks/deploy_dos.py @@ -44,7 +44,7 @@ FIRST_TX_GAS_LIMIT = 367724 SECOND_TX_GAS_LIMIT = 63042 -THIRD_TX_GAS_LIMIT = 104789 +THIRD_TX_GAS_LIMIT = 105781 FORTH_TX_GAS_LIMIT = 21272 FIFTH_TX_GAS_LIMIT = 21272 From 4b96de70d25591c64745e1421ece5fbdbb7d2e33 Mon Sep 17 00:00:00 2001 From: voith Date: Mon, 23 Sep 2019 12:40:53 +0530 Subject: [PATCH 6/9] mark randomStatetest94 as slow tests --- tests/json-fixtures/test_blockchain.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/json-fixtures/test_blockchain.py b/tests/json-fixtures/test_blockchain.py index a6c02844d2..2ff55d2b1f 100644 --- a/tests/json-fixtures/test_blockchain.py +++ b/tests/json-fixtures/test_blockchain.py @@ -167,6 +167,10 @@ ('GeneralStateTests/stStaticCall/static_Return50000_2_d0g0v0.json', 'static_Return50000_2_d0g0v0_ConstantinopleFix'), # noqa: E501 ('GeneralStateTests/stSystemOperationsTest/CallRecursiveBomb0_OOG_atMaxCallDepth_d0g0v0.json', 'CallRecursiveBomb0_OOG_atMaxCallDepth_d0g0v0_Frontier'), # noqa: E501 ('GeneralStateTests/stSystemOperationsTest/CallRecursiveBomb0_OOG_atMaxCallDepth_d0g0v0.json', 'CallRecursiveBomb0_OOG_atMaxCallDepth_d0g0v0_Homestead'), # noqa: E501 + ('ValidBlocks/bcStateTests/randomStatetest94.json', 'randomStatetest94_Homestead'), # noqa: E501 + ('ValidBlocks/bcStateTests/randomStatetest94.json', 'randomStatetest94_Byzantium'), # noqa: E501 + ('ValidBlocks/bcStateTests/randomStatetest94.json', 'randomStatetest94_Constantinople'), # noqa: E501 + ('ValidBlocks/bcStateTests/randomStatetest94.json', 'randomStatetest94_ConstantinopleFix'), # noqa: E501 } From 0d0c58ce61b3ceb75889ec5a8a4a2c006da82091 Mon Sep 17 00:00:00 2001 From: voith Date: Mon, 23 Sep 2019 13:18:35 +0530 Subject: [PATCH 7/9] add istanbul blockchain tests to CI fix copy/paste --- .circleci/config.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index cf83d502ea..5df3f2bc3e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -70,6 +70,12 @@ jobs: - image: circleci/python:3.6 environment: TOXENV: py36-native-blockchain-homestead + py36-native-blockchain-istanbul: + <<: *common + docker: + - image: circleci/python:3.6 + environment: + TOXENV: py36-native-blockchain-istanbul py36-native-blockchain-petersburg: <<: *common docker: @@ -171,6 +177,7 @@ workflows: - py36-native-blockchain-constantinople - py36-native-blockchain-frontier - py36-native-blockchain-homestead + - py36-native-blockchain-istanbul - py36-native-blockchain-petersburg - py36-native-blockchain-tangerine_whistle - py36-native-blockchain-spurious_dragon From cbaeba7c8e669dcb3156d229f9d5eb265a319a8a Mon Sep 17 00:00:00 2001 From: voith Date: Thu, 26 Sep 2019 14:49:18 +0530 Subject: [PATCH 8/9] Some fixtures do not have post state. Added a normalizer `normalize_post_stae` to handle this case. renamed existing method `normalize_post_state` to `normalize_post_state_hash` --- eth/tools/_utils/normalization.py | 44 ++++++++++++++++--------------- fixtures | 2 +- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/eth/tools/_utils/normalization.py b/eth/tools/_utils/normalization.py index 263e18c858..e13c48dfd0 100644 --- a/eth/tools/_utils/normalization.py +++ b/eth/tools/_utils/normalization.py @@ -362,29 +362,31 @@ def normalize_unsigned_transaction(transaction: TransactionDict, FixtureAccountState = Dict[Address, FixtureAccountDetails] -def normalize_account_state(account_state: FixtureAccountState) -> Union[AccountState, str]: - if isinstance(account_state, dict): - return { - to_canonical_address(address): { - 'balance': to_int(state['balance']), - 'code': decode_hex(state['code']), - 'nonce': to_int(state['nonce']), - 'storage': { - to_int(slot): big_endian_to_int(decode_hex(value)) - for slot, value in state['storage'].items() - }, - } for address, state in account_state.items() - } - elif isinstance(account_state, str): - # https://github.com/ethereum/tests/issues/637#issuecomment-532234905 - # some fixtures have postState as a string instead of map - return account_state +def normalize_account_state(account_state: FixtureAccountState) -> AccountState: + return { + to_canonical_address(address): { + 'balance': to_int(state['balance']), + 'code': decode_hex(state['code']), + 'nonce': to_int(state['nonce']), + 'storage': { + to_int(slot): big_endian_to_int(decode_hex(value)) + for slot, value in state['storage'].items() + }, + } for address, state in account_state.items() + } + + +def normalize_post_state(postate: FixtureAccountState) -> AccountState: + # poststate might not be present in some fixtures + # https://github.com/ethereum/tests/issues/637#issuecomment-534072897 + if postate is None: + return {} else: - raise Exception('Invariant') + return normalize_account_state(postate) @to_dict -def normalize_post_state(post_state: Dict[str, Any]) -> Iterable[Tuple[str, bytes]]: +def normalize_post_state_hash(post_state: Dict[str, Any]) -> Iterable[Tuple[str, bytes]]: yield 'hash', decode_hex(post_state['hash']) if 'logs' in post_state: yield 'logs', decode_hex(post_state['logs']) @@ -400,7 +402,7 @@ def normalize_statetest_fixture(fixture: Dict[str, Any], normalized_fixture = { 'env': normalize_environment(fixture['env']), 'pre': normalize_account_state(fixture['pre']), - 'post': normalize_post_state(post_state), + 'post': normalize_post_state_hash(post_state), 'transaction': normalize_unsigned_transaction( fixture['transaction'], post_state['indexes'], @@ -547,7 +549,7 @@ def normalize_blockchain_fixtures(fixture: Dict[str, Any]) -> Dict[str, Any]: 'genesisBlockHeader': normalize_block_header(fixture['genesisBlockHeader']), 'lastblockhash': decode_hex(fixture['lastblockhash']), 'pre': normalize_account_state(fixture['pre']), - 'postState': normalize_account_state(fixture['postState']), + 'postState': normalize_post_state(fixture.get('postState')), 'network': fixture['network'], } diff --git a/fixtures b/fixtures index 52d5247fe4..b5eb9900ee 160000 --- a/fixtures +++ b/fixtures @@ -1 +1 @@ -Subproject commit 52d5247fe41f489c274e4254b151520bc3f20cc7 +Subproject commit b5eb9900ee2147b40d3e681fe86efa4fd693959a From cd3e634f5e43fd6423b8f1ef44e297210e73600a Mon Sep 17 00:00:00 2001 From: voith Date: Wed, 2 Oct 2019 13:51:00 +0530 Subject: [PATCH 9/9] mark some tests as incorrect --- tests/json-fixtures/test_blockchain.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/json-fixtures/test_blockchain.py b/tests/json-fixtures/test_blockchain.py index 2ff55d2b1f..50741e1732 100644 --- a/tests/json-fixtures/test_blockchain.py +++ b/tests/json-fixtures/test_blockchain.py @@ -187,12 +187,14 @@ ('GeneralStateTests/stRevertTest/RevertInCreateInInit_d0g0v0.json', 'RevertInCreateInInit_d0g0v0_Byzantium'), # noqa: E501 ('GeneralStateTests/stRevertTest/RevertInCreateInInit_d0g0v0.json', 'RevertInCreateInInit_d0g0v0_Constantinople'), # noqa: E501 ('GeneralStateTests/stRevertTest/RevertInCreateInInit_d0g0v0.json', 'RevertInCreateInInit_d0g0v0_ConstantinopleFix'), # noqa: E501 + ('GeneralStateTests/stRevertTest/RevertInCreateInInit.json', 'RevertInCreateInInit_d0g0v0_Istanbul'), # noqa: E501 # The CREATE2 variant seems to have been derived from the one above - it, too, # has a "synthetic" state, on which py-evm flips. # * https://github.com/ethereum/py-evm/pull/1181#issuecomment-446330609 ('GeneralStateTests/stCreate2/RevertInCreateInInitCreate2_d0g0v0.json', 'RevertInCreateInInitCreate2_d0g0v0_Constantinople'), # noqa: E501 ('GeneralStateTests/stCreate2/RevertInCreateInInitCreate2_d0g0v0.json', 'RevertInCreateInInitCreate2_d0g0v0_ConstantinopleFix'), # noqa: E501 + ('GeneralStateTests/stCreate2/RevertInCreateInInitCreate2.json', 'RevertInCreateInInitCreate2_d0g0v0_Istanbul'), # noqa: E501 # Four variants have been specifically added to test a collision type # like the above; therefore, they fail in the same manner. @@ -206,6 +208,9 @@ ('GeneralStateTests/stSStoreTest/InitCollision_d0g0v0.json', 'InitCollision_d0g0v0_ConstantinopleFix'), # noqa: E501 ('GeneralStateTests/stSStoreTest/InitCollision_d1g0v0.json', 'InitCollision_d1g0v0_ConstantinopleFix'), # noqa: E501 ('GeneralStateTests/stSStoreTest/InitCollision_d3g0v0.json', 'InitCollision_d3g0v0_ConstantinopleFix'), # noqa: E501 + ('GeneralStateTests/stSStoreTest/InitCollision.json', 'InitCollision_d0g0v0_Istanbul'), # noqa: E501 + ('GeneralStateTests/stSStoreTest/InitCollision.json', 'InitCollision_d1g0v0_Istanbul'), # noqa: E501 + ('GeneralStateTests/stSStoreTest/InitCollision.json', 'InitCollision_d3g0v0_Istanbul'), # noqa: E501 }