Skip to content

Commit 732ca96

Browse files
decofeDaniPopes
andauthored
fix: disable caching for identity precompile in tuple impls (#305)
Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
1 parent aec3602 commit 732ca96

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

crates/evm/src/precompiles.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ use revm::{
1616
Context, Journal,
1717
};
1818

19+
/// Returns whether the given [`PrecompileId`] supports caching.
20+
///
21+
/// This returns `false` for precompiles where the cost of computing a cache key (hashing the
22+
/// input) is comparable to just re-executing the precompile (e.g., the identity precompile which
23+
/// simply copies input to output).
24+
const fn precompile_id_supports_caching(id: &PrecompileId) -> bool {
25+
!matches!(id, PrecompileId::Identity)
26+
}
27+
1928
/// A mapping of precompile contracts that can be either static (builtin) or dynamic.
2029
///
2130
/// This is an optimization that allows us to keep using the static precompiles
@@ -807,6 +816,10 @@ where
807816
fn call(&self, input: PrecompileInput<'_>) -> PrecompileResult {
808817
self.1(input)
809818
}
819+
820+
fn supports_caching(&self) -> bool {
821+
precompile_id_supports_caching(&self.0)
822+
}
810823
}
811824

812825
impl<F> Precompile for (&PrecompileId, F)
@@ -820,6 +833,10 @@ where
820833
fn call(&self, input: PrecompileInput<'_>) -> PrecompileResult {
821834
self.1(input)
822835
}
836+
837+
fn supports_caching(&self) -> bool {
838+
precompile_id_supports_caching(self.0)
839+
}
823840
}
824841

825842
impl Precompile for revm::precompile::Precompile {
@@ -832,7 +849,7 @@ impl Precompile for revm::precompile::Precompile {
832849
}
833850

834851
fn supports_caching(&self) -> bool {
835-
!matches!(self.id(), PrecompileId::Identity)
852+
precompile_id_supports_caching(self.id())
836853
}
837854
}
838855

0 commit comments

Comments
 (0)