-
Notifications
You must be signed in to change notification settings - Fork 188
feat(tests): EIP-6110 DepositEvent layout+topic tests
#1371
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
Merged
marioevz
merged 31 commits into
ethereum:main
from
jochem-brouwer:eip6110-event-layout-tests
Apr 16, 2025
Merged
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
a150f8e
new(tests): Add EIP-6110 Sepolia Variant Contract test
marioevz 52d4ffc
fix(tests): Log code
marioevz 4b32375
fix(tests): Log code
marioevz ac1a0d1
fix: ABI encoding optional
marioevz bdc6d17
fix: parametrize for ABI (No-ABI test disabled)
marioevz badf7cf
fix(docs): add docs to helper
jochem-brouwer 2c6443c
fix(tests): lint modified_contract (?)
jochem-brouwer 98f2dd9
feat(tests): add DEPOSIT_EVENT_SIGNATURE_HASH EIP-6110
jochem-brouwer aec74d1
tmp: add sepolia deposit log data
jochem-brouwer 46e315d
change test and helper methods
jochem-brouwer 1ca916f
convert back to little-endian encoding
jochem-brouwer d4be5db
feat(helpers): add helper method to construct modified deposit logs
jochem-brouwer 2a85c2f
feat(tests): use new helper in modified contract tests
jochem-brouwer bafdb21
update test modified contract
jochem-brouwer d205135
fix test filler to produce the correct requests hash
jochem-brouwer c23faf9
feat(tests): add EIP6110 invalid event layout tests
jochem-brouwer 5a3e363
feat(tests): add exception to transaction
jochem-brouwer c50ecca
cleanup(tests): use DEFAULTs where appropriate
jochem-brouwer ea65f51
feat(tests): add invalid log length test
jochem-brouwer 9512f65
chore(tests) lint
jochem-brouwer 9b0f133
Update tests/prague/eip6110_deposits/helpers.py
jochem-brouwer ad1e86f
Update tests/prague/eip6110_deposits/helpers.py
jochem-brouwer acf8529
Update tests/prague/eip6110_deposits/test_modified_contract.py
jochem-brouwer 05a4ae8
Update tests/prague/eip6110_deposits/test_modified_contract.py
jochem-brouwer 1f6ee64
Update tests/prague/eip6110_deposits/helpers.py
jochem-brouwer 84dd1da
Update tests/prague/eip6110_deposits/helpers.py
jochem-brouwer a9273da
chore(tests): lint
jochem-brouwer ee91ad7
chore(tests): make typecheck say "congratulations"
jochem-brouwer c8fa0ec
chore(tests): add pytestmark
jochem-brouwer 4f5cc55
chore(tests): remove TODO
jochem-brouwer bbc589a
Update tests/prague/eip6110_deposits/test_modified_contract.py
marioevz 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
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
223 changes: 223 additions & 0 deletions
223
tests/prague/eip6110_deposits/test_modified_contract.py
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,223 @@ | ||
| """Test variants of the deposit contract which adheres the log-style as described in EIP-6110.""" | ||
|
|
||
| import pytest | ||
|
|
||
| from ethereum_test_exceptions.exceptions import TransactionException | ||
| from ethereum_test_tools import ( | ||
| Account, | ||
| Alloc, | ||
| Block, | ||
| BlockchainTestFiller, | ||
| Header, | ||
| Requests, | ||
| Transaction, | ||
| ) | ||
| from ethereum_test_tools import Macros as Om | ||
| from ethereum_test_tools import Opcodes as Op | ||
|
|
||
| from .helpers import DepositRequest, create_deposit_log_bytes | ||
| from .spec import Spec, ref_spec_6110 | ||
|
|
||
| pytestmark = pytest.mark.valid_from("Prague") | ||
marioevz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| REFERENCE_SPEC_GIT_PATH = ref_spec_6110.git_path | ||
| REFERENCE_SPEC_VERSION = ref_spec_6110.version | ||
|
|
||
| EVENT_ARGUMENTS_NAMES = ["pubkey", "withdrawal_credentials", "amount", "signature", "index"] | ||
| EVENT_ARGUMENTS_LAYOUT_TYPE = ["size", "offset"] | ||
| EVENT_ARGUMENTS = [ | ||
| f"{name}_{layout}" for name in EVENT_ARGUMENTS_NAMES for layout in EVENT_ARGUMENTS_LAYOUT_TYPE | ||
| ] | ||
| EVENT_ARGUMENT_VALUES = ["zero", "max_uint256"] | ||
|
|
||
|
|
||
| DEFAULT_DEPOSIT_REQUEST = DepositRequest( | ||
| pubkey=0x01, | ||
| withdrawal_credentials=0x02, | ||
| amount=120_000_000_000_000_000, | ||
| signature=0x03, | ||
| index=0x0, | ||
| ) | ||
| DEFAULT_DEPOSIT_REQUEST_LOG_DATA_DICT = { | ||
| "pubkey_data": bytes(DEFAULT_DEPOSIT_REQUEST.pubkey), | ||
| "withdrawal_credentials_data": bytes(DEFAULT_DEPOSIT_REQUEST.withdrawal_credentials), | ||
| # Note: after converting to bytes, it is converted to little-endian by `[::-1]` | ||
| # (This happens on-chain also, but this is done by the solidity contract) | ||
| "amount_data": bytes.fromhex("0" + DEFAULT_DEPOSIT_REQUEST.amount.hex()[2:])[::-1], | ||
| "signature_data": bytes(DEFAULT_DEPOSIT_REQUEST.signature), | ||
| "index_data": bytes(DEFAULT_DEPOSIT_REQUEST.index), | ||
| } | ||
| DEFAULT_REQUEST_LOG = create_deposit_log_bytes(**DEFAULT_DEPOSIT_REQUEST_LOG_DATA_DICT) # type: ignore | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "include_deposit_event", | ||
| [ | ||
| pytest.param(True), | ||
| pytest.param(False), | ||
| ], | ||
| ) | ||
| def test_extra_logs( | ||
| blockchain_test: BlockchainTestFiller, | ||
| pre: Alloc, | ||
| include_deposit_event: bool, | ||
| ): | ||
| """Test deposit contract emitting more log event types than the ones in mainnet.""" | ||
| # Supplant mainnet contract with a variant that emits a `Transfer`` log | ||
| # If `include_deposit_event` is `True``, it will also emit a `DepositEvent` log` | ||
|
|
||
| # ERC20 token transfer log (Sepolia) | ||
| # https://sepolia.etherscan.io/tx/0x2d71f3085a796a0539c9cc28acd9073a67cf862260a41475f000dd101279f94f | ||
| # JSON RPC: | ||
| # curl https://sepolia.infura.io/v3/APIKEY \ | ||
| # -X POST \ | ||
| # -H "Content-Type: application/json" \ | ||
| # -d '{"jsonrpc": "2.0", "method": "eth_getLogs", | ||
| # "params": [{"address": "0x7f02C3E3c98b133055B8B348B2Ac625669Ed295D", | ||
| # "blockHash": "0x8062a17fa791f5dbd59ea68891422e3299ca4e80885a89acf3fc706c8bceef53"}], | ||
| # "id": 1}' | ||
|
|
||
| # {"jsonrpc":"2.0","id":1,"result": | ||
| # [{"removed":false,"logIndex":"0x80","transactionIndex":"0x56", | ||
| # "transactionHash":"0x2d71f3085a796a0539c9cc28acd9073a67cf862260a41475f000dd101279f94f", | ||
| # "blockHash":"0x8062a17fa791f5dbd59ea68891422e3299ca4e80885a89acf3fc706c8bceef53", | ||
| # "blockNumber":"0x794fb5", | ||
| # "address":"0x7f02c3e3c98b133055b8b348b2ac625669ed295d", | ||
| # "data":"0x0000000000000000000000000000000000000000000000000000000000000001", | ||
| # "topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", | ||
| # "0x0000000000000000000000006885e36bfcb68cb383dfe90023a462c03bcb2ae5", | ||
| # "0x00000000000000000000000080b5dc88c98e528bf9cb4b7f0f076ac41da24651"] | ||
|
|
||
| bytecode = Op.LOG3( | ||
| # ERC-20 token transfer log | ||
| # ERC-20 token transfers are LOG3, since the topic, the sender, and receiver | ||
| # are all topics (the sender and receiver are `indexed` in the solidity event) | ||
| 0, | ||
| 32, | ||
| 0xDDF252AD1BE2C89B69C2B068FC378DAA952BA7F163C4A11628F55A4DF523B3EF, | ||
| 0x000000000000000000000000AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, | ||
| 0x000000000000000000000000BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB, | ||
| ) | ||
|
|
||
| requests = Requests() | ||
|
|
||
| if include_deposit_event: | ||
| bytecode += Om.MSTORE(DEFAULT_REQUEST_LOG) + Op.LOG1( | ||
| 0, | ||
| len(DEFAULT_REQUEST_LOG), | ||
| Spec.DEPOSIT_EVENT_SIGNATURE_HASH, | ||
| ) | ||
| requests = Requests(DEFAULT_DEPOSIT_REQUEST) | ||
| bytecode += Op.STOP | ||
|
|
||
| pre[Spec.DEPOSIT_CONTRACT_ADDRESS] = Account( | ||
| code=bytecode, | ||
| nonce=1, | ||
| balance=0, | ||
| ) | ||
| sender = pre.fund_eoa() | ||
|
|
||
| tx = Transaction( | ||
| to=Spec.DEPOSIT_CONTRACT_ADDRESS, | ||
| sender=sender, | ||
| gas_limit=100_000, | ||
| ) | ||
|
|
||
| blockchain_test( | ||
| pre=pre, | ||
| blocks=[ | ||
| Block( | ||
| txs=[tx], | ||
| header_verify=Header( | ||
| requests_hash=requests, | ||
| ), | ||
| ), | ||
| ], | ||
| post={}, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "log_argument,value", | ||
| [(log_argument, value) for log_argument in EVENT_ARGUMENTS for value in EVENT_ARGUMENT_VALUES], | ||
| ) | ||
jochem-brouwer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @pytest.mark.exception_test | ||
| def test_invalid_layout( | ||
| blockchain_test: BlockchainTestFiller, pre: Alloc, log_argument: str, value: str | ||
| ): | ||
| """Test deposit contract emitting logs with invalid layouts (sizes/offsets).""" | ||
| log_params = {**DEFAULT_DEPOSIT_REQUEST_LOG_DATA_DICT} | ||
| log_params[log_argument] = 0 if value == "zero" else 2**256 - 1 # type: ignore | ||
|
|
||
| deposit_request_log = create_deposit_log_bytes(**log_params) # type: ignore | ||
|
|
||
| bytecode = Om.MSTORE(deposit_request_log) + Op.LOG1( | ||
| 0, | ||
| len(deposit_request_log), | ||
| Spec.DEPOSIT_EVENT_SIGNATURE_HASH, | ||
| ) | ||
| bytecode += Op.STOP | ||
|
|
||
| pre[Spec.DEPOSIT_CONTRACT_ADDRESS] = Account( | ||
| code=bytecode, | ||
| nonce=1, | ||
| balance=0, | ||
| ) | ||
| sender = pre.fund_eoa() | ||
|
|
||
| tx = Transaction( | ||
| to=Spec.DEPOSIT_CONTRACT_ADDRESS, | ||
| sender=sender, | ||
| gas_limit=100_000, | ||
jochem-brouwer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| error=TransactionException.INVALID_DEPOSIT_EVENT_LAYOUT, | ||
| ) | ||
|
|
||
| blockchain_test( | ||
| pre=pre, | ||
| blocks=[ | ||
| Block(txs=[tx], exception=TransactionException.INVALID_DEPOSIT_EVENT_LAYOUT), | ||
| ], | ||
| post={}, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "slice_bytes", | ||
| [ | ||
| pytest.param(True), | ||
| pytest.param(False), | ||
| ], | ||
| ) | ||
| @pytest.mark.exception_test | ||
| def test_invalid_log_length(blockchain_test: BlockchainTestFiller, pre: Alloc, slice_bytes: bool): | ||
| """Test deposit contract emitting logs with invalid log length (one byte more or less).""" | ||
| changed_log = DEFAULT_REQUEST_LOG[:-1] if slice_bytes else DEFAULT_REQUEST_LOG + b"\x00" | ||
|
|
||
| bytecode = Om.MSTORE(changed_log) + Op.LOG1( | ||
| 0, | ||
| len(changed_log), | ||
| Spec.DEPOSIT_EVENT_SIGNATURE_HASH, | ||
| ) | ||
| bytecode += Op.STOP | ||
|
|
||
| pre[Spec.DEPOSIT_CONTRACT_ADDRESS] = Account( | ||
| code=bytecode, | ||
| nonce=1, | ||
| balance=0, | ||
| ) | ||
| sender = pre.fund_eoa() | ||
|
|
||
| tx = Transaction( | ||
| to=Spec.DEPOSIT_CONTRACT_ADDRESS, | ||
| sender=sender, | ||
| gas_limit=100_000, | ||
| error=TransactionException.INVALID_DEPOSIT_EVENT_LAYOUT, | ||
| ) | ||
|
|
||
| blockchain_test( | ||
| pre=pre, | ||
| blocks=[ | ||
| Block(txs=[tx], exception=TransactionException.INVALID_DEPOSIT_EVENT_LAYOUT), | ||
| ], | ||
| post={}, | ||
| ) | ||
Oops, something went wrong.
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.