@@ -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
812825impl < 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
825842impl 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