Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@
color: true,
checks: [
{Credo.Check.Readability.MaxLineLength, max_length: 120},
{Credo.Check.Readability.PredicateFunctionNames, false},
{Credo.Check.Readability.WithSingleClause, false},
{Credo.Check.Readability.AliasOrder, false},
{Credo.Check.Refactor.Nesting, false},
{Credo.Check.Refactor.CyclomaticComplexity, false},
{Credo.Check.Refactor.FunctionArity, false},
{Credo.Check.Readability.ModuleDoc, false}
{Credo.Check.Refactor.FunctionArity, false}
]
}
]
Expand Down
3 changes: 2 additions & 1 deletion lib/eevm.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ defmodule EEVM do
- `EEVM.SystemContracts` — EIP-2935 (block hashes) and EIP-4788 (beacon roots)
"""

alias EEVM.{Interpreter, Tracer}
alias EEVM.Block.Bloom
alias EEVM.Interpreter
alias EEVM.Interpreter.{MachineState, Stack}
alias EEVM.Tracer

@doc """
Executes EVM bytecode and returns the final machine state.
Expand Down
3 changes: 2 additions & 1 deletion lib/eevm/block/processor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ defmodule EEVM.Block.Processor do
"""

alias EEVM.Block.{Bloom, Header, Receipt, Result}
alias EEVM.{Database, StateRoot}
alias EEVM.Context.Block, as: BlockCtx
alias EEVM.Database
alias EEVM.MPT.Trie
alias EEVM.StateRoot
alias EEVM.Transaction.Envelope

@type tx_result :: %{
Expand Down
3 changes: 1 addition & 2 deletions lib/eevm/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ defmodule EEVM.Config do
precompiles: %{optional(non_neg_integer()) => module()}
}

defstruct hardfork: nil,
precompiles: %{}
defstruct [:hardfork, precompiles: %{}]

@doc """
Creates a new config with the given hardfork (default: `:cancun`).
Expand Down
3 changes: 2 additions & 1 deletion lib/eevm/handler/post_execution.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ defmodule EEVM.Handler.PostExecution do
struct that callers consume.
"""

alias EEVM.{Database, TransactionResult}
alias EEVM.Block.Bloom
alias EEVM.Context.{Block, Transaction}
alias EEVM.Database
alias EEVM.Handler.{PreExecution, Validation}
alias EEVM.Interpreter.MachineState
alias EEVM.TransactionResult

@spec finalize(
MachineState.t(),
Expand Down
3 changes: 2 additions & 1 deletion lib/eevm/handler/pre_execution.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ defmodule EEVM.Handler.PreExecution do
fee-market formula.
"""

alias EEVM.{Database, Precompiles}
alias EEVM.Context.{Block, Contract, Transaction}
alias EEVM.Database
alias EEVM.Precompiles
alias EEVM.Transaction.IntrinsicGas

@spec charge_upfront(Database.t(), Transaction.t(), Block.t()) ::
Expand Down
10 changes: 6 additions & 4 deletions lib/eevm/interpreter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@ defmodule EEVM.Interpreter do
their semantics.
"""

alias EEVM.{HardforkConfig, Tracer}
alias EEVM.Interpreter.{MachineState, Memory, Stack}
alias EEVM.Database
alias EEVM.Gas.Static
alias EEVM.Transaction.IntrinsicGas
alias EEVM.Tracer.TraceStep
alias EEVM.HardforkConfig

alias EEVM.Interpreter.Instructions.{
Arithmetic,
Expand All @@ -61,6 +58,11 @@ defmodule EEVM.Interpreter do
System.Termination
}

alias EEVM.Interpreter.{MachineState, Memory, Stack}
alias EEVM.Tracer
alias EEVM.Tracer.TraceStep
alias EEVM.Transaction.IntrinsicGas

@doc """
Creates a `MachineState` from bytecode and options, then runs the execution loop.

Expand Down
2 changes: 1 addition & 1 deletion lib/eevm/interpreter/call_frame.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ defmodule EEVM.Interpreter.CallFrame do
needed to suspend and restore execution.
"""

alias EEVM.Interpreter.{Memory, Stack}
alias EEVM.Context.Contract
alias EEVM.Interpreter.{Memory, Stack}

@type t :: %__MODULE__{
code: binary(),
Expand Down
2 changes: 1 addition & 1 deletion lib/eevm/interpreter/instructions/arithmetic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ defmodule EEVM.Interpreter.Instructions.Arithmetic do
"""
import Bitwise

alias EEVM.Interpreter.{MachineState, Stack}
alias EEVM.Gas.Dynamic
alias EEVM.Interpreter.Instructions.Helpers
alias EEVM.Interpreter.{MachineState, Stack}

