Skip to main content

revive_strategy/
lib.rs

1//! This crate provides the Revive strategy for the Foundry EVM ExecutorStrategy.
2//!
3//! It is designed to work with the Revive runtime, allowing for the execution of smart contracts
4//! in a Polkadot environment.
5//!
6//! It is heavily inspired from <https://github.com/matter-labs/foundry-zksync/tree/main/crates/strategy/zksync>
7use std::fmt::Display;
8
9use foundry_evm::executors::ExecutorStrategy;
10
11use crate::executor::{
12    context::ReviveExecutorStrategyContext, runner::ReviveExecutorStrategyRunner,
13};
14
15mod backend;
16mod cheatcodes;
17mod executor;
18mod state;
19mod tracing;
20
21pub use cheatcodes::{PvmCheatcodeInspectorStrategyBuilder, ReviveStartupMigration};
22
23/// Runtime backend mode for pallet-revive
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
25pub enum ReviveRuntimeMode {
26    /// Run PolkaVM backend on pallet-revive (PVM mode)
27    Pvm,
28    #[default]
29    /// Run EVM backend on pallet-revive (EVM mode on Polkadot)
30    Evm,
31}
32
33impl Display for ReviveRuntimeMode {
34    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35        match self {
36            Self::Pvm => write!(f, "PVM"),
37            Self::Evm => write!(f, "EVM"),
38        }
39    }
40}
41
42/// Create Revive strategy for [ExecutorStrategy].
43pub trait ReviveExecutorStrategyBuilder {
44    /// Create new revive strategy.
45    fn new_revive(runtime_mode: ReviveRuntimeMode) -> Self;
46}
47
48impl ReviveExecutorStrategyBuilder for ExecutorStrategy {
49    fn new_revive(runtime_mode: ReviveRuntimeMode) -> Self {
50        Self {
51            runner: Box::leak(Box::new(ReviveExecutorStrategyRunner::new())),
52            context: Box::new(ReviveExecutorStrategyContext::new(runtime_mode)),
53        }
54    }
55}