Skip to content

Commit

Permalink
Apply EIP-150 to storage metering
Browse files Browse the repository at this point in the history
Also, a limit of 0 when determining a nested call's metering limit would
mean it was free to use all of the callee's resources.
Now, a limit of 0 means that the nested call will have an empty storage
meter.
  • Loading branch information
rockbmb committed Dec 17, 2024
1 parent 7001212 commit 039dcc2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion substrate/frame/revive/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ where
gas_meter,
Weight::max_value(),
storage_meter,
BalanceOf::<T>::zero(),
BalanceOf::<T>::max_value(),
false,
true,
)?
Expand Down
14 changes: 7 additions & 7 deletions substrate/frame/revive/src/storage/meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,16 @@ where
/// This is called whenever a new subcall is initiated in order to track the storage
/// usage for this sub call separately. This is necessary because we want to exchange balance
/// with the current contract we are interacting with.
pub fn nested(&self, limit: BalanceOf<T>) -> RawMeter<T, E, Nested> {
pub fn nested(&self, lim: BalanceOf<T>) -> RawMeter<T, E, Nested> {
debug_assert!(matches!(self.contract_state(), ContractState::Alive));

// Limit gas for nested call, per EIP-150.
let available = self.available() - self.available() / (BalanceOf::<T>::from(64u32));

// If a special limit is specified higher than it is available,
// we want to enforce the lesser limit to the nested meter, to fail in the sub-call.
let limit = self.available().min(limit);
if limit.is_zero() {
RawMeter { limit: self.available(), ..Default::default() }
} else {
RawMeter { limit, nested: Nested::OwnLimit, ..Default::default() }
}
let limit = available.min(lim);
RawMeter { limit, nested: Nested::OwnLimit, ..Default::default() }
}

/// Absorb a child that was spawned to handle a sub call.
Expand Down

0 comments on commit 039dcc2

Please sign in to comment.