-
Notifications
You must be signed in to change notification settings - Fork 686
[WIP] Update the contract limit size to follow EIP170 and add tests against it #1483
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ | |
|
||
|
||
# https://github.com/ethereum/EIPs/issues/170 | ||
EIP170_CODE_SIZE_LIMIT = 24577 | ||
EIP170_CODE_SIZE_LIMIT = 24576 | ||
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,85 @@ | ||||||
import pytest | ||||||
|
||||||
from eth_utils import ( | ||||||
to_canonical_address, | ||||||
) | ||||||
|
||||||
from eth.vm.message import ( | ||||||
Message, | ||||||
) | ||||||
|
||||||
from eth.vm.forks.spurious_dragon.computation import ( | ||||||
SpuriousDragonComputation, | ||||||
) | ||||||
|
||||||
from eth.vm.transaction_context import ( | ||||||
BaseTransactionContext, | ||||||
) | ||||||
|
||||||
|
||||||
NORMALIZED_ADDRESS_A = "0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" | ||||||
NORMALIZED_ADDRESS_B = "0xcd1722f3947def4cf144679da39c4c32bdc35681" | ||||||
CANONICAL_ADDRESS_A = to_canonical_address("0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
CANONICAL_ADDRESS_B = to_canonical_address("0xcd1722f3947def4cf144679da39c4c32bdc35681") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
CONTRACT_CODE_A = b"" | ||||||
CONTRACT_CODE_B = b"" | ||||||
CONTRACT_CODE_C = b"" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pipermerriam Would like to get suggestion on what is the best way of having different kinds of contract code in our tests. Do we usually just hardcode the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typically yes. I assume we don't need complex code and we could just do something like: |
||||||
|
||||||
|
||||||
@pytest.fixture | ||||||
def state(chain_without_block_validation): | ||||||
state = chain_without_block_validation.get_vm().state | ||||||
state.account_db.set_balance(CANONICAL_ADDRESS_A, 1000) | ||||||
return state | ||||||
|
||||||
|
||||||
@pytest.fixture | ||||||
def transaction_context(): | ||||||
tx_context = BaseTransactionContext( | ||||||
gas_price=1, | ||||||
origin=CANONICAL_ADDRESS_B, | ||||||
) | ||||||
return tx_context | ||||||
|
||||||
|
||||||
def test_code_size_limit(transaction_context, state): | ||||||
""" | ||||||
CONTRACT_CODE_A size is greater than EIP170_CODE_SIZE_LIMIT | ||||||
""" | ||||||
message_contract_code_a = Message( | ||||||
to=CANONICAL_ADDRESS_A, | ||||||
sender=CANONICAL_ADDRESS_B, | ||||||
value=100, | ||||||
data=b'', | ||||||
code=CONTRACT_CODE_A, | ||||||
gas=100, | ||||||
) | ||||||
computation = SpuriousDragonComputation( | ||||||
state=state, | ||||||
message=message_contract_code_a, | ||||||
transaction_context=transaction_context, | ||||||
) | ||||||
|
||||||
""" | ||||||
TODO: CONTRACT_CODE_B size is equal to EIP170_CODE_SIZE_LIMIT | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test should probably be parametrized (or use a parametrized fixture) instead of testing all three in the same test. |
||||||
""" | ||||||
message_contract_code_b = Message( | ||||||
to=CANONICAL_ADDRESS_A, | ||||||
sender=CANONICAL_ADDRESS_B, | ||||||
value=100, | ||||||
data=b'', | ||||||
code=CONTRACT_CODE_B, | ||||||
gas=100, | ||||||
) | ||||||
|
||||||
""" | ||||||
TODO: CONTRACT_CODE_C size is lower than EIP170_CODE_SIZE_LIMIT | ||||||
""" | ||||||
message_contract_code_c = Message( | ||||||
to=CANONICAL_ADDRESS_A, | ||||||
sender=CANONICAL_ADDRESS_B, | ||||||
value=100, | ||||||
data=b'', | ||||||
code=CONTRACT_CODE_C, | ||||||
gas=100, | ||||||
) |
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.