Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Hey @reednaa, in general I think including assembly adds some complexity to readers, so I believe it would be better to keep the cast as
And also the docs on casting to the type
So, according to the docs, the effect of |
|
This is what we internally initially also concluded. However, it is only true at usage time. When you use a smaller type, then its higher bits are cut off: uint256 v = type(uint256).max; // 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
address casted = address(uint160(uint256(v)));
bytes memory b = abi.encodePacked(casted); // 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF
b = abi.encode(casted); // 0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffffAll as you would expect, however, if we access uint256 v = type(uint256).max; // 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
address casted = address(uint160(uint256(v)))
uint256 va;
assembly {
va := casted // 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
}Since the codebase uses assembly values, it is much safer to do this casting in assembly land rather than in Solidity land to ensure they are all casted properly. |
|
That's interesting. I can see this becoming an issue with heavier usage of assembly and would be an improper casting. We could argue that's an edge case to do this back-and-forth with |
|
(Change casting function names to |
|
After reviewing this my thoughts are:
|
Description
After an internal discussion at LI.FI we couldn't settle on what direct casting in Solidity actually does. It seems casting in Solidity is fairly imprecise regarding cleaning bytes after casting.
To ensure that no mistakes are made when casting, variable cleaning is now explicitly done in assembly.
No idea what happened regarding the gas snapshots.