solang icon indicating copy to clipboard operation
solang copied to clipboard

Chained compound multiplication on a parameter-derived value crashes `strength_reduce`

Open ahmadsamehh opened this issue 3 months ago • 0 comments

Part of #1999 — soroban-emit-multifuzz-v2 campaign tracking issue

Note: possibly related to / overlapping with #1910, filed separately since it was found independently through this fuzzing campaign with its own MRE — flagging the connection for maintainers to dedupe as they see fit.

Solang version: confirmed on public v0.3.5 CLI (solang compile --target soroban) Target: Soroban Crash type: Rust panic (range N..M out of bounds), exit code 101

Summary

A chained compound-multiplication assignment where the right-hand side traces back to a function parameter (e.g. value *= value *= initial;) crashes the compiler during the strength_reduce codegen optimization pass. The panic originates inside the bitvec crate, from a value-range tracker that computes an inverted/out-of-bounds slice range against a 256-bit-sized buffer.

Minimal repro

contract C {
    int128 value;
    constructor(uint32 initial) {
        value *= value *= initial;
    }
}

Crash output

thread 'main' panicked at bitvec-1.1.1/src/slice/api.rs:2681:1:
range 192..128 out of bounds: 256

Root cause

The panic site is in bitvec's slice API, called from solang::codegen::optimize::strength_reduce, bouncing between expression_values and reaching_values before erroring out. The "256" bound is a bitvec-backed value-tracking bitset used by the strength_reduce pass. The chained compound self-assignment (*=/&= mixing a state variable and a function parameter) produces a computed range whose start legitimately exceeds what the bitset was sized for, and nothing validates the range before the slice operation runs.

Additional minimization notes

Removing the function parameter entirely (self-referencing value *= value *= value; with no external input) does not crash — confirming the function parameter (initial) is a required ingredient, not just self-reference.

Found via fuzzing

Discovered via AFL++ fuzzing campaign (soroban-emit-multifuzz-v2) against Solang's Soroban emit pass.

ahmadsamehh avatar Aug 20 '26 10:08 ahmadsamehh