Skip to content

Commit

Permalink
Implement EXTCODEHASH opcode for Constantinople
Browse files Browse the repository at this point in the history
  • Loading branch information
cburgdorf committed Aug 6, 2018
1 parent bf1d3c2 commit 578a2bc
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions eth/vm/forks/constantinople/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GAS_EXTCODEHASH_EIP1052 = 400
11 changes: 10 additions & 1 deletion eth/vm/forks/constantinople/opcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
from eth.vm.forks.byzantium.opcodes import (
BYZANTIUM_OPCODES
)
from eth.vm.forks.constantinople.constants import (
GAS_EXTCODEHASH_EIP1052
)
from eth.vm.logic import (
arithmetic
arithmetic,
context,
)
from eth.vm.opcode import (
as_opcode
Expand All @@ -32,6 +36,11 @@
mnemonic=mnemonics.SHR,
gas_cost=constants.GAS_VERYLOW,
),
opcode_values.EXTCODEHASH: as_opcode(
logic_fn=context.extcodehash,
mnemonic=mnemonics.EXTCODEHASH,
gas_cost=GAS_EXTCODEHASH_EIP1052,
),
}

CONSTANTINOPLE_OPCODES = merge(
Expand Down
7 changes: 7 additions & 0 deletions eth/vm/logic/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ def extcodecopy(computation):
computation.memory_write(mem_start_position, size, padded_code_bytes)


def extcodehash(computation):
account = force_bytes_to_address(computation.stack_pop(type_hint=constants.BYTES))
code_hash = computation.state.account_db.get_code_hash(account)

computation.stack_push(code_hash)


def returndatasize(computation):
size = len(computation.return_data)
computation.stack_push(size)
Expand Down
1 change: 1 addition & 0 deletions eth/vm/mnemonics.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
GASPRICE = 'GASPRICE'
EXTCODESIZE = 'EXTCODESIZE'
EXTCODECOPY = 'EXTCODECOPY'
EXTCODEHASH = 'EXTCODEHASH'
RETURNDATASIZE = 'RETURNDATASIZE'
RETURNDATACOPY = 'RETURNDATACOPY'
#
Expand Down
1 change: 1 addition & 0 deletions eth/vm/opcode_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
GASPRICE = 0x3a
EXTCODESIZE = 0x3b
EXTCODECOPY = 0x3c
EXTCODEHASH = 0x3f
RETURNDATASIZE = 0x3d
RETURNDATACOPY = 0x3e

Expand Down

0 comments on commit 578a2bc

Please sign in to comment.