---
eip: 7823
label: EIP-7823
title: Set upper bounds for MODEXP
status: Final
type: Standards Track
category: Core
created: 2024-11-11
requires: 198
official: https://eips.ethereum.org/EIPS/eip-7823
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7823.md
canonical: https://eips.huatuo.xyz/eip-7823/
lang: en
tldr: Caps each length field of the MODEXP precompile at 1024 bytes (8192 bits), removing an unbounded input space that had caused repeated consensus bugs.
tags: [precompile, modexp, cryptography, evm, core, fusaka]
---

# EIP-7823: Set upper bounds for MODEXP

> Each input field is restricted to a maximum of 8192 bits

**TL;DR:** Caps each length field of the MODEXP precompile at 1024 bytes (8192 bits), removing an unbounded input space that had caused repeated consensus bugs.

## What problem does it solve?

The MODEXP precompile at address `0x05`, added by [EIP-198](/eip-198/), computes `base ** exponent % modulus` on arbitrarily large numbers. "Arbitrarily large" is the problem: each operand's length is declared in the input and was unbounded, so client teams had to handle and test an effectively infinite input space. MODEXP has been the source of numerous consensus bugs, many triggered by deliberately strange, impractically long inputs. Its gas pricing is also complex because of the unbounded sizes.

Real-world use is far smaller. An on-chain analysis in the spec, covering blocks from Byzantium (April 2018) to January 2025, found that no successful call ever used an input longer than 513 bytes; almost all used 32, 128 or 256 bytes.

## How it works

The input format from EIP-198 is unchanged:

```
<length_of_BASE> <length_of_EXPONENT> <length_of_MODULUS> <BASE> <EXPONENT> <MODULUS>
```

The new rule: each of the three lengths must be **≤ 1024 bytes (8192 bits)**. If any length exceeds that, the precompile fails, returns an error and consumes all gas supplied to it.

Why 8192 bits? It still covers every practical use:

- RSA signature verification with keys up to 8192 bits (1024/2048/4096 are common).
- Elliptic-curve arithmetic, which typically needs at most 384 bits.

A bounded input also makes it more realistic to replace the precompile later with ordinary EVM code (for example using EVMMAX-style instructions), with fast paths for common sizes.

## Sample code

Calling MODEXP from Solidity, with a guard that mirrors the new limit:

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

library ModExp {
    uint256 constant MAX_LEN = 1024; // EIP-7823 limit, in bytes

    function modexp(bytes memory b, bytes memory e, bytes memory m)
        internal view returns (bytes memory result)
    {
        require(b.length <= MAX_LEN && e.length <= MAX_LEN && m.length <= MAX_LEN, "too long");
        bytes memory input = abi.encodePacked(
            uint256(b.length), uint256(e.length), uint256(m.length), b, e, m
        );
        result = new bytes(m.length);
        bool ok;
        assembly {
            ok := staticcall(gas(), 0x05, add(input, 32), mload(input),
                             add(result, 32), mload(m))
        }
        require(ok, "modexp failed");
    }
}
```

## Things to know

- **Status: Final**, included in the Fusaka upgrade ([EIP-7607](/eip-7607/)).
- Technically backwards incompatible, but the spec's analysis found no past transaction that would have behaved differently.
- The limit applies to the declared lengths, not just the actual bytes supplied, so an over-long length header fails even if the data is short.
- The pricing formula is not changed by this EIP; MODEXP repricing is handled separately (see [EIP-2565](/eip-2565/) for the earlier repricing).


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-7823
