Skip to content

feat(precompiles): add move_precompiles method#270

Merged
mattsse merged 2 commits intomainfrom
feat/move-precompiles
Feb 25, 2026
Merged

feat(precompiles): add move_precompiles method#270
mattsse merged 2 commits intomainfrom
feat/move-precompiles

Conversation

@mattsse
Copy link
Member

@mattsse mattsse commented Jan 26, 2026

Summary

Adds a method to move precompiles from source addresses to destination addresses, supporting the movePrecompileTo field in eth_simulateV1 state overrides.

Changes

New Error Type

  • MovePrecompileError enum with NotAPrecompile(Address) variant
  • Implements Display, Debug, PartialEq, Eq, Clone, and Error

New Methods on PrecompilesMap

  • move_precompiles<I>(&mut self, moves: I) -> Result<(), MovePrecompileError> - takes an iterator of (source, dest) pairs
  • with_moved_precompiles<I>(self, moves: I) -> Result<Self, MovePrecompileError> - builder-style variant

Behavior

  • Validates all source addresses are precompiles before making any changes
  • Skips moves where source == dest (no-op)
  • Atomically removes from source and installs at destination
  • Returns NotAPrecompile error if any source is not a precompile

Example Usage

// Move ECRECOVER from 0x01 to a custom address
let moves = [(
    address!("0x0000000000000000000000000000000000000001"),
    address!("0x0000000000000000000000000000000000000100"),
)];
precompiles.move_precompiles(moves)?;

Tests

  • test_move_precompiles - basic move with verification
  • test_move_precompiles_not_a_precompile - error case
  • test_move_precompiles_same_address_noop - no-op case
  • test_move_precompiles_multiple - moving multiple precompiles

@mattsse mattsse requested a review from klkvr as a code owner January 26, 2026 14:17
Add a method to move precompiles from source addresses to destination
addresses, with a dedicated MovePrecompileError type.

The method:
- Takes an iterator of (source, dest) address pairs
- Validates all source addresses are precompiles before making changes
- Skips no-op moves where source == dest
- Removes precompiles from source and installs at destination

Also adds:
- MovePrecompileError enum with NotAPrecompile variant
- with_moved_precompiles builder-style variant
- Comprehensive tests for the new functionality

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019bfaa4-f4da-731b-be5d-4278ddd726b8
@mattsse mattsse force-pushed the feat/move-precompiles branch from 623868d to 04bc994 Compare January 26, 2026 14:19
@mattsse mattsse merged commit 22eb6b7 into main Feb 25, 2026
27 checks passed
@mattsse mattsse deleted the feat/move-precompiles branch February 25, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant