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

Merged
merged 6 commits into from
Jan 23, 2025
Merged

Conversation

pacrob
Copy link
Contributor

@pacrob pacrob commented Jan 7, 2025

🗒️ Description

Converts calldatacopy tests from here

PR to delete from ethereum/tests is here

Tests pass run against evm statetest and evm blocktest geth version 1.14.12-stable-293a300d

Questions:

  • 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 2 times, most recently 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
tests/frontier/opcodes/test_calldatacopy.py Outdated Show resolved Hide resolved
tests/frontier/opcodes/test_calldatacopy.py Outdated Show resolved Hide resolved
tests/frontier/opcodes/test_calldatacopy.py Outdated Show resolved Hide resolved
tests/frontier/opcodes/test_calldatacopy.py Outdated Show resolved Hide resolved
tests/frontier/opcodes/test_calldatacopy.py Outdated Show resolved Hide resolved
tests/frontier/opcodes/test_calldatacopy.py Outdated Show resolved Hide resolved
tests/frontier/opcodes/test_calldatacopy.py Outdated Show resolved Hide resolved
tests/frontier/opcodes/test_calldatacopy.py Outdated Show resolved Hide resolved
@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
@winsvega
Copy link
Contributor

winsvega commented Jan 9, 2025

or you can reference legacy test file. because ethereum/tests:: develop tests are essentially a copy of tests in legacytests/cancun.
legacytests are frozen from modifications
ethereum/tests are to be converted to .py and deleted. so no development or new modifications

@pacrob pacrob force-pushed the convert-calldata-tests branch from dd2223f to a011f44 Compare January 10, 2025 23:34
@pacrob pacrob force-pushed the convert-calldata-tests branch 3 times, most recently from 34e9230 to 83f2ab6 Compare January 14, 2025 16:56
@pacrob pacrob force-pushed the convert-calldata-tests branch from 83f2ab6 to 1a2026b Compare January 14, 2025 16:57
@pacrob pacrob marked this pull request as ready for review January 14, 2025 20:26
@pacrob
Copy link
Contributor Author

pacrob commented Jan 14, 2025

OK! I've addressed all the comments. Last questions from the checklist:

  • I can't set tags. What should they be?
  • How do you want the tests to be run? I've successfully fed them to evm statetest and evm blocktest (geth version 1.14.12-stable-293a300d), but not sure how to use a filled test file with the geth t8n tool.
  • mkdocs serve runs fine, but there doesn't seem to be any documentation generated in this case. Is that correct?

Also, I got the last failing tests to run by raising the gas limit in the tx from 100_000 to 100_000_000, but didn't try anything in between. Is it important here to try to be specific in the gas amount, or is just adding a bunch OK?

@marioevz
Copy link
Member

Hey! thanks, giving it another look just now :)

  • I can't set tags. What should they be?
    Do you mean the ones in the PR? I think it should be ok to set the labels to scope: tests.
  • How do you want the tests to be run? I've successfully fed them to evm statetest and evm blocktest (geth version 1.14.12-stable-293a300d), but not sure how to use a filled test file with the geth t8n tool.

This is perfect, evm statetest and evm blocktest should be more than enough.

  • mkdocs serve runs fine, but there doesn't seem to be any documentation generated in this case. Is that correct?

I tried it out and it generated ok, checkout "Test Case Reference":
image

Then in the sidebar you should see the test case you wrote here:
image

Also, I got the last failing tests to run by raising the gas limit in the tx from 100_000 to 100_000_000, but didn't try anything in between. Is it important here to try to be specific in the gas amount, or is just adding a bunch OK?

If there's no way around it then it's ok to add a bunch of gas, but if we can keep the gas limit to less than 30,000,000 it means that the test can run in live networks.
Otherwise we can just add the

@pytest.mark.execute(pytest.mark.skip("too much gas"))

marker (the string is not standardized) and it should be gracefully skipped when running in live networks. 👍

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.

Hey looks good so far, I have a couple more comments.

The gas issue I haven't been able to figure out but one thing that we could to is just limit the test to be filled only on Byzantium and after.

Let me know what you think.

tests/frontier/opcodes/test_calldatacopy.py Outdated Show resolved Hide resolved
tests/frontier/opcodes/test_calldatacopy.py Outdated Show resolved Hide resolved
tests/frontier/opcodes/test_calldatacopy.py Outdated Show resolved Hide resolved
tests/frontier/opcodes/test_calldatacopy.py Outdated Show resolved Hide resolved
@marioevz
Copy link
Member

Figured out the gas issue: It seems like passing something above the current available gas results in the CALL opcode charging a really high amount of gas in Frontier and Homestead, which I think was fixed in Byzantium with EIP-150.

The solution seems to be something along the lines of:

Op.CALL(
                gas=Op.SUB(Op.GAS(), 0x100),
                address=code_address,
                value=0x0,
                args_offset=0xF,
                args_size=0x10,
                ret_offset=0x20,
                ret_size=0x40,
            )

so the call does not try to send a gas amount higher than it currently gas.

With this change, sending the transaction with a gas limit of 100_000 works for all tests 🎉

@pacrob
Copy link
Contributor Author

pacrob commented Jan 21, 2025

OK! All requested updates pushed. I found them in docs, just didn't know where to look 😄

@winsvega
Copy link
Contributor

the only missing coverage is calldataload and add opcodes. can be ignored.

@winsvega winsvega requested a review from marioevz January 23, 2025 11:58
docs/CHANGELOG.md Outdated Show resolved Hide resolved
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.

LGTM, thanks!

@pacrob
Copy link
Contributor Author

pacrob commented Jan 23, 2025

Thanks for updating the gas, @marioevz - guess I got it in the one place and missed the other.

@marioevz
Copy link
Member

I've verified the coverage loss and it's down to a couple of things:

  • The ADD and CALLDATALOAD opcodes are no longer used, which is ok
  • There are no empty accounts in the test's pre-state, also ok
  • MPT state differences (due to different accounts used), also ok

We should be able to merge without issues 👍

@marioevz marioevz merged commit f6297b2 into ethereum:main Jan 23, 2025
11 of 12 checks passed
fselmo pushed a commit to fselmo/execution-spec-tests that referenced this pull request Jan 24, 2025
* convert calldatacopy from yml

* adding gas to tx gets everything passing

* review updates

* Update tests/frontier/opcodes/test_calldatacopy.py

* Update docs/CHANGELOG.md

---------

Co-authored-by: winsvega <[email protected]>
Co-authored-by: Mario Vega <[email protected]>
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