Chained call on a void-returning builtin bypasses "not callable" check, causing assertion panic in retrieve_type
Part of #1999 — soroban-emit-multifuzz-v2 campaign tracking issue
Solang version: confirmed on public v0.3.5 CLI (solang compile --target soroban) Target: Soroban Crash type: Rust panic (assertion left == right failed), exit code 101
Summary
Calling the result of a void-returning builtin as if it were itself callable (e.g. auth.authAsCurrContract(c)(c)) crashes the compiler during semantic analysis. The same pattern applied to an ordinary user-defined void function is correctly rejected with a clean diagnostic (expression is not a function) - but builtins go through a different call-resolution path that skips this check, and the malformed expression only fails much later when something unrelated calls .ty() on it.
Minimal repro
contract Test {
function call_b(address c) public returns (uint64) {
auth.authAsCurrContract(c)(c);
return 1;
}
}
Crash output
thread 'main' panicked at src/sema/expression/retrieve_type.rs:71:17:
assertion left == right failed
left: 0
right: 1
Backtrace
core::panicking::assert_failed
solang::sema::expression::retrieve_type::ty
solang::sema::expression::function_call::function_call_expr
solang::sema::expression::function_call::call_expr
solang::sema::statements::statement
solang::sema::statements::resolve_function_body
solang::sema::contracts::resolve
solang::sema::sema_file
Root cause
auth.authAsCurrContract is a genuine Soroban builtin (sema/builtin.rs), correctly declared with ret: vec![] since it's a void authorization side-effect call. Its handler builds Expression::Builtin with an empty tys list accordingly - this part works exactly as intended.
The bug is in call resolution: when the parser/resolver encounters the second, chained (...) - treating the builtin call's result as callable - nothing rejects this as "not a function," unlike the equivalent case for an ordinary user-defined void function (see control below). The malformed expression is accepted and only fails two layers downstream, in retrieve_type.rs, where the code for Builtin/InternalFunctionCall/ExternalFunctionCall expressions asserts that returns.len() equals 1 before indexing into it. This assumes any call expression reaching .ty() has exactly one return value - an assumption that chained-call resolution on a void builtin violates, since returns.len() is 0 here.
Control (confirms this is specific to builtins, not void calls generally)
contract Test {
function nothing() public {
}
function foo() public returns (uint64) {
return nothing()(1);
}
}
This compiles with a clean error - expression is not a function - as expected. The same "call the result of a void call" pattern is correctly caught for a user-defined function, but not for auth.authAsCurrContract, confirming the gap is in the builtin-specific call-resolution path.
Found via fuzzing
Discovered by AFL++ fuzzing against Solang's own tests/soroban_testcases corpus.