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

convert calldatacopy test #1056

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

Conversation

pacrob
Copy link
Contributor

@pacrob pacrob commented Jan 7, 2025

🗒️ Description

Converts calldatacopy tests from here

Questions:

  • I'm not sure why tests before Byzantium are failing.
  • If the file is to be deleted from ethereum/tests, how should I reference the source in the docstring?
  • I'm not sure how to address the coverage CI failure. I tried running it locally but didn't get any more clarifying info from it.

🔗 Related Issues

✅ Checklist

  • All: Set appropriate labels for the changes.
  • All: Considered squashing commits to improve commit history.
  • All: Added an entry to CHANGELOG.md.
  • All: Considered updating the online docs in the ./docs/ directory.
  • Tests: All converted JSON/YML tests from ethereum/tests have been added to converted-ethereum-tests.txt.
  • Tests: A PR with removal of converted JSON/YML tests from ethereum/tests have been opened.
  • Tests: Included the type and version of evm t8n tool used to locally execute test cases: e.g., ref with commit hash or geth 1.13.1-stable-3f40e65.
  • Tests: Ran mkdocs serve locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.

@pacrob pacrob force-pushed the convert-calldata-tests branch from 8442fde to 26070d9 Compare January 7, 2025 17:31
@pacrob pacrob force-pushed the convert-calldata-tests branch from ada2d17 to a8cb99b Compare January 7, 2025 18:44
@pacrob pacrob changed the title convert calldatacopy from yml convert calldatacopy test Jan 7, 2025
Copy link
Member

@marioevz marioevz 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 this! I've left some comments to make the code more readable, I can fully review once these are applied 👍

docs/CHANGELOG.md Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
Comment on lines 15 to 18
Op.PUSH1[0x2]
+ Op.PUSH1[0x1]
+ Op.PUSH1[0x0]
+ Op.CALLDATACOPY
Copy link
Member

Choose a reason for hiding this comment

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

Can be rewritten as:

Suggested change
Op.PUSH1[0x2]
+ Op.PUSH1[0x1]
+ Op.PUSH1[0x0]
+ Op.CALLDATACOPY
Op.CALLDATACOPY(dest_offset=0, offset=1, size=2)

Improves readability a bit IMO.

Comment on lines 23 to 25
+ Op.MSIZE
+ Op.PUSH1[0x0]
+ Op.RETURN
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
+ Op.MSIZE
+ Op.PUSH1[0x0]
+ Op.RETURN
+ Op.RETURN(offset=0, size=Op.MSIZE)

Also here and for the rest of the bytecodes.

+ Op.MSIZE
+ Op.PUSH1[0x0]
+ Op.RETURN
+ Op.STOP
Copy link
Member

Choose a reason for hiding this comment

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

This can be removed because RETURN is a terminating opcode, and if the test gets automatically converted to EOF it could be annoying.

Suggested change
+ Op.STOP

tx_data: bytes,
pre: Alloc,
code_address_storage: Account,
to_address_storage: Account,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
to_address_storage: Account,
to_address_storage: Account | None,

From some of the parametrized values.

+ Op.PUSH2[0x1000]
+ Op.ADD
+ Op.PUSH3[0xFFFFFF]
+ Op.CALL
Copy link
Member

Choose a reason for hiding this comment

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

I think this and most if not all lines above can be rewritten using parentheses like Op.CALL(0xFFFFFF, Op.ADD( ....

+ Op.STOP
),
nonce=0,
balance=0x0BA1A9CE0BA1A9CE,
Copy link
Member

Choose a reason for hiding this comment

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

I think this amount of balance might be unnecessary.

A bit of background is that this value was common in ethereum/tests, but now we can use the execute command to send these transactions to a live network, and if we use this amount the pre-deploy account has to be funded with this. So it's better to keep it to the minimum necessary.

data=tx_data,
gas_limit=0x04C4B400,
gas_price=0x0A,
nonce=0x00,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
nonce=0x00,

Can be removed since the sender that is returned by pre.fund_eoa() has a nonce counter that is automatically increased and used for each transaction that is generated with it.


tx = Transaction(
data=tx_data,
gas_limit=0x04C4B400,
Copy link
Member

Choose a reason for hiding this comment

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

I think this also can be reduced due to similar reason as the balance of the contract.

Suggested change
gas_limit=0x04C4B400,
gas_limit=100_000,

@marioevz
Copy link
Member

marioevz commented Jan 8, 2025

Questions:

  • I'm not sure why tests before Byzantium are failing.

This could potentially be due to the protected field in the transaction, since I think the transactions can only be protected on Byzantium and afterwards. You can try protected=fork>=Byzantium in the transaction building call (requires adding fork: Fork as parameter to the test function, and importing Fork from ethereum_test_forks).

  • If the file is to be deleted from ethereum/tests, how should I reference the source in the docstring?

We could use the permalink to the file: https://github.com/ethereum/tests/blob/ae4791077e8fcf716136e70fe8392f1a1f1495fb/src/GeneralStateTestsFiller/VMTests/vmTests/calldatacopyFiller.yml

  • I'm not sure how to address the coverage CI failure. I tried running it locally but didn't get any more clarifying info from it.

This might be because of the way the code is compiled for the ethereum/tests version of the test, so there's a difference between the opcodes used, but we could analyze the result and if deemed unimportant we can merge as is, no problem.

@pacrob pacrob force-pushed the convert-calldata-tests branch from c5aa077 to 1f652aa Compare January 8, 2025 21:13
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.

2 participants