From 88dd6be1985e92d32d4de5f35c988a4240e4bdac Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Wed, 22 May 2024 15:17:09 +0100 Subject: [PATCH] add RemovedPrecompilesAt for filtering a list of removed precompiles --- precompiles/src/precompile_set.rs | 63 +++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/precompiles/src/precompile_set.rs b/precompiles/src/precompile_set.rs index ebe2d11cfd..4f6d6898f3 100644 --- a/precompiles/src/precompile_set.rs +++ b/precompiles/src/precompile_set.rs @@ -132,6 +132,7 @@ impl From> for IsPrecompileResult { pub enum PrecompileKind { Single(H160), Prefixed(Vec), + Multiple(Vec), } #[derive(Debug, Clone)] @@ -836,6 +837,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);