Skip to content

Commit 668fb4d

Browse files
committed
revive: cap remaining_gas to u64::MAX in substrate_execution
When calculating resource limits for nested calls through substrate_execution::new_nested_meter, the ratio-based scaling fails when deposit_left is very large (e.g., u128::MAX default). The ratio becomes near-zero because: - remaining_gas = weight_gas + deposit_gas (huge number from deposit) - ratio = requested_gas / remaining_gas ≈ 0 - nested_weight_limit = ratio × weight_left ≈ 0 This causes proxy contracts using delegatecall to fail with OutOfGas when called through ReviveApi.call, while the same calls succeed through eth_transact. Cap remaining_gas to u64::MAX since Ethereum gas is a u64 value. This ensures the ratio is 1.0 when requesting all gas, giving the nested call the full remaining weight.
1 parent 5fd7bb5 commit 668fb4d

File tree

1 file changed

+6
-0
lines changed
  • substrate/frame/revive/src/metering

1 file changed

+6
-0
lines changed

substrate/frame/revive/src/metering/math.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ pub mod substrate_execution {
120120
return Err(<Error<T>>::OutOfGas.into());
121121
};
122122

123+
// Cap remaining_gas to u64::MAX since Ethereum gas is a u64 value.
124+
// Without this cap, when deposit_left is very large (e.g., u128::MAX),
125+
// the ratio calculation would produce a near-zero value, causing the
126+
// nested call to receive almost no weight even when requesting all gas.
127+
let remaining_gas = remaining_gas.min(u64::MAX.saturated_into());
128+
123129
let gas_limit = remaining_gas.min(*gas);
124130

125131
let ratio = if remaining_gas.is_zero() {

0 commit comments

Comments
 (0)