Fix calldatasize check for fallback#478
Merged
Merged
Conversation
The previous attempt kept the instance head polymorphic in args/rets while the body called `fn(())`, which forces args = (). The typechecker rejected this as 'type not polymorphic enough'. Specialise the head to Fallback(payability, (), (), fn) so the declared and inferred signatures match. The ABIAttribs / ABIDecode / ABIEncode constraints are dropped since the body no longer decodes or encodes anything, and ContractDispatch.hs already builds the Fallback value with Proxy(()) for args and rets (sigParams is empty and sigReturn defaults to unit), so instance resolution still succeeds at the dispatch call site. Co-authored-by: Alex Beregszaszi <alex@rtfs.hu>
axic
commented
Jun 19, 2026
| cdsz := calldatasize() | ||
| } | ||
| if ((cdsz - 4) < hdsz) { | ||
| if (cdsz < (hdsz + 4)) { |
Contributor
Author
There was a problem hiding this comment.
The original code her resulted in underflow (wraparound), which "kind of" made the flow work.
The problem is that if this gets fixed here, then the do_exec() chain ends up in both cases (cdsz < 4 and cdsz >= 4) in the variant where cdsz < 4 is checked (the check-decode-exec-encode variant).
I fixed this with specializing the fallback case to not reuse that code.
This then showed yet another issue: without the implicit stop/return(0,0), we end up with main function's return:
mstore(0, _mainresult)
return(0, 32)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.