revm_precompile/
fatal_precompile.rs

1use crate::primitives::{
2    Address, Bytes, Env, Precompile, PrecompileErrors, PrecompileResult, StatefulPrecompile,
3};
4use crate::PrecompileWithAddress;
5use std::{string::String, sync::Arc};
6
7/// Disable kzg precompile. This will return Fatal error on precompile call
8pub fn fatal_precompile(address: Address, msg: String) -> PrecompileWithAddress {
9    PrecompileWithAddress(address, FatalPrecompile::new_precompile(msg))
10}
11
12/// Fatal precompile that returns Fatal error on precompile call
13pub struct FatalPrecompile {
14    msg: String,
15}
16
17impl FatalPrecompile {
18    /// Create a new fatal precompile
19    pub fn new(msg: String) -> Self {
20        Self { msg }
21    }
22
23    /// Create a new stateful fatal precompile
24    pub fn new_precompile(msg: String) -> Precompile {
25        Precompile::Stateful(Arc::new(Self::new(msg)))
26    }
27}
28
29impl StatefulPrecompile for FatalPrecompile {
30    fn call(&self, _: &Bytes, _: u64, _: &Env) -> PrecompileResult {
31        Err(PrecompileErrors::Fatal {
32            msg: self.msg.clone(),
33        })
34    }
35}