EraVM ↔ EVM Contract Interactions

How different execution modes interact

EVM contracts and EraVM contracts can interact, but due to differences in execution models, some constraints exist. The EVM Emulator ensures that EVM contracts execute in an environment that closely follows EVM semantics, while EraVM contracts continue to operate natively.

This page covers the interaction rules, execution behavior, and limitations when calling between EraVM and EVM contracts.

This page contains technical details that may be redundant for most cases. In general, EVM and EraVM contracts can call each other.

Calling an EVM Contract from an EraVM Contract

Execution Flow

  1. EraVM contract makes a call to an EVM contract.
  2. The system reads the versioned hash of the target contract from AccountCodeStorage.
    • If the contract is marked as an EVM contract (version 0x02), the system redirects execution to the EVM Emulator.
  3. The EVM Emulator:
    • Loads and interprets the EVM contract’s bytecode.
    • Executes the contract as if it were running on an EVM.
    • Returns the result in EraVM format.

Gas Handling

  • EraVM contracts use ergs (EraVM gas).
  • When calling an EVM contract, fixed constant (5:1) is used to derive EVM gas from native EraVM gas.
  • EVM gas is emulated for compatibility. Actual execution is paid in native EraVM gas. See EVM gas emulation for details

Data Handling

  • Calldata is passed as-is. EraVM contracts do not need to modify the calldata when calling an EVM contract.
  • Returned data is forwarded directly without modifications.

Calling an EraVM Contract from an EVM Contract

Execution Flow

  1. EVM contract calls an EraVM contract.
  2. The system detects that the target contract has an EraVM-native versioned hash (0x01).
  3. The system executes the contract using the EraVM execution model.

Gas Handling

  • The EVM emulator derives amount of native gas passed using a fixed ratio (1:5).
  • The call proceeds as a native EraVM call with the converted gas amount (or less, if remaining gas amount is not enough).

Execution Constraints

delegatecall Is Not Supported Between EVM and EraVM Contracts

  • EVM contracts cannot use delegatecall to EraVM contracts.
  • EraVM contracts cannot use delegatecall to EVM contracts.

This restriction prevents unintended access to system-level features and ensures execution isolation.

Call stack depth

EVM emulation have no forced call stack depth limit. The 63/64 gas forwarding rule implicitly enforces a depth limitation in the same way as in EraVM.

Out-of-Ergs Handling

  • If the EVM emulation frame runs out of native EraVM gas (ergs), it triggers an internal panic that reverts the entire EVM call stack.
  • If the EVM emulation frame runs out of EVM gas, the revert propagates only to that contract’s execution context according to EVM rules.

See EVM gas emulation for more details.

Summary

ScenarioSupported?Notes
EraVM → EVM callCalls invoke the EVM emulator. EVM gas is derived from passed native EraVM gas (ergs).
EVM → EraVM callCalls execute using native EraVM logic with gas conversion.
EraVM delegatecall to EVMNot supported due to execution model differences.
EVM delegatecall to EraVMNot supported due to execution model differences.
Out-of-ergs handling⚠️EVM contracts revert all EVM calls on out-of-ergs errors. EraVM contracts revert only their local execution.

Next Steps


Made with ❤️ by the ZKsync Community