Skip to content

Fix calldatasize check for fallback#478

Merged
rodrigogribeiro merged 4 commits into
argotorg:mainfrom
axic:short-calldata-check
Jun 19, 2026
Merged

Fix calldatasize check for fallback#478
rodrigogribeiro merged 4 commits into
argotorg:mainfrom
axic:short-calldata-check

Conversation

@axic

@axic axic commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

No description provided.

axic and others added 4 commits June 19, 2026 12:57
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>
Comment thread std/dispatch.solc
cdsz := calldatasize()
}
if ((cdsz - 4) < hdsz) {
if (cdsz < (hdsz + 4)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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)

@rodrigogribeiro rodrigogribeiro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM.

@rodrigogribeiro rodrigogribeiro merged commit d5d895f into argotorg:main Jun 19, 2026
4 checks passed
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.

3 participants