diff --git a/precompiles/src/precompile_set.rs b/precompiles/src/precompile_set.rs index 345da89f8f..d89d983f93 100644 --- a/precompiles/src/precompile_set.rs +++ b/precompiles/src/precompile_set.rs @@ -129,6 +129,7 @@ impl From> for IsPrecompileResult { pub enum PrecompileKind { Single(H160), Prefixed(Vec), + Multiple(Vec), } #[derive(Debug, Clone)] @@ -833,6 +834,68 @@ impl IsActivePrecompile for RevertPrecompile { } } +/// Precompiles that were removed from a precompile set. +/// Still considered precompiles but are inactive and always revert. +pub struct RemovedPrecompilesAt(PhantomData); +impl PrecompileSetFragment for RemovedPrecompilesAt +where + A: Get>, +{ + #[inline(always)] + fn new() -> Self { + Self(PhantomData) + } + + #[inline(always)] + fn execute( + &self, + handle: &mut impl PrecompileHandle, + ) -> Option { + if A::get().contains(&handle.code_address()) { + Some(Err(revert("Removed precompile"))) + } else { + None + } + } + + #[inline(always)] + fn is_precompile(&self, address: H160, _gas: u64) -> IsPrecompileResult { + IsPrecompileResult::Answer { + is_precompile: A::get().contains(&address), + extra_cost: 0, + } + } + + #[inline(always)] + fn used_addresses(&self) -> Vec { + A::get() + } + + fn summarize_checks(&self) -> Vec { + vec![PrecompileCheckSummary { + name: None, + precompile_kind: PrecompileKind::Multiple(A::get()), + recursion_limit: Some(0), + accept_delegate_call: true, + callable_by_smart_contract: "Reverts in all cases".into(), + callable_by_precompile: "Reverts in all cases".into(), + }] + } +} + +impl IsActivePrecompile for RemovedPrecompilesAt +where + Self: PrecompileSetFragment, +{ + #[inline(always)] + fn is_active_precompile(&self, _address: H160, _gas: u64) -> IsPrecompileResult { + IsPrecompileResult::Answer { + is_precompile: false, + extra_cost: 0, + } + } +} + /// A precompile that was removed from a precompile set. /// Still considered a precompile but is inactive and always revert. pub struct RemovedPrecompileAt(PhantomData);