Skip to content

Commit

Permalink
Add support for a gas-based storage limit (rust-ethereum#173)
Browse files Browse the repository at this point in the history
* add a len attribute to ExternalOperation::Write

* update record_external_cost to support recording storage growth
  • Loading branch information
ahmadkaouk authored Aug 23, 2023
1 parent b7b82c7 commit 44bb77c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions core/src/external.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use primitive_types::H160;
use primitive_types::{H160, U256};

/// Operations for recording external costs
pub enum ExternalOperation {
Expand All @@ -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),
}
11 changes: 6 additions & 5 deletions src/executor/stack/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ pub trait StackState<'config>: Backend {
&mut self,
_ref_time: Option<u64>,
_proof_size: Option<u64>,
_storage_growth: Option<u64>,
) -> Result<(), ExitError> {
Ok(())
}
Expand Down Expand Up @@ -1009,10 +1010,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);
Expand Down Expand Up @@ -1465,10 +1465,11 @@ impl<'inner, 'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> Pr
&mut self,
ref_time: Option<u64>,
proof_size: Option<u64>,
storage_growth: Option<u64>,
) -> 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.
Expand Down
1 change: 1 addition & 0 deletions src/executor/stack/precompile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub trait PrecompileHandle {
&mut self,
ref_time: Option<u64>,
proof_size: Option<u64>,
storage_growth: Option<u64>,
) -> Result<(), ExitError>;

/// Refund Substrate specific cost.
Expand Down

0 comments on commit 44bb77c

Please sign in to comment.