Skip to content

Commit

Permalink
Fix some failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pipermerriam committed Dec 10, 2018
1 parent 04ac2a5 commit 010b840
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion eth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#
# Ensure we can reach 1024 frames of recursion
#
EVM_RECURSION_LIMIT = 1024 * 10
EVM_RECURSION_LIMIT = 1024 * 12

This comment has been minimized.

Copy link
@lithp

lithp Dec 11, 2018

Contributor

11 because you're adding a call to apply_create_message, 12 because computation.state.* calls deepen the stack further? But if that were the reason you'd need to go bigger than 12.

This comment has been minimized.

Copy link
@pipermerriam

pipermerriam Dec 11, 2018

Author Member

12 because I tested with 10 and it failed, tried 15 and it succeeded, and moved down to 12 and it still succeeded..... I'm mildly embarrassed....

When the original 10 was set it was a more precise number based on the actually upper bound, but the computation process has grown in complexity and it's not trivial anymore to derive it (but I think it could still be done).

This comment has been minimized.

Copy link
@lithp

lithp Dec 11, 2018

Contributor

Ahh, that makes sense, both 11 and 12 are for the computation.state.* calls.

You could probably grab it by using sys.settrace() and holding onto the longest stack trace you see during test execution.

sys.setrecursionlimit(max(EVM_RECURSION_LIMIT, sys.getrecursionlimit()))


Expand Down
33 changes: 26 additions & 7 deletions eth/vm/logic/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@
ceil32,
)
from eth.vm import mnemonics
from eth.vm.computation import (
BaseComputation
)
from eth.vm.opcode import (
Opcode,
)
from eth.vm.computation import BaseComputation
from eth.vm.message import Message
from eth.vm.opcode import Opcode

from .call import max_child_gas_eip150

Expand Down Expand Up @@ -193,13 +190,16 @@ def __call__(self, computation: BaseComputation) -> None:
code=call_data,
create_address=contract_address,
)
self.apply_create_message(computation, child_msg)

def apply_create_message(self, computation: BaseComputation, child_msg: Message) -> None:
child_computation = computation.apply_child_computation(child_msg)

if child_computation.is_error:
computation.stack_push(0)
else:
computation.stack_push(contract_address)
computation.stack_push(child_msg.storage_address)

computation.return_gas(child_computation.get_gas_remaining())


Expand Down Expand Up @@ -240,3 +240,22 @@ def generate_contract_address(self,
stack_data.salt,
call_data
)

def apply_create_message(self, computation: BaseComputation, child_msg: Message) -> None:
# We need to ensure that creation operates on empty storage **and**
# that if the initialization code fails that we revert the account back
# to its original state root.
snapshot = computation.state.snapshot()

computation.state.account_db.delete_storage(child_msg.storage_address)

child_computation = computation.apply_child_computation(child_msg)

if child_computation.is_error:
computation.state.revert(snapshot)
computation.stack_push(0)
else:
computation.state.commit(snapshot)
computation.stack_push(child_msg.storage_address)

computation.return_gas(child_computation.get_gas_remaining())

0 comments on commit 010b840

Please sign in to comment.