From 8ba9f9b1413838bde7fb9b0f07a09f59fc8661b1 Mon Sep 17 00:00:00 2001 From: Ahmad Kaouk Date: Sat, 19 Aug 2023 23:44:58 +0200 Subject: [PATCH 1/2] add a len attribute to ExternalOperation::Write --- core/src/external.rs | 6 +++--- src/executor/stack/executor.rs | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/core/src/external.rs b/core/src/external.rs index 85a98a6c5..591e09ad4 100644 --- a/core/src/external.rs +++ b/core/src/external.rs @@ -1,4 +1,4 @@ -use primitive_types::H160; +use primitive_types::{H160, U256}; /// Operations for recording external costs pub enum ExternalOperation { @@ -8,6 +8,6 @@ pub enum ExternalOperation { AddressCodeRead(H160), /// Basic check for account emptiness. Fixed size. IsEmpty, - /// Writing to storage. Fixed size. - Write, + /// Writing to storage (Number of bytes written). + Write(U256), } diff --git a/src/executor/stack/executor.rs b/src/executor/stack/executor.rs index a2e6e7cc8..3f6d5cb20 100644 --- a/src/executor/stack/executor.rs +++ b/src/executor/stack/executor.rs @@ -1009,10 +1009,9 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> { Ok(()) => { let exit_result = self.exit_substate(StackExitKind::Succeeded); - - if let Err(e) = - self.record_external_operation(crate::ExternalOperation::Write) - { + if let Err(e) = self.record_external_operation( + crate::ExternalOperation::Write(U256::from(out.len())), + ) { return (e.into(), None, Vec::new()); } self.state.set_code(address, out); From 6bd1f61d38e33aab44b6b52cb14deaf9668755b5 Mon Sep 17 00:00:00 2001 From: Ahmad Kaouk Date: Mon, 21 Aug 2023 15:47:32 +0200 Subject: [PATCH 2/2] update record_external_cost to support recording storage growth --- src/executor/stack/executor.rs | 4 +++- src/executor/stack/precompile.rs | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/executor/stack/executor.rs b/src/executor/stack/executor.rs index 3f6d5cb20..e35bae13b 100644 --- a/src/executor/stack/executor.rs +++ b/src/executor/stack/executor.rs @@ -250,6 +250,7 @@ pub trait StackState<'config>: Backend { &mut self, _ref_time: Option, _proof_size: Option, + _storage_growth: Option, ) -> Result<(), ExitError> { Ok(()) } @@ -1464,10 +1465,11 @@ impl<'inner, 'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> Pr &mut self, ref_time: Option, proof_size: Option, + storage_growth: Option, ) -> Result<(), ExitError> { self.executor .state - .record_external_cost(ref_time, proof_size) + .record_external_cost(ref_time, proof_size, storage_growth) } /// Refund Substrate specific cost. diff --git a/src/executor/stack/precompile.rs b/src/executor/stack/precompile.rs index 556df901a..c59b32752 100644 --- a/src/executor/stack/precompile.rs +++ b/src/executor/stack/precompile.rs @@ -55,6 +55,7 @@ pub trait PrecompileHandle { &mut self, ref_time: Option, proof_size: Option, + storage_growth: Option, ) -> Result<(), ExitError>; /// Refund Substrate specific cost.