MODEXP
Arithmetic
Arbitrary-precision modular exponentiation: base^exponent mod modulus.
| Address | 0x0000000000000000000000000000000000000005 |
|---|---|
| Name | MODEXP |
| Minimum gas | 500 |
| Input | variable, 96-byte header + operands |
| Output | modLen bytes |
| Available since | Byzantium; repriced at Berlin (EIP-2565) and Osaka (EIP-7883) |
Input
| Offset | Length | Field | Description |
|---|---|---|---|
| 0 | 32 | baseLen | Byte length of `base`, big-endian. |
| 32 | 32 | expLen | Byte length of `exponent`, big-endian. |
| 64 | 32 | modLen | Byte length of `modulus`, big-endian. |
| 96 | baseLen | base | The base, big-endian. |
| — | expLen | exponent | The exponent, big-endian. |
| — | modLen | modulus | The modulus, big-endian. |
Output
base^exponent mod modulus, big-endian, left-padded to exactly `modLen` bytes.
Gas
max(500, mult_complexity(max(baseLen, modLen)) × iteration_count(expLen, expHead))
Frost prices MODEXP under Osaka rules (EIP-7883): the minimum is 500 gas, the exponent-length multiplier is 16, and multiplication complexity is 16 for operands up to 32 bytes and 2 × ceil(x/8)² above that.
Failure behaviour
- Reverts with an error if any of
baseLen,expLen, ormodLenexceeds 1024 bytes (EIP-7823). - A zero modulus returns
modLenzero bytes rather than failing. - Input shorter than the expected length is right-padded with zero bytes rather than rejected.
Calling it
Precompiles have no ABI and no function selector: the input is raw bytes at the exact offsets above. Call with staticcall.
// MODEXP at 0x05(bool ok, bytes memory out) = address(0x05).staticcall(input);require(ok, "MODEXP reverted");