Skip to content

Add mysterious Petersburg fork #1719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ jobs:
- image: circleci/python:3.5
environment:
TOXENV: py35-native-blockchain-homestead
py35-native-blockchain-petersburg:
<<: *common
docker:
- image: circleci/python:3.5
environment:
TOXENV: py35-native-blockchain-petersburg
py35-native-blockchain-tangerine_whistle:
<<: *common
docker:
Expand Down Expand Up @@ -157,6 +163,12 @@ jobs:
- image: circleci/python:3.6
environment:
TOXENV: py36-native-blockchain-homestead
py36-native-blockchain-petersburg:
<<: *common
docker:
- image: circleci/python:3.6
environment:
TOXENV: py36-native-blockchain-petersburg
py36-native-blockchain-tangerine_whistle:
<<: *common
docker:
Expand Down Expand Up @@ -219,6 +231,7 @@ workflows:
- py36-native-blockchain-constantinople
- py36-native-blockchain-frontier
- py36-native-blockchain-homestead
- py36-native-blockchain-petersburg
- py36-native-blockchain-tangerine_whistle
- py36-native-blockchain-spurious_dragon
- py36-native-blockchain-transition
Expand All @@ -232,6 +245,7 @@ workflows:
- py35-native-blockchain-constantinople
- py35-native-blockchain-frontier
- py35-native-blockchain-homestead
- py35-native-blockchain-petersburg
- py35-native-blockchain-tangerine_whistle
- py35-native-blockchain-spurious_dragon
- py35-native-blockchain-transition
Expand Down
6 changes: 6 additions & 0 deletions docs/release_notes/index.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Release notes
=============

Unreleased (latest source)
--------------------------

- `#1719 <https://github.com/ethereum/py-evm/pull/1719>`_: Implement and activate Petersburg fork (aka Constantinople fixed)


0.2.0-alpha.40
--------------

Expand Down
8 changes: 4 additions & 4 deletions eth/chains/mainnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .constants import (
MAINNET_CHAIN_ID,
BYZANTIUM_MAINNET_BLOCK,
CONSTANTINOPLE_MAINNET_BLOCK,
PETERSBURG_MAINNET_BLOCK,
TANGERINE_WHISTLE_MAINNET_BLOCK,
HOMESTEAD_MAINNET_BLOCK,
SPURIOUS_DRAGON_MAINNET_BLOCK,
Expand All @@ -29,9 +29,9 @@
from eth.vm.base import BaseVM # noqa: F401
from eth.vm.forks import (
ByzantiumVM,
ConstantinopleVM,
FrontierVM,
HomesteadVM,
PetersburgVM,
SpuriousDragonVM,
TangerineWhistleVM,
)
Expand Down Expand Up @@ -80,15 +80,15 @@ class MainnetHomesteadVM(MainnetDAOValidatorVM):
TANGERINE_WHISTLE_MAINNET_BLOCK,
SPURIOUS_DRAGON_MAINNET_BLOCK,
BYZANTIUM_MAINNET_BLOCK,
CONSTANTINOPLE_MAINNET_BLOCK,
PETERSBURG_MAINNET_BLOCK,
)
MAINNET_VMS = (
FrontierVM,
MainnetHomesteadVM,
TangerineWhistleVM,
SpuriousDragonVM,
ByzantiumVM,
ConstantinopleVM,
PetersburgVM,
)

MAINNET_VM_CONFIGURATION = tuple(zip(MAINNET_FORK_BLOCKS, MAINNET_VMS))
Expand Down
4 changes: 2 additions & 2 deletions eth/chains/mainnet/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
BYZANTIUM_MAINNET_BLOCK = BlockNumber(4370000)

#
# Constantinople Block
# Petersburg Block
#
CONSTANTINOPLE_MAINNET_BLOCK = BlockNumber(9876543210)
PETERSBURG_MAINNET_BLOCK = BlockNumber(7280000)
3 changes: 3 additions & 0 deletions eth/chains/ropsten/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .constants import (
BYZANTIUM_ROPSTEN_BLOCK,
CONSTANTINOPLE_ROPSTEN_BLOCK,
PETERSBURG_ROPSTEN_BLOCK,
ROPSTEN_CHAIN_ID,
SPURIOUS_DRAGON_ROPSTEN_BLOCK,
TANGERINE_WHISTLE_ROPSTEN_BLOCK,
Expand All @@ -16,6 +17,7 @@
from eth.vm.forks import (
ByzantiumVM,
ConstantinopleVM,
PetersburgVM,
SpuriousDragonVM,
TangerineWhistleVM,
)
Expand All @@ -27,6 +29,7 @@
(SPURIOUS_DRAGON_ROPSTEN_BLOCK, SpuriousDragonVM),
(BYZANTIUM_ROPSTEN_BLOCK, ByzantiumVM),
(CONSTANTINOPLE_ROPSTEN_BLOCK, ConstantinopleVM),
(PETERSBURG_ROPSTEN_BLOCK, PetersburgVM),
)


