Home / Smart Contract Auditing / Solidity Compiler Vulnerability Discovered in IR-Based Code Generator Affecting Custom Errors in Require Statements

Solidity Compiler Vulnerability Discovered in IR-Based Code Generator Affecting Custom Errors in Require Statements

On February 4, 2026, security researchers identified a subtle yet significant compiler bug within the Intermediate Representation (IR) based code generator of Solidity, the leading programming language for smart contracts on the Ethereum blockchain. The vulnerability, which affects how custom errors are handled when passed to require statements using named-parameter syntax, was brought to light through the official Ethereum Foundation bug bounty program. Carl, a researcher affiliated with Cantina Security, submitted the finding, alerting the Solidity development team to an issue that had quietly persisted within the compiler infrastructure for nearly two years.

According to the technical analysis provided by the Solidity team, the bug causes the arguments of a custom error—when passed to a require statement via named-parameter syntax—to be placed onto the execution stack in the order they appear at the call site, rather than adhering to the strict declaration order defined in the error signature. Consequently, when the ABI encoder subsequently processes these stack values, it reads them out of sequence, resulting in mis-encoded revert payloads or corrupted error data being emitted by the smart contract upon failure.

The underlying flaw was inadvertently introduced in Solidity version 0.8.26, a release that notably expanded the language’s capabilities by adding native support for passing custom errors as the second argument to require statements. Fortunately, the core development team has addressed the issue in Solidity version 0.8.37, which provides a comprehensive fix for the IR-based code generation pathway.

Despite the technical complexity of the bug, the Solidity team assigned it a severity rating of "very low." Because of this classification, the fix was not prioritized for an expedited or emergency out-of-band release, but rather integrated into the standard release cycle. The rationale behind this low severity assessment lies in the highly specific and narrow set of conditions required to trigger the bug, combined with the fact that the affected code path is strictly confined to transactions that are already slated to revert. As a result, the vulnerability has absolutely no impact on the legitimate state of a smart contract, nor does it alter successful execution paths, storage variables, or normal return values.

Triggering the bug requires a precise combination of elements within a contract’s source code. Specifically, a developer must utilize a custom error inside a require statement, instantiate that error using named arguments, and explicitly write those named arguments in an order that deviates from their original declaration sequence. Furthermore, the issue exclusively impacts contracts compiled using the modern IR-based code generation pipeline, leaving legacy code generation pathways unaffected. Other similar language constructs and built-in error handling paths were thoroughly investigated as part of the due diligence process following the discovery, and developers confirmed that those alternative paths correctly handle stack ordering and are fully covered by existing and newly added test suites.

To understand the mechanics of the bug, one must examine how Solidity manages custom error declarations, named arguments, and the ABI encoding process. A custom error declaration explicitly establishes the exact order of its parameters, which directly dictates its unique ABI signature and the physical layout of its encoded payload in memory or calldata. For instance, an error declared with two parameters, such as error NamedArgsError(uint256 a, uint256 b);, establishes that a precedes b in the encoding schema.

Solidity offers developers the flexibility to pass arguments by name, allowing them to invoke this error at a call site in a different order from its declaration, such as require(false, NamedArgsError(b: 7, a: 2));. The compiler’s type checker successfully binds these named arguments to parameters by name, accepting any permutation that specifies every parameter exactly once. The type system does not enforce that the call-site order must match the declaration order. Consequently, the bug could be triggered by any deliberate or accidental reordering of arguments. This includes simple swaps between two arguments of identical types—a scenario where static analysis tools, compilers, and decoders cannot catch the discrepancy because no type mismatch occurs. More surprisingly, the compiler would also silently accept and encode reorderings involving arguments of entirely different types without raising any compilation warnings or errors.

The failure originates in how the IR-based code generator bridges the gap between the function call site and the final revert data construction. Normally, the compiler emits instructions that evaluate arguments and push them onto the execution stack in declaration order. The ABI encoder then iterates through the error’s parameter list, pulling the corresponding slots from the stack to append their encoding to the revert data payload. Most standard data types occupy a single stack slot, holding either the raw value or a reference pointing to memory, storage, or calldata. More complex structures require multiple slots, such as external function pointers taking two slots, and dynamic calldata arrays utilizing an extra slot to store their length. String literals, by contrast, consume zero stack slots because their values are hard-coded directly into the encoder. Because the execution stack consists of untyped slots without explicit boundaries marking where one argument ends and another begins, the encoder relies entirely on receiving data in the anticipated sequence.

In the affected IR-based code generator, the lowering process for require statements containing custom errors omitted the crucial reordering step. Instead of aligning the stack values with the parameter declarations, the compiler pushed the arguments in the exact order they appeared in the named-parameter syntax at the call site. Taking the previous example, the contract would revert with a payload where the first word contained b (valued at 7) and the second word contained a (valued at 2). Consequently, off-chain decoders would incorrectly interpret the data as a = 7 and b = 2, completely reversing the intended semantic values defined by the developer.

