-
Notifications
You must be signed in to change notification settings - Fork 490
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
Assembly length checks #396
Conversation
test/libraries/CalldataDecoder.t.sol
Outdated
decoder.decodeUint256(invalidParams); | ||
} | ||
|
||
function test_fuzz_decodeCurrencyUint256AndBool(Currency _currency, uint256 _amount, bool _boolean) public { |
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 test shouldve been here before... was just missing 🤷♀️
@@ -136,6 +140,12 @@ library CalldataDecoder { | |||
{ | |||
// ExactInputParams is a variable length struct so we just have to look up its location | |||
assembly ("memory-safe") { | |||
// only safety checks for the minimum length, where path is empty | |||
// 0xa0 = 5 * 0x20 -> 3 elements, path offset, and path length 0 | |||
if lt(params.length, 0xa0) { |
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.
since params.length is calldataload(params.offset) we might be able to save some gas by just getting that once and then reusing the value for both the check and the copy
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.
will check 👀
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.
update: params.offset
holds the offset of where the content of the dynamic field starts, not the length
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.
ah that's right! gains would be minimal if at all anyway 🙃
No description provided.