Skip to content
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

feat(tests): Add Tests for STOP Opcode and Blob Data Handling in Shard Blob Transactions for EIP-4844 #977

Closed
wants to merge 1 commit into from

Conversation

jcqln2
Copy link

@jcqln2 jcqln2 commented Nov 28, 2024

🗒️ Description

This test covers:

  • Transactions containing blob data with KZG commitments and proofs
  • Validation of STOP opcode (0x00) in transaction data
  • Execution simulation to verify that transactions with the STOP opcode halt as expected

🔗 Related Issues

Copy link
Member

@danceratopz danceratopz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @jcqln2! I appreciate your ambition in tackling a complex task like testing an opcode within a blob transaction!

While your test test_stop_opcode_with_transaction fills correctly and passes when executed against clients, it seems that it's not testing the opcode execution as intended. The reason is that the bytecode provided in the calldata (tx.data) isn't executed when sent to an EOA address. In Ethereum, only contract accounts execute code upon receiving a transaction.

In your current implementation, the transaction sends calldata to an EOA (to="0x000000000000000000000000000000000000dead"), but EOAs do not execute code. Although a contract creation transaction would execute the initcode that is set as part of tx.data, as per the EIP-4844 specification, type 3 transactions (blob transactions) cannot be contract creation transactions (where to=None). This means we need an alternative approach to test opcode execution within a blob transaction.

Here are a couple of paths you might explore:

  1. To align the test with your original intention: Deploy a contract with the desired bytecode in the pre-state allocation. Then, send a transaction to this contract's address to trigger code execution. You can refer to this example where a contract is deployed and interacted with:

    contract_address = pre.deploy_contract(Op.SSTORE(1, Op.CHAINID) + Op.STOP)
    sender = pre.fund_eoa()
    tx = Transaction(
    ty=0x0,
    chain_id=0x01,
    to=contract_address,
    gas_limit=100000000,
    gas_price=10,
    sender=sender,

  2. Alternatively, modify the test to focus on a specific behavior that is permissible within the constraints of EIP-4844.

If time permits, to verify what the EVM is executing during the test, you can use Geth's evm tool.

Here's how you can use it:

  1. Install/download geth (note geth is no longer a prerequisite for filling - this is an old version of the docs): https://ethereum.github.io/execution-spec-tests/v3.0.0/getting_started/quick_start/

  2. Fill the test using Geth's evm t8n command instead of EELS to get execution traces:

    fill tests/cancun/eip4844_blobs/eip4844_stopblob.py --evm-bin=~/bin/go-ethereum/bin/evm --traces --evm-dump-dir=/tmp/debug
    
  3. Inspect the trace file to see if the EVM executed any code. If the EVM didn't use any gas, it indicates no execution took place (/tmp/debug/cancun__eip4844_blobs__eip4844_stopblob__test_stop_opcode_with_transaction/fork_Cancun_blockchain_test/0/trace-0-0xce0288fdff9e0b7b3ec1bb8663b645d651da5a54df6941403dc1cc604267db2d.jsonl).

Alternatively, you can use consume to execute the test against Geth's evm blocktest command:

consume direct --input=fixtures/blockchain_tests/cancun/eip4844_blobs/eip4844_stopblob/  --evm-bin=~/bin/go-ethereum/bin/evm -k blockchain_test -v

Edit: Instead of consume, it's easier to run evm blocktest directly:

evm --json --debug --verbosity 100 blocktest fixtures/blockchain_tests/cancun/eip4844_blobs/eip4844_stopblob/stop_opcode_with_transaction.json

@danceratopz
Copy link
Member

Edit: Instead of consume, it's easier to run evm blocktest directly:

evm --json --debug --verbosity 100 blocktest fixtures/blockchain_tests/cancun/eip4844_blobs/eip4844_stopblob/stop_opcode_with_transaction.json

@jcqln2 - just so you don't miss it, I made a small edit above.

@jcqln2
Copy link
Author

jcqln2 commented Nov 29, 2024

Thanks for the feedback, I'll try to modify and commit changes today by my midday (EST)

@danceratopz
Copy link
Member

Thanks for the feedback, I'll try to modify and commit changes today by my midday (EST)

As I mentioned in DMs, feel free to take as much time as you like/can afford 👍

@danceratopz
Copy link
Member

Closing in favor of #982.

@danceratopz danceratopz closed this Dec 2, 2024
@danceratopz danceratopz changed the title feat(tests): STOP- assignment- Add Tests for STOP Opcode and Blob Data Handling in Shard Blob Transactions for EIP-4844 feat(tests): Add Tests for STOP Opcode and Blob Data Handling in Shard Blob Transactions for EIP-4844 Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants