-
Notifications
You must be signed in to change notification settings - Fork 649
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
Py evm 1466 #1799
Open
dherykw
wants to merge
6
commits into
ethereum:main
Choose a base branch
from
dherykw:py-evm-1466
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Py evm 1466 #1799
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
39fdd9f
Update the contract limit size to follow EIP170. Add tests against th…
glaksmono 43f379b
Added test for computation.output EIP170_CODE_SIZE_LIMIT
b9cdb6f
Adding comment suggestions
8f65b4e
Merge branch 'master' of https://github.com/ethereum/py-evm into py-e…
92c142f
Updated state.set_balance
435058d
Cleaning print flags
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from unittest import mock | ||
|
||
import pytest | ||
from eth_utils import ( | ||
to_canonical_address, | ||
) | ||
|
||
from eth import ( | ||
Chain, | ||
) | ||
from eth.vm.computation import ( | ||
BaseComputation, | ||
) | ||
from eth.vm.forks.spurious_dragon.computation import ( | ||
SpuriousDragonComputation, | ||
) | ||
from eth.vm.forks.spurious_dragon.constants import ( | ||
EIP170_CODE_SIZE_LIMIT | ||
) | ||
from eth.vm.message import ( | ||
Message, | ||
) | ||
from eth.vm.transaction_context import ( | ||
BaseTransactionContext, | ||
) | ||
|
||
NORMALIZED_ADDRESS_A = "0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" | ||
NORMALIZED_ADDRESS_B = "0xcd1722f3947def4cf144679da39c4c32bdc35681" | ||
CANONICAL_ADDRESS_A = to_canonical_address(NORMALIZED_ADDRESS_A) | ||
CANONICAL_ADDRESS_B = to_canonical_address(NORMALIZED_ADDRESS_B) | ||
|
||
|
||
@pytest.fixture | ||
def make_computation(): | ||
message = Message( | ||
to=CANONICAL_ADDRESS_B, | ||
sender=CANONICAL_ADDRESS_A, | ||
value=1, | ||
data=b'', | ||
code=b'', | ||
gas=5000000, | ||
) | ||
transaction_context = BaseTransactionContext(gas_price=1, origin=CANONICAL_ADDRESS_B, ) | ||
|
||
def _make_computation(chain) -> BaseComputation: | ||
state = chain.get_vm().state | ||
state.set_balance(CANONICAL_ADDRESS_A, 1000) | ||
computation = SpuriousDragonComputation( | ||
state=state, | ||
message=message, | ||
transaction_context=transaction_context, | ||
) | ||
|
||
return computation | ||
|
||
return _make_computation | ||
|
||
|
||
@pytest.mark.parametrize('chain_without_block_validation', [Chain, ], indirect=True) | ||
@pytest.mark.parametrize( | ||
'computation_output', | ||
[ | ||
b'\x00' * (EIP170_CODE_SIZE_LIMIT + 1), | ||
b'\x00' * EIP170_CODE_SIZE_LIMIT, | ||
b'\x00' * (EIP170_CODE_SIZE_LIMIT - 1), | ||
] | ||
) | ||
def test_computation_output_size_limit(chain_without_block_validation, | ||
make_computation, | ||
computation_output): | ||
computation: BaseComputation = make_computation(chain_without_block_validation) | ||
computation.output = computation_output | ||
|
||
with mock.patch.object(SpuriousDragonComputation, 'apply_message', return_value=computation): | ||
computation.apply_create_message() | ||
|
||
if len(computation_output) >= EIP170_CODE_SIZE_LIMIT: | ||
assert computation.is_error | ||
else: | ||
assert not computation.is_error |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mock based approaches tend to be problematic. I'd prefer we test this properly using a contract that actually exceeds this limit so that we can see this fail using non-mock/real mechanisms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nothing related to this comment and I agree with piper here, but here's a nice article I found on mocking today written by Ned Batchelder: https://nedbatchelder.com/blog/201908/why_your_mock_doesnt_work.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries @pipermerriam and @voith, currently I am out of my town with limited connectivity, but next week I will give it another try. It will help me to have a better understanding of the code and help with more complicated task.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello guys,
I am stuck for a while, I am trying to deploy a dummy contract to the chain but I am receiving a huge out of gas error. I have introduced the question on stack exchange:
https://ethereum.stackexchange.com/questions/74091/deploy-contract-in-py-evm?noredirect=1#comment90183_74091
The full "test" code (because I haven introduces the asserts yet) is:
I would appreciate any help :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dherykw how did you go about getting that deployment bytecode. My guess is that there's something wrong with it. The error you're receiving is a standard EVM error so it's probably worth you trying to trace the VM execution to figure out why it's trying to expand the memory to such a large size.