Expand Down
6 changes: 6 additions & 0 deletions eth/chains/ropsten/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@
# Constantinople
#
CONSTANTINOPLE_ROPSTEN_BLOCK = BlockNumber(4230000)


#
# Petersburg
#
PETERSBURG_ROPSTEN_BLOCK = BlockNumber(4939394)
3 changes: 2 additions & 1 deletion eth/tools/builder/chain/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
SpuriousDragonVM,
ByzantiumVM,
ConstantinopleVM,
PetersburgVM,
)


Expand Down Expand Up @@ -225,7 +226,7 @@ def dao_fork_at(dao_fork_block_number: BlockNumber,
spurious_dragon_at = fork_at(SpuriousDragonVM)
byzantium_at = fork_at(ByzantiumVM)
constantinople_at = fork_at(ConstantinopleVM)

petersburg_at = fork_at(PetersburgVM)

GENESIS_DEFAULTS = (
('difficulty', 1),
Expand Down
5 changes: 5 additions & 0 deletions eth/tools/fixtures/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
BaseVM,
)
from eth.vm.forks import (
PetersburgVM,
ConstantinopleVM,
ByzantiumVM,
TangerineWhistleVM,
Expand Down Expand Up @@ -131,6 +132,10 @@ def chain_vm_configuration(fixture: Dict[str, Any]) -> Iterable[Tuple[int, Type[
return (
(0, ConstantinopleVM),
)
elif network == 'ConstantinopleFix':
return (
(0, PetersburgVM),
)
elif network == 'FrontierToHomesteadAt5':
HomesteadVM = BaseHomesteadVM.configure(support_dao_fork=False)
return (
Expand Down
3 changes: 3 additions & 0 deletions eth/vm/forks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
from .constantinople import ( # noqa: F401
ConstantinopleVM,
)
from .petersburg import ( # noqa: F401
PetersburgVM,
)
11 changes: 1 addition & 10 deletions eth/vm/forks/constantinople/computation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from eth_utils.toolz import (
merge,
)

from eth.vm.forks.byzantium.computation import (
BYZANTIUM_PRECOMPILES
)
Expand All @@ -15,12 +11,7 @@

from .opcodes import CONSTANTINOPLE_OPCODES

CONSTANTINOPLE_PRECOMPILES = merge(
BYZANTIUM_PRECOMPILES,
{
# TODO: add new precompiles
},
)
CONSTANTINOPLE_PRECOMPILES = BYZANTIUM_PRECOMPILES


class ConstantinopleComputation(ByzantiumComputation):
Expand Down
38 changes: 38 additions & 0 deletions eth/vm/forks/petersburg/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from typing import ( # noqa: F401
Type,
)

from eth.rlp.blocks import BaseBlock # noqa: F401
from eth.vm.forks.byzantium import (
ByzantiumVM,
get_uncle_reward,
)
from eth.vm.state import BaseState # noqa: F401

from .blocks import PetersburgBlock
from .constants import EIP1234_BLOCK_REWARD
from .headers import (
compute_petersburg_difficulty,
configure_petersburg_header,
create_petersburg_header_from_parent,
)
from .state import PetersburgState


class PetersburgVM(ByzantiumVM):
# fork name
fork = 'petersburg'

# classes
block_class = PetersburgBlock # type: Type[BaseBlock]
_state_class = PetersburgState # type: Type[BaseState]

# Methods
create_header_from_parent = staticmethod(create_petersburg_header_from_parent) # type: ignore # noqa: E501
compute_difficulty = staticmethod(compute_petersburg_difficulty) # type: ignore
configure_header = configure_petersburg_header
get_uncle_reward = staticmethod(get_uncle_reward(EIP1234_BLOCK_REWARD))

@staticmethod
def get_block_reward() -> int:
return EIP1234_BLOCK_REWARD
22 changes: 22 additions & 0 deletions eth/vm/forks/petersburg/blocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from rlp.sedes import (
CountableList,
)
from eth.rlp.headers import (
BlockHeader,
)
from eth.vm.forks.byzantium.blocks import (
ByzantiumBlock,
)

from .transactions import (
PetersburgTransaction,
)


class PetersburgBlock(ByzantiumBlock):
transaction_class = PetersburgTransaction
fields = [
('header', BlockHeader),
('transactions', CountableList(transaction_class)),
('uncles', CountableList(BlockHeader))
]
20 changes: 20 additions & 0 deletions eth/vm/forks/petersburg/computation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from eth.vm.forks.byzantium.computation import (
BYZANTIUM_PRECOMPILES
)
from eth.vm.forks.byzantium.computation import (
ByzantiumComputation
)

from .opcodes import PETERSBURG_OPCODES

PETERSBURG_PRECOMPILES = BYZANTIUM_PRECOMPILES


class PetersburgComputation(ByzantiumComputation):
"""
A class for all execution computations in the ``Petersburg`` fork.
Inherits from :class:`~eth.vm.forks.byzantium.computation.ByzantiumComputation`
"""
# Override
opcodes = PETERSBURG_OPCODES
_precompiles = PETERSBURG_PRECOMPILES
6 changes: 6 additions & 0 deletions eth/vm/forks/petersburg/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from eth_utils import denoms


GAS_EXTCODEHASH_EIP1052 = 400

EIP1234_BLOCK_REWARD = 2 * denoms.ether
13 changes: 13 additions & 0 deletions eth/vm/forks/petersburg/headers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from eth.vm.forks.byzantium.headers import (
configure_header,
create_header_from_parent,
compute_difficulty,
)


compute_petersburg_difficulty = compute_difficulty(5000000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe compute_difficulty(bomb_delay=5000000) as a way to document what this magic number is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, this fails the tests with:

TypeError: compute_difficulty() got multiple values for argument 'bomb_delay' (CI job)

Leaving it as is for now.


create_petersburg_header_from_parent = create_header_from_parent(
compute_petersburg_difficulty
)
configure_petersburg_header = configure_header(compute_petersburg_difficulty)
60 changes: 60 additions & 0 deletions eth/vm/forks/petersburg/opcodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import copy
from eth_utils.toolz import (
merge
)

from eth import (
constants
)
from eth.vm import (
mnemonics,
opcode_values,
)
from eth.vm.forks.byzantium.opcodes import (
BYZANTIUM_OPCODES,
)
from eth.vm.forks.petersburg.constants import (
GAS_EXTCODEHASH_EIP1052
)
from eth.vm.logic import (
arithmetic,
context,
system,
)
from eth.vm.opcode import (
as_opcode
)


UPDATED_OPCODES = {
opcode_values.SHL: as_opcode(
logic_fn=arithmetic.shl,
mnemonic=mnemonics.SHL,
gas_cost=constants.GAS_VERYLOW,
),
opcode_values.SHR: as_opcode(
logic_fn=arithmetic.shr,
mnemonic=mnemonics.SHR,
gas_cost=constants.GAS_VERYLOW,
),
opcode_values.SAR: as_opcode(
logic_fn=arithmetic.sar,
mnemonic=mnemonics.SAR,
gas_cost=constants.GAS_VERYLOW,
),
opcode_values.EXTCODEHASH: as_opcode(
logic_fn=context.extcodehash,
mnemonic=mnemonics.EXTCODEHASH,
gas_cost=GAS_EXTCODEHASH_EIP1052,
),
opcode_values.CREATE2: system.Create2.configure(
__name__='opcode:CREATE2',
mnemonic=mnemonics.CREATE2,
gas_cost=constants.GAS_CREATE,
)(),
}

PETERSBURG_OPCODES = merge(
copy.deepcopy(BYZANTIUM_OPCODES),
UPDATED_OPCODES,
)
9 changes: 9 additions & 0 deletions eth/vm/forks/petersburg/state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from eth.vm.forks.byzantium.state import (
ByzantiumState
)

from .computation import PetersburgComputation


class PetersburgState(ByzantiumState):
computation_class = PetersburgComputation
Loading