-
Notifications
You must be signed in to change notification settings - Fork 169
feat(tests): add first few single-opcode test for state access in BloatNet #2040
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
Open
gballet
wants to merge
29
commits into
ethereum:main
Choose a base branch
from
gballet:bloatnet-test-SSTORE
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.
+383
β0
Open
Changes from 18 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
a1f2153
Add BloatNet tests
gballet 02d65b4
try building the contract
gballet e721cc6
fix: SSTORE 0 -> 1 match all values in the state
gballet d1cad25
add the tx for 0 -> 1 and 1 -> 2
gballet 16f6d30
fix: linter issues
gballet 374e08a
remove more whitespaces
gballet 333c876
fix formatting
gballet 79a95b8
move to benchmarks
gballet 8131e98
fix linter value
gballet 5f805fd
use the gas limit from the environment
gballet 090a400
parameterize the written value in SSTORE
gballet cd02a02
fix linter issues
gballet 1f3c381
update CHANGELOG.md
gballet f6def7e
fix format
gballet 7e20a50
simplify syntax
gballet c24ad35
fix: start with an empty contract storage
gballet fc27e53
more fixes, but the result is still incorrect
gballet 7d87262
fix: finally fix the tests
gballet 8556014
linter fix
gballet 326915e
add SLOAD tests
gballet bc7ee84
Merge branch 'main' into bloatnet-test-SSTORE
gballet 4164f3c
review feedback
gballet 6d12da6
more review feedback
gballet b3aa527
refactor(tests): Proposed patch for bloatnet SSTORE tests (#1)
fselmo add1a36
mandatory linter issue fix
gballet 134dc8c
fix SLOAD test
gballet 20c47b7
fix linter issue
gballet f668f86
break sload tests in multiple txs
gballet edfc381
fix doc issue in CI
gballet 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 hidden or 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 hidden or 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 @@ | ||
""" | ||
abstract: Tests [EIP-8047 BloatNet](https://eips.ethereum.org/EIPS/eip-8047) | ||
Test cases for [EIP-8047 BloatNet](https://eips.ethereum.org/EIPS/eip-8047)]. | ||
""" | ||
|
||
import pytest | ||
|
||
from ethereum_test_forks import Fork | ||
from ethereum_test_tools import ( | ||
Account, | ||
Alloc, | ||
Block, | ||
BlockchainTestFiller, | ||
Environment, | ||
Storage, | ||
Transaction, | ||
) | ||
from ethereum_test_tools.vm.opcode import Opcodes as Op | ||
|
||
REFERENCE_SPEC_GIT_PATH = "DUMMY/eip-DUMMY.md" | ||
fselmo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
REFERENCE_SPEC_VERSION = "0.1" | ||
gballet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
@pytest.mark.valid_from("Prague") | ||
@pytest.mark.parametrize("final_storage_value", [0x02 << 248, 0x02]) | ||
def test_bloatnet( | ||
blockchain_test: BlockchainTestFiller, pre: Alloc, fork: Fork, final_storage_value: int | ||
fselmo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
): | ||
""" | ||
A test that calls a contract with many SSTOREs. | ||
|
||
The first block will have many SSTORES that go from 0 -> 1 | ||
fselmo marked this conversation as resolved.
Show resolved
Hide resolved
fselmo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
and the 2nd block will have many SSTORES that go from 1 -> 2 | ||
""" | ||
# Get gas costs for the current fork | ||
gas_costs = fork.gas_costs() | ||
|
||
# this is only used for computing the intinsic gas | ||
data = final_storage_value.to_bytes(32, "big").rstrip(b"\x00") | ||
|
||
storage = Storage() | ||
|
||
totalgas = gas_costs.G_BASE * 2 + gas_costs.G_VERY_LOW # Initial gas for PUSH0 + CALLDATALOAD + POP (at the end) | ||
totalgas = totalgas + fork.transaction_intrinsic_cost_calculator()(calldata=data); | ||
gas_increment = gas_costs.G_VERY_LOW * 2 + gas_costs.G_STORAGE_SET + gas_costs.G_COLD_SLOAD | ||
sstore_code = Op.PUSH0 + Op.CALLDATALOAD | ||
storage_slot: int = 0 | ||
while totalgas + gas_increment < Environment().gas_limit: | ||
fselmo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
totalgas += gas_increment | ||
sstore_code = sstore_code + Op.SSTORE(storage_slot, Op.DUP1) | ||
storage[storage_slot] = final_storage_value | ||
storage_slot += 1 | ||
|
||
sstore_code = sstore_code + Op.POP # Drop last value on the stack | ||
|
||
sender = pre.fund_eoa() | ||
print(sender) | ||
fselmo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
contract_address = pre.deploy_contract( | ||
code=sstore_code, | ||
storage=Storage(), | ||
gballet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
tx_0_1 = Transaction( | ||
to=contract_address, | ||
gas_limit=Environment().gas_limit, | ||
data=(final_storage_value // 2).to_bytes(32, "big").rstrip(b"\x00"), | ||
value=0, | ||
sender=sender, | ||
) | ||
tx_1_2 = Transaction( | ||
to=contract_address, | ||
gas_limit=Environment().gas_limit, | ||
data=final_storage_value.to_bytes(32, "big").rstrip(b"\x00"), | ||
value=0, | ||
sender=sender, | ||
) | ||
|
||
post = {contract_address: Account(storage=storage)} | ||
|
||
blockchain_test(pre=pre, blocks=[Block(txs=[tx_0_1, tx_1_2])], post=post) |
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.
Uh oh!
There was an error while loading. Please reload this page.