@max_uint256 (1 <<< 256) - 1

Expand Down
2 changes: 1 addition & 1 deletion lib/eevm/interpreter/instructions/bitwise.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ defmodule EEVM.Interpreter.Instructions.Bitwise do
"""
import Bitwise

alias EEVM.Interpreter.{MachineState, Stack}
alias EEVM.Interpreter.Instructions.Helpers
alias EEVM.Interpreter.{MachineState, Stack}

@max_uint256 (1 <<< 256) - 1

Expand Down
2 changes: 1 addition & 1 deletion lib/eevm/interpreter/instructions/comparison.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ defmodule EEVM.Interpreter.Instructions.Comparison do
- `&Kernel.</2` captures the less-than operator as an anonymous function.
The `/2` means it takes two arguments.
"""
alias EEVM.Interpreter.{MachineState, Stack}
alias EEVM.Interpreter.Instructions.Helpers
alias EEVM.Interpreter.{MachineState, Stack}

@doc """
Dispatches and executes a comparison opcode.
Expand Down
4 changes: 1 addition & 3 deletions lib/eevm/interpreter/instructions/control_flow.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ defmodule EEVM.Interpreter.Instructions.ControlFlow do
SWAP depth adds 1 (`op - 0x90 + 1`) to include the top-of-stack position.
"""

alias EEVM.Interpreter.{MachineState, Stack}
alias EEVM.HardforkConfig
alias EEVM.Interpreter.Instructions.Registry
alias EEVM.Interpreter.Instructions.Helpers
alias EEVM.Interpreter.Instructions.Registry
alias EEVM.Interpreter.Instructions.Helpers
alias EEVM.Interpreter.{MachineState, Stack}

@doc """
Dispatches a control flow opcode to its implementation.
Expand Down
2 changes: 1 addition & 1 deletion lib/eevm/interpreter/instructions/crypto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ defmodule EEVM.Interpreter.Instructions.Crypto do
- The binary pattern `<<hash_int::unsigned-big-256>>` decodes the raw 32-byte
hash binary into a single 256-bit unsigned integer in one step.
"""
alias EEVM.Interpreter.{MachineState, Memory, Stack}
alias EEVM.Gas.Dynamic
alias EEVM.Gas.Memory, as: GasMemory
alias EEVM.Interpreter.{MachineState, Memory, Stack}

@doc """
Hashes a region of memory with Keccak-256 and pushes the result.
Expand Down
4 changes: 2 additions & 2 deletions lib/eevm/interpreter/instructions/environment/data.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ defmodule EEVM.Interpreter.Instructions.Environment.Data do
and RETURNDATACOPY (0x3E).
"""

alias EEVM.Interpreter.{MachineState, Memory, Stack}
alias EEVM.Context.Contract
alias EEVM.Gas.Dynamic
alias EEVM.Gas.Memory, as: GasMemory
alias EEVM.Context.Contract
alias EEVM.Interpreter.{MachineState, Memory, Stack}

@spec execute(non_neg_integer(), MachineState.t()) ::
{:ok, MachineState.t()} | {:error, atom(), MachineState.t()}
Expand Down
4 changes: 2 additions & 2 deletions lib/eevm/interpreter/instructions/environment/external.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ defmodule EEVM.Interpreter.Instructions.Environment.External do
EXTCODEHASH (0x3F), and SELFBALANCE (0x47).
"""

alias EEVM.Context.Contract
alias EEVM.Database
alias EEVM.Interpreter.{MachineState, Memory, Stack}
alias EEVM.Gas.Access
alias EEVM.Gas.Dynamic
alias EEVM.Gas.Memory, as: GasMemory
alias EEVM.Context.Contract
alias EEVM.Interpreter.Instructions.Helpers
alias EEVM.Interpreter.{MachineState, Memory, Stack}

@spec execute(non_neg_integer(), MachineState.t()) ::
{:ok, MachineState.t()} | {:error, atom(), MachineState.t()}
Expand Down
2 changes: 1 addition & 1 deletion lib/eevm/interpreter/instructions/environment/simple.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ defmodule EEVM.Interpreter.Instructions.Environment.Simple do
GASLIMIT, CHAINID, BASEFEE, BLOBBASEFEE, GAS, BLOCKHASH, and BLOBHASH.
"""

alias EEVM.Interpreter.{MachineState, Stack}
alias EEVM.Context.Block
alias EEVM.Interpreter.Instructions.Helpers
alias EEVM.Interpreter.{MachineState, Stack}

@spec execute(non_neg_integer(), MachineState.t()) ::
{:ok, MachineState.t()} | {:error, atom(), MachineState.t()}
Expand Down
2 changes: 1 addition & 1 deletion lib/eevm/interpreter/instructions/logging.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ defmodule EEVM.Interpreter.Instructions.Logging do
- `binary_part/3` extracts a slice from a binary — used to read log data from memory bytes.
"""

alias EEVM.Interpreter.{MachineState, Memory, Stack}
alias EEVM.Gas.Dynamic
alias EEVM.Gas.Memory, as: GasMemory
alias EEVM.Interpreter.{MachineState, Memory, Stack}

@doc """
Dispatches a LOG opcode (LOG0–LOG4) to the matching topic-count handler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ defmodule EEVM.Interpreter.Instructions.StackMemoryStorage.MemoryOps do
- **MCOPY** (0x5E) — copies a region of memory to another location (EIP-5656).
"""

alias EEVM.Interpreter.{MachineState, Memory, Stack}
alias EEVM.Gas.Dynamic
alias EEVM.Gas.Memory, as: GasMemory
alias EEVM.HardforkConfig
alias EEVM.Interpreter.Instructions.Helpers
alias EEVM.Interpreter.{MachineState, Memory, Stack}

@spec execute(non_neg_integer(), MachineState.t()) ::
{:ok, MachineState.t()} | {:error, atom(), MachineState.t()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ defmodule EEVM.Interpreter.Instructions.StackMemoryStorage.StorageOps do
"""

alias EEVM.Database
alias EEVM.Interpreter.{MachineState, Stack}
alias EEVM.Gas.{Access, Dynamic}
alias EEVM.HardforkConfig
alias EEVM.Interpreter.{MachineState, Stack}

@cold_sload_cost 2100

Expand Down
7 changes: 4 additions & 3 deletions lib/eevm/interpreter/instructions/system/calls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ defmodule EEVM.Interpreter.Instructions.System.Calls do
All call opcodes use EIP-150 gas forwarding: `min(requested, available - available/64)`.
"""

alias EEVM.{Database, Interpreter}
alias EEVM.Interpreter.{Journal, MachineState, Memory, Stack}
alias EEVM.Context.Contract
alias EEVM.Database
alias EEVM.Gas.Dynamic
alias EEVM.Gas.Memory, as: GasMemory
alias EEVM.Context.Contract
alias EEVM.Interpreter
alias EEVM.Interpreter.{Journal, MachineState, Memory, Stack}
alias EEVM.Precompiles

@spec execute(non_neg_integer(), MachineState.t()) ::
Expand Down
8 changes: 5 additions & 3 deletions lib/eevm/interpreter/instructions/system/creation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ defmodule EEVM.Interpreter.Instructions.System.Creation do
@max_initcode_size 49_152
@initcode_word_cost 2

alias EEVM.{Database, HardforkConfig, Interpreter}
alias EEVM.Interpreter.{Journal, MachineState, Memory, Stack}
alias EEVM.Context.Contract
alias EEVM.Database
alias EEVM.Gas.Dynamic
alias EEVM.Gas.Memory, as: GasMemory
alias EEVM.Context.Contract
alias EEVM.HardforkConfig
alias EEVM.Interpreter
alias EEVM.Interpreter.{Journal, MachineState, Memory, Stack}

@spec execute(non_neg_integer(), MachineState.t()) ::
{:ok, MachineState.t()} | {:error, atom(), MachineState.t()}
Expand Down
5 changes: 3 additions & 2 deletions lib/eevm/interpreter/instructions/system/termination.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ defmodule EEVM.Interpreter.Instructions.System.Termination do
created the contract.
"""

alias EEVM.{Database, HardforkConfig}
alias EEVM.Interpreter.{MachineState, Memory, Stack}
alias EEVM.Database
alias EEVM.Gas.Memory, as: GasMemory
alias EEVM.HardforkConfig
alias EEVM.Interpreter.{MachineState, Memory, Stack}

@spec execute(non_neg_integer(), MachineState.t()) ::
{:ok, MachineState.t()} | {:error, atom(), MachineState.t()}
Expand Down
6 changes: 3 additions & 3 deletions lib/eevm/interpreter/machine_state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ defmodule EEVM.Interpreter.MachineState do
- The `alias` keyword lets us reference modules by their short name.
"""

alias EEVM.Tracer
alias EEVM.Interpreter.{CallFrame, Memory, Stack}
alias EEVM.Config
alias EEVM.Context.{Block, Contract, Transaction}
alias EEVM.Database
alias EEVM.Database.InMemory, as: InMemoryDB
alias EEVM.Context.{Block, Contract, Transaction}
alias EEVM.Interpreter.{CallFrame, Memory, Stack}
alias EEVM.Precompiles
alias EEVM.Tracer

@type status :: :running | :stopped | :reverted | :invalid | :out_of_gas | {:error, atom()}

Expand Down
14 changes: 7 additions & 7 deletions lib/eevm/precompiles.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ defmodule EEVM.Precompiles do

alias EEVM.Config
alias EEVM.HardforkConfig
alias EEVM.Precompiles.BN256Add
alias EEVM.Precompiles.BN256Mul
alias EEVM.Precompiles.BN256Pairing
alias EEVM.Precompiles.BLS12MapFp2ToG2
alias EEVM.Precompiles.BLS12MapFpToG1
alias EEVM.Precompiles.BLS12Pairing
alias EEVM.Precompiles.Blake2F
alias EEVM.Precompiles.BLS12G1Add
alias EEVM.Precompiles.BLS12G1MSM
alias EEVM.Precompiles.BLS12G2Add
alias EEVM.Precompiles.BLS12G2MSM
alias EEVM.Precompiles.Blake2F
alias EEVM.Precompiles.BLS12MapFp2ToG2
alias EEVM.Precompiles.BLS12MapFpToG1
alias EEVM.Precompiles.BLS12Pairing
alias EEVM.Precompiles.BN256Add
alias EEVM.Precompiles.BN256Mul
alias EEVM.Precompiles.BN256Pairing
alias EEVM.Precompiles.ECRecover
alias EEVM.Precompiles.Identity
alias EEVM.Precompiles.KZGPointEval
Expand Down
2 changes: 1 addition & 1 deletion lib/eevm/precompiles/bn256.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule EEVM.Precompiles.BN256 do
arbitrary-precision integers for coordinate parsing.
"""

alias BN.{FQ, FQ2, BN128Arithmetic, Pairing}
alias BN.{BN128Arithmetic, FQ, FQ2, Pairing}

@field_modulus 21_888_242_871_839_275_222_246_405_745_257_275_088_696_311_157_297_823_662_689_037_894_645_226_208_583

Expand Down
6 changes: 4 additions & 2 deletions lib/eevm/system_contracts/beacon_roots.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ defmodule EEVM.SystemContracts.BeaconRoots do
small for higher layers that aren't yet aware of full EVM state.
"""

alias EEVM.{Database, HardforkConfig, Interpreter}
alias EEVM.Interpreter.MachineState
alias EEVM.Context.{Block, Contract, Transaction}
alias EEVM.Database
alias EEVM.HardforkConfig
alias EEVM.Interpreter
alias EEVM.Interpreter.MachineState

@address 0x000F3DF6D732807EF1319FB7B8BB8522D0BEAC02
@system_address 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE
Expand Down
6 changes: 4 additions & 2 deletions lib/eevm/system_contracts/block_hashes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ defmodule EEVM.SystemContracts.BlockHashes do
if the caller knows the slot was written.
"""

alias EEVM.{Database, HardforkConfig, Interpreter}
alias EEVM.Interpreter.MachineState
alias EEVM.Context.{Block, Contract, Transaction}
alias EEVM.Database
alias EEVM.HardforkConfig
alias EEVM.Interpreter
alias EEVM.Interpreter.MachineState

@address 0x0000F90827F1C53A10CB7A02335B175320002935
@system_address 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE
Expand Down
2 changes: 1 addition & 1 deletion lib/eevm/transaction_result.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ defmodule EEVM.TransactionResult do
cheap and keeps serializers flexible.
"""

alias EEVM.Database
alias EEVM.Block.Bloom
alias EEVM.Database

@type status :: :success | :reverted | :failed_validation

Expand Down
5 changes: 3 additions & 2 deletions test/hardfork_config_test.exs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
defmodule EEVM.HardforkConfigTest do
use ExUnit.Case, async: true

alias EEVM.HardforkConfig
alias EEVM.Context.Contract
alias EEVM.{Database, WorldState}
alias EEVM.Database
alias EEVM.HardforkConfig
alias EEVM.WorldState

# ---------------------------------------------------------------------------
# HardforkConfig.enabled?/2 unit tests
Expand Down
2 changes: 1 addition & 1 deletion test/interpreter/call_frame_test.exs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
defmodule EEVM.CallFrameTest do
use ExUnit.Case, async: true

alias EEVM.Context.Contract
alias EEVM.Interpreter
alias EEVM.Interpreter.{CallFrame, MachineState, Memory, Stack}
alias EEVM.Context.Contract

test "push_frame stores parent frame and switches execution context" do
parent_state = MachineState.new(<<0x00>>, contract: Contract.new(address: 1), gas: 1000)
Expand Down
Loading
Loading