3 Dec 2026, Thu

Solidity Compiler Bug in IR-Based Code Generator Leads to Incorrect Custom Error Argument Encoding in Require Statements

The Ethereum Foundation has officially addressed a vulnerability discovered in the Solidity compiler’s intermediate representation (IR) code generator. Reported on February 4, 2026, by security researcher Carl from Cantina Security through the official Ethereum Foundation bug bounty program, the issue involves the mishandling of custom error arguments passed via named-parameter syntax inside require statements. While the bug could result in misaligned stack data during transaction reverts, its narrow trigger conditions and lack of impact on contract state led developers to classify its severity as very low. A permanent fix has since been implemented and shipped with the release of Solidity 0.8.37.

The underlying flaw originated in Solidity version 0.8.26, a release that notably introduced support for passing custom errors directly as the second argument to require statements. Under normal operational circumstances, developers utilize require to validate conditions and trigger transaction reversals alongside descriptive custom errors, enhancing both gas efficiency and debugging capabilities on-chain. However, for a subset of contracts compiled using the IR-based pipeline, the compiler inadvertently failed to align the stack order of named parameters with the layout expected by the ABI encoder.

To understand how the defect manifests, it is necessary to examine the path arguments take from source code to final revert data. When a custom error is declared in Solidity, its parameter sequence establishes an immutable order that dictates both its ABI signature and the structure of its encoded payload. While developers can supply arguments using named-parameter syntax—effectively shuffling the input order at the call site—the compiler type checker accepts any permutation as long as every parameter is addressed precisely once.

The compilation pipeline normally ensures that arguments are evaluated, pushed onto the execution stack, and subsequently consumed by the ABI encoder in the precise order specified by the original error declaration. In the affected versions utilizing the IR-based code generator, however, the compilation step dedicated to lowering require calls with custom errors omitted the essential reordering phase. Consequently, the arguments were placed on the stack in their call-site order rather than their declaration order. When the ABI encoder subsequently walked the parameter list, it consumed the stack slots sequentially without recognizing the mismatch, resulting in a compiled revert payload containing misplaced values.

The practical ramifications of this misalignment varied depending on the types of the arguments involved. In scenarios where developers swapped two arguments of identical types—such as two uint256 variables—the transaction would revert with a payload that remained structurally valid to external decoders, but contained inverted values. Because no type mismatch occurred, neither the compiler nor off-chain decoding tools could automatically detect the discrepancy, leading monitoring systems to read incorrect operational data.

More complex behaviors emerged when reordered arguments occupied differing numbers of stack slots or involved reference types. Because the stack is fundamentally an untyped sequence of slots, shifting the boundaries between arguments caused parameters to inadvertently consume data intended for neighboring values. For instance, swapping a dynamic memory type with a fixed value type caused the encoder to misinterpret basic integers as memory offsets or lengths. This could trigger an EVM-level encoding failure that forced the transaction to revert without any decodable error data, or conversely, produce a deceptively valid payload that completely misrepresented the source-level inputs.

Despite the potential for data corruption in revert payloads, the development team assigned the vulnerability a "very low" severity rating due to several mitigating factors. The bug exclusively impacted the construction of revert data for transactions that were already destined to fail and roll back. Consequently, it had zero impact on state variables, actual return values, or the execution of preceding successful operations within a transaction. Furthermore, triggering the condition required a very specific combination of factors: the use of an IR-based pipeline, a require statement incorporating a custom error, and named-argument instantiation written out of the declaration order. Standalone revert statements utilizing named parameters were routed through an entirely separate code path and remained entirely unaffected.

The rarity of this exact syntax pattern in production environments explains why the bug persisted undetected for nearly two years following its introduction in version 0.8.26. While third-party exploitation was deemed impossible—since an attacker cannot unilaterally alter the source code of an independently deployed contract—the risk primarily centered on off-chain consumers. Block explorers, indexers, automated test frameworks, and specialized tooling that rely on accurate error decoding could theoretically ingest misaligned parameters and process incorrect values. This is particularly relevant for advanced standards like ERC-3668, commonly known as CCIP Read, which depends on clients accurately parsing custom errors such as OffchainLookup to facilitate decentralized data retrieval flows.

Following the initial disclosure and subsequent validation by the Ethereum Foundation security team, the issue was addressed directly within the compiler codebase. Developers seeking to ensure absolute protection against the serialization flaw are advised to update their compilation environments to Solidity 0.8.37 or later, where the IR code generator correctly aligns named arguments prior to ABI encoding.

Leave a Reply

Your email address will not be published. Required fields are marked *