Home / Smart Contract Auditing / Solidity 0.8.37 Patches IR Code Generator Bug Affecting Named-Parameter Custom Errors in Require Statements

Solidity 0.8.37 Patches IR Code Generator Bug Affecting Named-Parameter Custom Errors in Require Statements

On February 4, 2026, security researchers reported a subtle compiler bug within the Intermediate Representation (IR) based code generator of Solidity, the primary programming language for smart contracts on the Ethereum blockchain. The vulnerability, discovered by Carl from Cantina Security through the official Ethereum Foundation bug bounty program, affects how specific custom error arguments are organized and ABI-encoded when utilized alongside named-parameter syntax inside require statements.

The issue stems from a mismatch in stack ordering during the compilation process. Specifically, when a developer passes a custom error with named arguments out of the original declaration order inside a require condition, the IR code generator places those arguments onto the stack in their call-site sequence rather than adjusting them to match the declaration order required for proper ABI encoding.

The bug was originally introduced in Solidity version 0.8.26, a release that notably added native support for passing custom errors directly as the second argument to require statements. After a thorough investigation and security assessment, the Solidity development team addressed the issue in Solidity 0.8.37, which provides a definitive fix for the mis-encoding behavior.

Because the flaw exclusively impacts the construction of revert data for transactions that are already failing and destined to revert, it leaves contract state completely untouched. It does not modify persistent storage, alter return values, or influence external calls within the execution path leading up to the revert. Consequently, the Solidity team assigned the vulnerability a severity rating of "very low," meaning the fix was incorporated into a standard release cycle rather than prompting an emergency expedited deployment. Triggering the vulnerability demands a very precise set of conditions: it requires a custom error passed into a require function, instantiated explicitly via named arguments in an order that diverges from the error’s original parameter declaration, and compiled using the IR-based code generation pipeline.

Technical Details

To fully understand how the bug manifests, it is helpful to trace how custom error arguments travel from smart contract source code down to the raw revert data returned by the Ethereum Virtual Machine (EVM). A custom error declaration strictly defines the sequence of its parameters, which in turn dictates its unique ABI signature and the exact byte layout of its encoded payload.

For instance, consider a basic custom error declaration specifying two parameters:

error NamedArgsError(uint256 a, uint256 b);

Solidity permits developers to invoke this error by passing arguments explicitly by name. This syntax allows callers to specify parameters in a sequence that differs from the primary declaration order, such as placing b before a:

require(false, NamedArgsError(b: 7, a: 2));

During normal compilation, the type checker verifies that every declared parameter is mentioned exactly once, accepting any valid permutation regardless of whether the call-site order matches the original declaration order. The compiler then emits bytecode that evaluates these arguments and pushes their values onto the execution stack. Ideally, the ABI encoder subsequently reads the error’s parameter list, pulls the corresponding slots from the stack, and appends them to the revert payload in exact accordance with the declaration.

Most data types occupy a single stack slot, storing either an immediate value or a reference pointing to memory, storage, or calldata. Certain complex types require multiple slots: external function pointers utilize two slots, and dynamic calldata arrays carry an additional slot to represent their length. String literals require no stack slots at all because their data is treated as part of the type itself, becoming hard-coded directly into the encoder.

The core of the bug lay in the IR-based code generator’s handling of require statements paired with custom errors. The generator omitted the necessary reordering step, pushing the arguments onto the stack in the exact sequence they appeared at the call site. Because the subsequent ABI encoder continued to consume stack slots according to the original declaration order, a misalignment occurred. In the example above, the resulting revert payload wrongly placed the value of b (7) into the first word and the value of a (2) into the second word. Consequently, off-chain decoders reading the transaction logs or revert reason would interpret the values as a = 7 and b = 2, completely inverting the programmer’s intent.

It is worth noting that standalone revert ErrorName(...) statements utilize an entirely separate code path within the compiler. That alternative path correctly reorders arguments prior to encoding, leaving standard revert statements completely unaffected. The bug was strictly isolated to the require-with-custom-error mechanism introduced in Solidity 0.8.26.

Misinterpreted Values and Stack Misalignment

The consequences of this bug varied depending on the types of the arguments involved. When developers reordered parameters of different types that happened to occupy the exact same number of stack slots—such as pairing a uint256 with an address—the compiler produced no structural misalignment or execution failure. Instead, each value simply landed in the alternate parameter’s stack position, resulting in a payload that was structurally valid under the ABI specification but contained entirely incorrect, type-confused data.

Similar issues arose with reference types. Swapping a uint256 with a memory array caused the ABI encoder to misinterpret the integer as a memory offset, encoding whatever arbitrary data resided at that memory location as the contents of the array, while treating the array’s actual offset as the integer value. Equivalent errors occurred when swapping different categories of references, such as a memory array with a storage array, or comparing two distinct structs containing different internal fields.

The problem escalated when reordered arguments occupied a different number of stack slots. While individual argument slots remained grouped together on the stack, the encoder divided the stack based on the expected declaration order. This caused argument boundaries to drift, resulting in parameters inadvertently consuming stack slots that belonged to adjacent arguments.

Consider a scenario involving a string and a uint256:

error StringAndUint(string a, uint256 b);

contract C 
    function f(string calldata s) external pure 
        require(false, StringAndUint(b: 42, a: s));
    

The encoding helper for StringAndUint expects to process the two slots describing the calldata string a (its offset and length) before reading the single slot holding the integer b. Due to the bug, the encoder received b‘s single slot first, followed by a‘s two slots. It then processed them under the assumption that the initial two slots belonged to the dynamic type parameter. The offset field was consequently read from the integer value 42, the length field was pulled from the string’s actual calldata offset, and b ended up holding the string’s length.

Depending on the specific runtime values, this misalignment could trigger an EVM-level execution error. When that happened, the transaction still reverted as intended, but the resulting error data became completely undecodable, preventing consumers from identifying the specific custom error. In other instances, the contract reverted with a payload that coincidentally matched the expected ABI signature and decoded successfully. Because the misplaced data consisted of ordinary numeric words, small integers easily passed as valid byte offsets. This scenario presented a more insidious risk: off-chain applications matching on the error selector would successfully decode plausible-looking values that bore no relation to the actual source-level arguments.

Severity Assessment and Implications

Because the bug only manifested during the construction of revert data for transactions that were already failing and preparing to abort execution, it posed no threat to contract state. It could not modify storage variables, alter successful return values, or influence external contract calls within a valid transaction path. Revert data is nonetheless observable on-chain; advanced callers can intercept it using try/catch blocks or via low-level CALL operations to execute conditional logic based on the returned error bytes, though such practices remain relatively uncommon in day-to-day smart contract development.

The primary impact of the compiler defect fell on external consumers of revert data—including block explorers, decentralized indexers, error-decoding libraries, and automated testing frameworks. These tools decode transaction payloads assuming that arguments were placed in their correct positions, leading them to display swapped or type-confused values when evaluating failed transactions. In instances of severe stack misalignment, the resulting encoding failure replaced the intended custom-error revert with a generic or empty revert, potentially disrupting off-chain systems designed to differentiate specific custom errors from standard execution failures.

Advanced Ethereum standards such as ERC-3668, commonly known as CCIP Read, rely heavily on clients decoding specific custom errors like OffchainLookup to orchestrate off-chain data retrieval flows. While ERC-3668 incorporates specific architectural safeguards against malicious or forged revert errors, those protections cannot mitigate scenarios where an honest, correctly written smart contract emits mis-encoded revert data due to an underlying compiler bug. Because OffchainLookup combines dynamic and value types within its parameters, a misordering in an affected require statement could generate a payload that decodes cleanly while carrying entirely corrupted values, subtly breaking the lookup process without raising immediate red flags. This interaction with standardized contract interfaces heavily influenced the security team’s evaluation.

Despite these theoretical risks, the practical threat landscape remained extremely limited. Third-party actors could not maliciously introduce mis-encodings into a properly written smart contract; the flawed named-argument reordering had to exist within the contract’s original source code. Furthermore, an attacker seeking to mislead consumers with incorrect revert data could easily achieve the same result by simply deploying a custom contract designed to revert with arbitrary byte sequences. The actual harm was strictly confined to contracts inadvertently emitting misleading data to trusting off-chain consumers.

Named-argument syntax is rarely utilized inside require statements in production environments, which helps explain why the flaw remained undetected for nearly two years following its introduction in Solidity 0.8.26. The combination of very narrow trigger conditions, the strictly read-only nature of the affected code path, and the absence of any viable external exploitation vector ultimately warranted its classification as a low-severity issue.

Recommended Actions

With the release of Solidity 0.8.37, developers working with the IR-based code generator are advised to update their compiler version to ensure complete safety. Projects utilizing named arguments within custom errors passed to require statements should review their codebase to verify that parameter ordering aligns correctly with error declarations, or upgrade their toolchain to permanently resolve the underlying code generation defect.

Tagged: