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) Precompile Checks #1120

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

reedsa
Copy link
Contributor

@reedsa reedsa commented Jan 23, 2025

🗒️ Description

Add tests to check each precompile at specific addresses.

Tests from: https://github.com/ethereum/tests/blob/develop/src/GeneralStateTestsFiller/stPreCompiledContracts/idPrecompsFiller.yml

🔗 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.

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.

Gave this one a quick look and I wrote one comment.

We also have this similar test over here: https://github.com/ethereum/execution-spec-tests/blob/main/tests/frontier/precompiles/test_precompile_absence.py

Comment on lines 14 to 26
["address", "exists"],
[
("01", True),
("02", True),
("03", True),
("04", True),
("05", True),
("06", True),
("07", True),
("08", True),
("09", True),
("0A", True),
("0B", False),
Copy link
Member

Choose a reason for hiding this comment

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

This list would only be valid for Cancun, but we could use this marker @pytest.mark.parametrize_by_fork to dynamically generate this list by fork.

I would also reduce the amount of cases to the first exists=False fork.

@reedsa
Copy link
Contributor Author

reedsa commented Jan 24, 2025

Gave this one a quick look and I wrote one comment.

We also have this similar test over here: https://github.com/ethereum/execution-spec-tests/blob/main/tests/frontier/precompiles/test_precompile_absence.py

Those tests are very similar. Do you think it's still worth migrating these tests?

+ Op.MSTORE(gas_test, Op.GAS())
# Setup stack to CALL into precompile with the CALLDATA and CALL into it (+ pop value)
+ Op.CALL(
address=Op.CALLDATALOAD(0),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trying to pass in the precompile address in the data of the transaction for this call. It doesn't seem like I can pass the correct value from the bytes value passed, even if I try to convert the value from the CALLDATALOAD to an integer. Is there a recommendation for how to approach this?

Copy link
Contributor

Choose a reason for hiding this comment

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

here the data must be padded as EVM word of 32 bytes. so not enough just fromhex(1 byte) you need to padd it with zeros to the left. like Hash32(data, left_padding=true)

@reedsa reedsa changed the title (feat) Precompile Checks feat(tests) Precompile Checks Jan 28, 2025
@reedsa reedsa force-pushed the id-precompiles branch 3 times, most recently from dfbf4c6 to f78c534 Compare January 30, 2025 20:30
@reedsa
Copy link
Contributor Author

reedsa commented Jan 30, 2025

@winsvega @marioevz now I have the data (precompile address) being sent into the transaction. It looks like all tests are returning 0 however. Is there something I may have missed with the logic in the contract? In the original test, the gas cost difference is found based on a condition that the precompile gas is greater than the gas for the call at the address 0x10000.


"""
return [
("01", True),
Copy link
Contributor

Choose a reason for hiding this comment

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

you can access fork class from the test if you add fixture in the parameter list.
fork: Fork

and then it has a function that returns all precompiles currently active on that fork as integer list.

if_false=Op.SUB(Op.MLOAD(gas_10000), Op.MLOAD(gas_test)),
),
)
+ Op.SSTORE(0, Op.LT(Op.SLOAD(0), 0x10))
Copy link
Contributor

Choose a reason for hiding this comment

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

here also a pattern we use. there is class Storage.
so you can call Op.SSTORE(storage.store_next(expected_value, "debug hint"), logic)

Copy link
Contributor

@winsvega winsvega left a comment

Choose a reason for hiding this comment

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

added comments

@reedsa reedsa force-pushed the id-precompiles branch 2 times, most recently from 0cb561c to d2cab4a Compare February 3, 2025 21:20
Check each fork for valid precompiles
Only verify absence of precompile for one address
@reedsa
Copy link
Contributor Author

reedsa commented Feb 3, 2025

@marioevz @winsvega Latest revisions are creating parameterized tests for each fork with valid precompiles as well as a single invalid precompile. I noticed the gas cost is slightly higher than what the original tests were using. Instead of the gas being compared with 0x10 in the original test, it now checks that the cost is less than 0x1A4.

This however fails with Byzantium and Constantinople for precompile 5 and I'm not sure why.

@winsvega
Copy link
Contributor

winsvega commented Feb 3, 2025

I think the tes was not designed for that forks. Check in ethereum/legacytests if it has a revision for other forks.

But yes, need to understand what's going on

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