solang icon indicating copy to clipboard operation
solang copied to clipboard

Compiler panic when a unary operator (~) is applied to a void-returning external/interface call

Open ahmadsamehh opened this issue 3 months ago • 0 comments

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 (assert_eq! failure in retrieve_type::ty()), exit code 101

Summary

Applying the bitwise-NOT operator (~) to a function call that returns no value (void) crashes the compiler with an internal assertion failure - but only when the void-returning call is made through an interface/external contract reference (e.g. someInterface.someMethod(...)). The exact same pattern using a plain internal function call is correctly rejected with a clean diagnostic instead.

Root cause

retrieve_type::ty() (called via bitwise_not -> user_defined_operator) assumes an expression being operated on always resolves to exactly 1 type. For a void-returning external/interface call, the expression resolves to 0 types instead of 1, and the internal assert_eq! fires, aborting the process. The equivalent void-check that correctly catches a plain internal void call does not run (or is structured differently) on the external-call code path, letting the invalid expression reach user_defined_operator unchecked.

Proof it's specifically about calling another contract

  1. ~noReturn(); where noReturn() is a plain function in the same contract -> Solang catches it correctly, clean error, no crash.
  2. The same pattern, but the void function belongs to a separate contract accessed through an interface (auth.authAsCurrContract(...)) -> crash, same exact panic.

Suggested fix direction

Ensure the same "expression of type void not allowed" validation that catches plain internal void calls also runs for void-returning calls made through interface/external contract references, before the expression reaches operator-resolution code such as bitwise_not/user_defined_operator.

Additional notes

This is a semantic-analysis-phase crash (happens before any LLVM/codegen involvement). Worth checking whether other unary/user-defined operators (e.g. !, -) exhibit the same gap when applied to void external calls.

Found via fuzzing

Discovered via AFL++ fuzzing campaign (soroban-emit-multifuzz-v2), tree-sitter grammar-aware mutator targeting the Soroban emit pass. The original triggering input had the fuzzer insert a stray ~ character directly before a // comment in otherwise valid Soroban auth code, causing the parser to treat ~ as a real operator rather than part of a comment.

ahmadsamehh avatar Aug 20 '26 11:08 ahmadsamehh