feat(tests): converting calldataload and calldatasize tests#1236
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.
is there better way to declare bytes ? more readable
There was a problem hiding this comment.
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. |
marioevz
left a comment
There was a problem hiding this comment.
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.
| @pytest.mark.parametrize( | ||
| "args_size,sha3_len,storage", | ||
| [ | ||
| ("0002", "01", Account(storage={0x00: 0x02})), |
There was a problem hiding this comment.
| ("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_data = bytes.fromhex("1a8451e6" + "00" * 30 + args_size + "00" * 31 + sha3_len) |
There was a problem hiding this comment.
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.
@marioevz I simplified it a bit, but I'm pretty sure it's still checking correctly. Anything I'm missing?
eb7658b to
982f52f
Compare
|
lets add |
13ce646 to
b07e05c
Compare
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
marioevz
left a comment
There was a problem hiding this comment.
Hey, some comments, sorry about the back and forth but hopefully this is the last one :)
| address_b = pre.deploy_contract( | ||
| Om.MSTORE(calldata, 0x0) | ||
| + Op.CALL( | ||
| gas=Op.SUB(Op.GAS(), 0x100), | ||
| address=address_a, | ||
| value=0x0, | ||
| args_offset=0x0, | ||
| args_size=len(calldata), | ||
| ret_offset=0x0, | ||
| ret_size=0x0, | ||
| ) | ||
| ) | ||
|
|
||
| to = pre.deploy_contract( | ||
| code=( | ||
| Op.ADD(0x1000, Op.CALLDATALOAD(offset=0x4)) | ||
| + Op.CALL( | ||
| gas=Op.SUB(Op.GAS(), 0x100), | ||
| address=address_b, | ||
| value=0x0, | ||
| args_offset=0x0, | ||
| args_size=0x0, | ||
| ret_offset=0x0, | ||
| ret_size=0x0, | ||
| ) | ||
| + Op.STOP | ||
| ), | ||
| ) |
There was a problem hiding this comment.
| address_b = pre.deploy_contract( | |
| Om.MSTORE(calldata, 0x0) | |
| + Op.CALL( | |
| gas=Op.SUB(Op.GAS(), 0x100), | |
| address=address_a, | |
| value=0x0, | |
| args_offset=0x0, | |
| args_size=len(calldata), | |
| ret_offset=0x0, | |
| ret_size=0x0, | |
| ) | |
| ) | |
| to = pre.deploy_contract( | |
| code=( | |
| Op.ADD(0x1000, Op.CALLDATALOAD(offset=0x4)) | |
| + Op.CALL( | |
| gas=Op.SUB(Op.GAS(), 0x100), | |
| address=address_b, | |
| value=0x0, | |
| args_offset=0x0, | |
| args_size=0x0, | |
| ret_offset=0x0, | |
| ret_size=0x0, | |
| ) | |
| + Op.STOP | |
| ), | |
| ) | |
| to = pre.deploy_contract( | |
| Om.MSTORE(calldata, 0x0) | |
| + Op.CALL( | |
| gas=Op.SUB(Op.GAS(), 0x100), | |
| address=address_a, | |
| value=0x0, | |
| args_offset=0x0, | |
| args_size=len(calldata), | |
| ret_offset=0x0, | |
| ret_size=0x0, | |
| ) | |
| ) |
Can be simplified like this.
It might result in a drop in coverage because we eliminate the use of the ADD opcode, but it's not the focus of the test so it's ok.
Reason behind these extra contracts in the original test is because the original yml hardcoded many contracts in the same test, but it's no longer necessary.
There was a problem hiding this comment.
We could also do a variant of the test where the entry point is address_a to verify that Op.CALLDATALOAD behaves correctly when it's fetching data from the transaction's calldata.
@pytest.mark.parametrize("calldata_source", ["tx", "contract"])And if calldata_source == "tx":
tx = Transaction(
data=calldata,
gas_limit=100_000,
protected=fork >= Byzantium,
sender=pre.fund_eoa(),
to=address_a,
)And the to contract is omitted entirely.
| to = pre.deploy_contract( | ||
| code=( | ||
| Om.MSTORE(b"\x01" * args_size, 0x0) | ||
| + 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, | ||
| ) | ||
| ) | ||
| ) |
There was a problem hiding this comment.
Same comment as the other test where we can parametrize by calldata_source.
6e2c9fa to
e67cdd5
Compare
|
Hey, @marioevz, I've addressed your recent feedback. Let me know if you have more! |
|
Checking the lost coverage and it's due of the following reasons:
|
🗒️ Description
🔗 Related Issues
✅ Checklist
geth version 1.15.2-stable-c8c62dafmkdocs servelocally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.