It is worth noting that standalone revert ErrorName(...) statements utilize an entirely separate internal code path that properly reorders arguments prior to ABI encoding, meaning they remained completely unaffected by this vulnerability. The flaw was strictly isolated to the specific require-with-custom-error mechanism introduced in Solidity 0.8.26.

When developers reordered parameters of different data types that happened to occupy the same number of stack slots, such as pairing a uint256 with an address, the resulting payload remained structurally valid but contained fundamentally swapped values. Each value landed in the alternate parameter’s slot and was erroneously interpreted as the wrong data type. Similar anomalies occurred with reference types; swapping a uint256 with a memory array caused the encoder to treat the integer value as a memory offset, encoding whatever arbitrary data resided at that memory location as the contents of the array, while the original array offset was misinterpreted as an integer.

The consequences became even more pronounced when reordered arguments occupied differing numbers of stack slots. Because the encoder splits the stack based on the expected declaration order while the incoming data arrived in call-site order, the parameter boundaries became completely misaligned. A parameter would inadvertently consume stack slots belonging to an entirely different argument.

Consider a custom error declaration involving a string and an integer, such as error StringAndUint(string a, uint256 b);, paired with a call site that passes the arguments out of order. The encoding helper for this error expects to receive the two slots describing the dynamic string a (its calldata offset and length) followed by the single slot holding the integer b. Due to the compiler bug, the encoder received the integer’s single slot first, followed by the string’s two slots. It then processed these slots under the assumption that the first two slots belonged to the dynamic type. As a result, the offset field was read from the integer’s value, the length field was derived from the string’s calldata offset, and the integer ended up holding the string’s length. The actual string data was subsequently copied from an unrelated calldata location using a corrupted length value.

Depending on the specific runtime values involved, this misalignment could cause the encoding process to abort with a low-level EVM execution error. While this still forced the transaction to revert, it produced completely undecodable error data rather than the intended custom error payload. In other instances, the contract reverted with a payload that coincidentally matched the expected ABI signature and decoded successfully, because the misplaced data words could easily pass for valid numerical offsets or small integers. This latter scenario presents greater risks, as off-chain consumers matching on the error selector would successfully decode the fields and observe plausible-looking values that bore no relation to the actual source-level arguments.

Because this vulnerability exclusively impacts the generation of revert data for transactions that are already failing and rolling back, it does not modify contract storage, alter successful return values, or interfere with external calls made during normal execution. Revert data can, however, be observed on-chain if a caller explicitly intercepts it using try/catch blocks or low-level CALL operations to branch execution based on error contents, though such practices remain relatively uncommon in day-to-day smart contract development.

The primary practical consequence is the potential to mislead off-chain consumers of revert data—including block explorers, indexers, automated testing frameworks, and error-decoding libraries—which parse the payload assuming the values were correctly encoded. In scenarios where stack misalignment causes an encoding-level revert, code designed to distinguish specific custom errors from generic failures may alter its expected control flow.

Of particular note are standards like ERC-3668, commonly known as CCIP Read, which rely heavily on clients decoding specialized custom errors such as OffchainLookup to orchestrate secure off-chain data retrieval. While ERC-3668 incorporates various validation mechanisms to guard against malicious or forged revert errors, those safeguards cannot inherently detect when an honest, benign contract emits mis-encoded revert data resulting from an underlying compiler bug. Because OffchainLookup combines dynamic and value types, a parameter misordering in an affected require statement would generate a payload that decodes cleanly while carrying entirely incorrect values, disrupting the lookup workflow in a subtle and difficult-to-diagnose manner. The inclusion of revert data as a fundamental part of modern contract interfaces heavily influenced the security assessment of the bug.

The possibility of third-party exploitation remains practically non-existent. An external attacker cannot force a correctly written contract to exhibit this mis-encoding behavior unless the flawed, misordered named argument syntax is already explicitly present in the contract’s source code. Furthermore, an attacker seeking to present misleading revert data to users can already achieve this trivially by deploying a custom contract that intentionally reverts with arbitrary bytes. Consequently, the actual risk is strictly limited to well-intentioned contracts unknowingly emitting erroneous diagnostic data to trusting consumers.

Named-argument syntax is relatively uncommon within require statements in real-world Solidity development, which largely explains why this subtle bug remained undetected for nearly two years. The combination of very narrow trigger conditions, the strictly read-only nature of the affected execution path, and the complete absence of any external exploitation vectors cemented the classification of this issue within the lowest severity tier. Developers utilizing Solidity 0.8.26 through 0.8.36 who rely on named arguments within require-based custom errors are encouraged to update their compiler toolchain to version 0.8.37 or later to ensure fully correct code generation.

Tagged:

Leave a Reply

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