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

Optimize getting function selector #58

Merged
merged 2 commits into from
Apr 19, 2024
Merged

Optimize getting function selector #58

merged 2 commits into from
Apr 19, 2024

Conversation

wilsoncusack
Copy link
Contributor

@xenoliss
Copy link
Contributor

xenoliss commented Apr 19, 2024

There is a difference though, doing [0:4] will revert if msg.data is less than 4 bytes, while doing byte4(data) won't and simply right pad with zeros.

EDIT: Right padding is fine as the worst case is calling executeWithoutChainIdValidation() with no inner data.
RE-EDIT: executeWithoutChainIdValidation() selector is 0x2c2abd1e so not reachable by right padding with zeros.

@wilsoncusack
Copy link
Contributor Author

There is a difference though, doing [0:4] will revert if msg.data is less than 4 bytes, while doing byte4(data) won't and simply right pad with zeros.

Yes but this shouldn't cause any new security risk. If the function selector has trailing 0s, using the right padding to reach the same function selector should be functionally the same call flow.

@wilsoncusack
Copy link
Contributor Author

Also @xenoliss I sanity checked the selector of executeWithoutChainIdValidation and it's 0x2c2abd1e, so this should never be possible.

@wilsoncusack wilsoncusack merged commit 29b8235 into main Apr 19, 2024
7 of 9 checks passed
@wilsoncusack wilsoncusack deleted the wilson/bytes4 branch April 19, 2024 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants