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

Address: 0x0000000000000000000000000000000000000004 Introduced: Frontier The Identity precompile is the simplest precompile - it returns the input data unchanged. While this may seem trivial, it serves important purposes for data copying, memory operations, and gas accounting in the EVM.

Gas Cost

Formula: 15 + 3 * ceil(input_length / 32)
  • Base cost: 15 gas
  • Per-word cost: 3 gas per 32-byte word
  • Partial words round up
Examples:
  • 0 bytes: 15 gas
  • 32 bytes: 18 gas (15 + 3*1)
  • 33 bytes: 21 gas (15 + 3*2)
  • 64 bytes: 21 gas (15 + 3*2)

Input Format

Accepts arbitrary-length byte array. No restrictions on input size or content.

Output Format

Identical to input - returns input bytes unchanged.

Usage Example

import { execute, PrecompileAddress } from '@tevm/voltaire/precompiles';
import { Hardfork } from '@tevm/voltaire/primitives/Hardfork';
import * as Hex from '@tevm/voltaire/Hex';

// Copy some data
const input = Hex('0x0102030405');

// Calculate required gas
const words = Math.ceil(input.length / 32);
const gasNeeded = 15n + 3n * BigInt(words);

// Execute precompile
const result = execute(
  PrecompileAddress.IDENTITY,
  input,
  gasNeeded,
  Hardfork.CANCUN
);

if (result.success) {
  // Output === input
  console.log('Output:', result.output);
  console.log('Gas used:', result.gasUsed);
} else {
  console.error('Error:', result.error);
}

Error Conditions

  • Out of gas (insufficient for 15 + 3 * ceil(len/32))

Use Cases

  • Data copying: Efficient way to copy data between memory locations
  • Gas metering: Test gas consumption for data operations
  • Calldata to memory: Copy calldata to memory efficiently
  • Proxy contracts: Forward data without modification
  • Testing: Validate precompile execution mechanics

Implementation Details

  • Zig: Simple allocate + copy operation using allocator.dupe
  • TypeScript: Creates new Uint8Array copy of input
  • Integration: Standalone, no dependencies
  • Optimization: Most efficient data copy operation in EVM

Performance Characteristics

The Identity precompile is the cheapest way to copy data in the EVM:
  • Base cost: 15 gas
  • Per-byte cost: ~0.09375 gas/byte
  • More efficient than CODECOPY (3 gas/word + memory expansion)
  • Cheaper than manual byte-by-byte copying

Why Does Identity Exist?

While it seems trivial, Identity serves several purposes:
  1. Efficient memory operations: Copying data via precompile avoids expensive EVM opcodes
  2. Gas accounting: Provides predictable gas cost for data operations
  3. Testing: Validates precompile calling mechanism
  4. Historical: Part of original Ethereum design, maintained for compatibility

Comparison with Other Copy Operations

OperationBase GasPer-Word GasUse Case
IDENTITY153General data copy
CALLDATACOPY33Calldata to memory
CODECOPY33Code to memory
MCOPY (EIP-5656)33Memory to memory
Identity has higher base cost but same per-word cost. Use MCOPY (if available) for memory-to-memory copies.

Test Vectors

import * as Hex from '@tevm/voltaire/Hex';

// Test 1: Empty input
const input1 = new Uint8Array(0);
const result1 = executeIdentity(input1);
// Expected: empty array (0 bytes)
// Gas: 15 + 3 * 0 = 15

// Test 2: 5 bytes
const input2 = Hex('0x0102030405');
const result2 = executeIdentity(input2);
// Expected: [1, 2, 3, 4, 5]
// Gas: 15 + 3 * ceil(5/32) = 15 + 3*1 = 18

// Test 3: Exact 32-byte boundary
const input3 = Hex('0x' + 'ff'.repeat(32));
const result3 = executeIdentity(input3);
// Expected: 32 bytes of 0xFF
// Gas: 15 + 3 * 1 = 18

// Test 4: Partial word (33 bytes)
const input4 = Hex('0x' + '00'.repeat(33));
const result4 = executeIdentity(input4);
// Expected: 33 bytes (unchanged)
// Gas: 15 + 3 * ceil(33/32) = 15 + 3*2 = 21

References

Specifications