revm_precompile/
fatal_precompile.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use crate::primitives::{Address, Bytes};
use crate::{
    Precompile, PrecompileErrors, PrecompileResult, PrecompileWithAddress, StatefulPrecompile,
};
use std::{string::String, sync::Arc};
use wiring::default::CfgEnv;

/// Disable kzg precompile. This will return Fatal error on precompile call
pub fn fatal_precompile(address: Address, msg: String) -> PrecompileWithAddress {
    PrecompileWithAddress(address, FatalPrecompile::new_precompile(msg))
}

/// Fatal precompile that returns Fatal error on precompile call
pub struct FatalPrecompile {
    msg: String,
}

impl FatalPrecompile {
    /// Create a new fatal precompile
    pub fn new(msg: String) -> Self {
        Self { msg }
    }

    /// Create a new stateful fatal precompile
    pub fn new_precompile(msg: String) -> Precompile {
        Precompile::Stateful(Arc::new(Self::new(msg)))
    }
}

impl StatefulPrecompile for FatalPrecompile {
    fn call(&self, _: &Bytes, _: u64, _: &CfgEnv) -> PrecompileResult {
        Err(PrecompileErrors::Fatal {
            msg: self.msg.clone(),
        })
    }
}