Skip to main content
This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.

Overview

Opcode: 0x0a Introduced: Frontier (EVM genesis) Gas Update: EIP-160 (Spurious Dragon, 2016) EXP computes base^exponent where both operands are 256-bit unsigned integers. The result wraps modulo 2^256 on overflow. Unlike other arithmetic operations, EXP has dynamic gas costs based on the byte length of the exponent. This operation uses exponentiation by squaring for efficient computation, critical for cryptographic operations and mathematical calculations.

Specification

Stack Input:
Stack Output:
Gas Cost: 10 + (50 × byte_length(exponent)) Operation:

Behavior

EXP pops two values from the stack (base, exponent), computes base^exponent, and pushes the result back:
  • Normal case: Result is base^exponent mod 2^256
  • Exponent = 0: Result is 1 (even when base = 0)
  • Base = 0: Result is 0 (except when exponent = 0)
  • Overflow wrapping: Result wraps modulo 2^256
The implementation uses fast exponentiation by squaring (square-and-multiply algorithm) for O(log n) complexity.

Examples

Basic Exponentiation

Zero Exponent

Zero Base

Large Exponent with Overflow

Power of 10 (Wei/Ether)

Gas Cost

Base Cost: 10 gas (GasSlowStep) Dynamic Cost: 50 gas per byte of exponent (EIP-160) Formula: gas = 10 + (50 × byte_length(exponent))

Byte Length Calculation

The byte length is the number of bytes needed to represent the exponent:

Gas Examples

Comparison

Edge Cases

EVM 0^0 Convention

Power of 2 Overflow

Large Base Overflow

Identity Exponent

Stack Underflow

Out of Gas

Common Usage

Wei to Ether Conversion

Power-of-Two Operations

Modular Exponentiation

Fixed-Point Math

Bit Mask Generation

Implementation

Testing

Test Coverage

Edge Cases Tested

  • Basic exponentiation (2^3 = 8)
  • Zero exponent (any^0 = 1)
  • Zero base (0^n = 0)
  • 0^0 special case (returns 1)
  • Overflow wrapping (2^256 = 0)
  • Large exponents (10^18, 2^255)
  • Gas calculation for different byte lengths
  • Exponentiation by squaring correctness
  • Stack underflow (< 2 items)
  • Out of gas (insufficient for byte length)

Security

Gas Attacks

Before EIP-160, EXP had constant gas cost, enabling DoS attacks: Pre-EIP-160 vulnerability:
Post-EIP-160 fix:
  • Gas cost proportional to exponent byte length
  • Prevents DoS by making large exponents expensive

Overflow Behavior

EXP wraps on overflow without reverting:

Constant-Time Considerations

EXP implementation must avoid timing leaks in cryptographic contexts:

Algorithm: Exponentiation by Squaring

EXP uses the efficient square-and-multiply algorithm:
Complexity: O(log n) multiplications where n is exponent value Example: 3^13

References

  • MUL - Basic multiplication
  • MULMOD - Modular multiplication (used in modExp)
  • EXP Precompile - BigInt modular exponentiation (0x05)