-
Notifications
You must be signed in to change notification settings - Fork 122
feat(tests): converting calldataload
and calldatasize
tests
#1236
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
base: main
Are you sure you want to change the base?
Conversation
91c493a
to
f6a91be
Compare
Account(storage={0x00: 0x11}), | ||
), | ||
( | ||
b"\x1a\x84Q\xe6\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00!\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01", |
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.
is there better way to declare bytes ? more readable
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.
shortened and labeled!
evmone build script failing |
OK, I think it's gtg. Still getting coverage loss though. How can I see what's lost , and is there a solution? I think my previous PR had the same issue.
|
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.
Hey, some comments which I think should make the test a bit more EEST-like, but we might lose irrelevant coverage (Like the SHA3
function which is IMO is out-of-scope for these tests) but that's ok.
|
||
Based on https://github.com/ethereum/tests/blob/ae4791077e8fcf716136e70fe8392f1a1f1495fb/src/GeneralStateTestsFiller/VMTests/vmTests/calldatacopyFiller.yml | ||
""" | ||
address_a = pre.deploy_contract(code_for_address_a) |
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.
It might be unnecessary to get the entire code as a parameter since it's very similar in all cases, so we could change it only having a calldataload_offset
parameter and change this to:
address_a = pre.deploy_contract(code_for_address_a) | |
address_a = pre.deploy_contract(Op.SSTORE(0, Op.CALLDATALOAD(calldataload_offset)) + Op.STOP) |
(Op.MSTORE8(offset=0x0, value=0x25) + Op.MSTORE8(offset=0x1, value=0x60)), | ||
0x2, |
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.
It might be better to change these two parameters to a single one called calldata
, which could contain a bytes
value as follows:
- two_bytes: b'\x25\x60'
- word_n_byte: b'\xff' * 32 + b'\x23'
- 34_bytes: bytes.fromhex('123456789ABCDEF00000000000000000000000000000000000000000000000000024')
or something similar, then in the code we could use the Om.MSTORE(calldata, 0x00)
(Macros can be imported by from ethereum_test_tools import Macros as Om
) to put the call data in memory and args_size = len(calldata)
, then finally Op.CALL
to the address_a
.
Advantages to this method are:
- IMO it makes it easier to understand what the test is trying to verify by showing exactly what the calldata is when calldataload is being called.
- We can parametrize for generate a test where
address_a
is the entry point of the transaction andcalldata
is the data of the transaction.
) | ||
|
||
tx = Transaction( | ||
data=tx_data, |
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 think tx_data
is not really used anywhere and could be safely removed.
But ideally it should be replaced by calldata
as described in the previous comment π
Account( | ||
storage={0x00: 0x2560000000000000000000000000000000000000000000000000000000000000} | ||
), |
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.
Could be simplified to:
Account( | |
storage={0x00: 0x2560000000000000000000000000000000000000000000000000000000000000} | |
), | |
0x2560000000000000000000000000000000000000000000000000000000000000, |
And then the function defines the Account(storage=...
part.
@pytest.mark.parametrize( | ||
"args_size,sha3_len,storage", | ||
[ | ||
("0002", "01", Account(storage={0x00: 0x02})), |
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.
("0002", "01", Account(storage={0x00: 0x02})), | |
("0002", "01", 0x02), |
Similar comment to previous file, Account(storage=...
can be defined inside the function to make the parametrization more readable.
tx = Transaction( | ||
data=tx_data, | ||
gas_limit=100_000, | ||
gas_price=0x0A, |
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.
gas_price=0x0A, |
Can be safely removed, so we can execute this same test in other environments.
protected=fork >= Byzantium, | ||
sender=pre.fund_eoa(), | ||
to=to, | ||
value=0x01, |
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.
value=0x01, |
I think this can also be safely removed since it's not used anywhere.
) | ||
) | ||
) | ||
tx_data = bytes.fromhex("1a8451e6" + "00" * 30 + args_size + "00" * 31 + sha3_len) |
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.
No need to encode this as call data to be decoded by the contract, args_size
and sha3_len
could be integers and they could be placed inside of the contract directly:
to = pre.deploy_contract(
code=(
Op.MSTORE(offset=0x0, value=Op.SHA3(offset=0x0, size=sha3_len))
+ Op.CALL(
gas=Op.SUB(Op.GAS(), 0x100),
address=address,
value=0x0,
args_offset=0x0,
args_size=args_size,
ret_offset=0x0,
ret_size=0x0,
)
)
)
Although I'm having trouble understanding why the original test is using SHA3
in the first place since the memory contents are irrelevant, and my best guess is to just have a non-zero filled memory.
I think we should replace all of this with calldata
just like the comment in test_calldataload.py
, and also parametrize this function to test calldatasize at the top-level call (returns len(tx.data)
) or a sub-level call (returns arg_size).
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 I simplified it a bit, but I'm pretty sure it's still checking correctly. Anything I'm missing?
f21d975
to
de67c5c
Compare
lets add |
Not all fixed, but better. Thanks! before:
after:
|
Latest coverage fail:
Looking into it: expected:
unknown:
I'll keep poking, but if you know whether the last 2 can be fixed or should be ignored, let me know! |
About sha3 I don't get what are the inputs for call in Oris test. |
calldataload
and calldatasize
testscalldataload
and calldatasize
tests
ποΈ Description
π Related Issues
β Checklist
geth version 1.15.2-stable-c8c62daf
mkdocs serve
locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.