Skip to content
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

Merged
merged 4 commits into from
Nov 22, 2024
Merged

Assembly length checks #396

merged 4 commits into from
Nov 22, 2024

Conversation

hensha256
Copy link
Contributor

No description provided.

decoder.decodeUint256(invalidParams);
}

function test_fuzz_decodeCurrencyUint256AndBool(Currency _currency, uint256 _amount, bool _boolean) public {
Copy link
Contributor Author

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) {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will check 👀

Copy link
Contributor Author

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

Copy link
Contributor

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 🙃

@hensha256 hensha256 merged commit 1394ff2 into main Nov 22, 2024
3 checks passed
@hensha256 hensha256 deleted the length-checks-decode branch November 22, 2024 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants