Feb 28, 2026·5 min read·4 visits
The Frontier modexp precompile underprices gas for even moduli. Attackers can trigger slow calculation paths in the underlying math library, stalling nodes via cheap transactions.
A denial-of-service vulnerability exists in the Frontier Ethereum compatibility layer for Substrate. The modular exponentiation (modexp) precompile fails to account for algorithmic performance discrepancies between even and odd moduli in the underlying 'num-bigint' library. This allows attackers to trigger computationally expensive operations with low gas costs, potentially stalling block production and validation.
Frontier serves as the Ethereum compatibility layer for Substrate-based blockchains, enabling them to run unmodified Ethereum Virtual Machine (EVM) contracts. A critical component of the EVM is the set of precompiled contracts located at specific addresses, which handle computationally intensive operations natively rather than in EVM bytecode. Address 0x00...05 corresponds to the modular exponentiation (modexp) precompile.
In affected versions of Frontier, the modexp implementation relies on the Rust num-bigint crate to perform the underlying mathematical calculations. The vulnerability stems from a discrepancy between the gas cost charged by the EVM and the actual computational resources required by num-bigint to execute the operation. Specifically, the gas cost formula treated all moduli uniformly, ignoring significant performance differences based on the parity of the modulus.
This misalignment allows an attacker to craft transactions using large, even moduli that trigger a worst-case performance path in the underlying library. Because the gas cost is calculated based on an optimized path, the transaction remains cheap to execute on the network but expensive for the physical hardware, leading to a Denial of Service (DoS) condition.
The root cause lies in the algorithmic implementation of modular exponentiation within the num-bigint crate and Frontier's failure to model its performance characteristics accurately. Modular exponentiation ($B^E \mod M$) is optimized in num-bigint using Montgomery Reduction when the modulus $M$ is odd. Montgomery Reduction replaces expensive division operations with efficient bit shifts and multiplications, resulting in highly performant execution.
However, when the modulus $M$ is even, num-bigint cannot use Montgomery Reduction. Instead, it falls back to a standard "plain power" algorithm, typically exponentiation by squaring combined with standard division-based reduction. Standard division is significantly more CPU-intensive than the operations used in Montgomery reduction.
Frontier's calculate_gas_cost function determined the transaction fee based solely on the bit lengths of the base, exponent, and modulus. It did not check the modulus value itself. Consequently, it assigned the same gas cost to calculations involving even moduli as it did to those involving odd moduli, despite the former being orders of magnitude slower to compute. This created an "Algorithmic Complexity" vulnerability (CWE-407) where the resource consumption was not proportional to the input size metric used for billing.
The vulnerability existed in frame/evm/precompile/modexp/src/lib.rs. The fix involves modifying the gas calculation logic to penalize operations involving even moduli. The developers introduced a heuristic multiplier to align the gas cost with the increased computational time.
Below is the logic before and after the patch:
Vulnerable Code (Conceptual):
fn calculate_gas_cost(..., mod_length: u64, ...) -> u64 {
// Standard gas calculation based on input length
// Complexity assumes optimized Montgomery reduction
math::calculate_standard_cost(mod_length, ...)
}Patched Code (Commit 5af12e9):
fn calculate_gas_cost(
// ... existing parameters ...
mod_is_even: bool, // New parameter to check parity
) -> u64 {
let standard_cost = math::calculate_standard_cost(...);
// Apply a 20x multiplier if the modulus is even
// saturating_mul ensures the value doesn't wrap on overflow
standard_cost.saturating_mul(if mod_is_even { 20 } else { 1 })
}The patch specifically targets the mod_is_even condition. By multiplying the gas cost by 20, the developers effectively de-incentivize the attack vector. While this is a heuristic rather than a precise measurement of the underlying algorithm's complexity, it raises the cost of attack sufficiently to mitigate the DoS risk in the short term. The long-term solution suggested by the maintainers involves migrating to a constant-time cryptographic library that handles both cases efficiently.
To exploit this vulnerability, an attacker does not need special privileges or access to the node's configuration. The attack is performed entirely via the standard Ethereum JSON-RPC interface or by submitting signed transactions to the p2p network.
Attack Scenario:
modexp precompile (address 0x05). The payload consists of a large Base, a large Exponent, and a large Even Modulus (e.g., a 2048-bit number ending in 0).num-bigint. Detecting the even modulus, the library enters the slow division-based reduction loop.The primary impact of CVE-2023-28431 is Denial of Service (DoS). By stalling the block execution process, an attacker can prevent the network from finalizing blocks in a timely manner. In a permissionless blockchain context, this is a high-severity issue because it directly affects the availability and liveness of the network.
CVSS v3.1 Analysis:
AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:HWhile the vulnerability is severe for availability, it does not allow for remote code execution or privilege escalation. The scope is limited to the node's execution runtime.
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H| Product | Affected Versions | Fixed Version |
|---|---|---|
Frontier Parity Technologies | <= 0.1.0 | Post-PR #1017 |
| Attribute | Detail |
|---|---|
| CWE | CWE-682 (Incorrect Calculation) |
| CVSS v3.1 | 7.5 (High) |
| Attack Vector | Network |
| Impact | Denial of Service (DoS) |
| EPSS Score | 0.00265 |
| Patch Commit | 5af12e94d7dfc8a0208a290643a800f55de7b219 |
The software performs a calculation that generates incorrect or unintended results that are later used in security-critical decisions.