-
Notifications
You must be signed in to change notification settings - Fork 107
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
base: main
Are you sure you want to change the base?
Conversation
4ade831
to
ccb6574
Compare
There was a problem hiding this 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
["address", "exists"], | ||
[ | ||
("01", True), | ||
("02", True), | ||
("03", True), | ||
("04", True), | ||
("05", True), | ||
("06", True), | ||
("07", True), | ||
("08", True), | ||
("09", True), | ||
("0A", True), | ||
("0B", False), |
There was a problem hiding this comment.
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.
ccb6574
to
473e19f
Compare
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), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
dfbf4c6
to
f78c534
Compare
@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 |
|
||
""" | ||
return [ | ||
("01", True), |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added comments
d2cab4a
to
e43edba
Compare
@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 This however fails with Byzantium and Constantinople for precompile 5 and I'm not sure why. |
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 |
e43edba
to
9372ea0
Compare
Contract compares gas cost for each precompile. Only checks a single unsupported precompile address.
9372ea0
to
cc74bbb
Compare
""" | ||
supported_precompiles = fork.precompiles() | ||
|
||
for address in range(1, len(supported_precompiles) + 2): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why +2
and what if precompiles are ranges [1..to 11], [100 to 112]
gas_10000 = 0x20 | ||
|
||
account = pre.deploy_contract( | ||
Op.MSTORE(gas_test, Op.GAS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marioevz it works Op.GAS
as well as Op.GAS()
?
output_offset=output_offset, | ||
output_size=output_size, | ||
) | ||
+ Op.MSTORE(gas_10000, Op.SUB(Op.GAS, Op.MLOAD(gas_10000))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you get negative value here
// If the VS Code "Run and Debug" button, respecively launch selector are not visible, see this answer: | ||
// https://stackoverflow.com/a/74245823 | ||
// | ||
"version": "0.2.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the settings got exported?
""" | ||
env = Environment() | ||
|
||
args_offset = 0x1000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you didn't want to copy, but then you can actually use default values of this args leaving it empty.
and it is always good when reading the code If it is visible what is the offset without scrolling up to the defenition (IMHO), then the call would fit in one line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when implementing test for the first time, we, actually take our understanding of vm for granted, but newcomers must use vmtrace. and it always good to use vmtrace to see what is actually happening. (yes by now we have little compiler in our head)
I remember the first year I was using vmtrace all the time, it is essential to get an idea of what is going on and how your code is executed.
saying that we might want to use/develop better tools for vmtrace visualizing and debugging. and manuals.
🗒️ Description
Add tests to check each precompile at specific addresses.
Tests from: https://github.com/ethereum/tests/blob/develop/src/GeneralStateTestsFiller/stPreCompiledContracts/idPrecompsFiller.yml
Removed in:
ethereum/tests#1444
🔗 Related Issues
✅ Checklist
mkdocs serve
locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.