Skip to content

Conversation

@pgherveou
Copy link
Contributor

@pgherveou pgherveou commented Jan 28, 2026

Summary

  • Fixes proxy contract calls failing with OutOfGas when using ReviveApi.call (Substrate runtime API)
  • The same calls succeed through eth_transact (Ethereum RPC)

see paritytech/contract-issues#256

Problem

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 for unlimited deposit).

The calculation flow:

  1. remaining_gas = weight_gas + deposit_gas → huge number (deposit dominates at ~10^38)
  2. Contract requests all gas: requested_gas = u64::MAX (~10^19)
  3. ratio = requested_gas / remaining_gas ≈ 0.0000000000000027
  4. nested_weight_limit = ratio × weight_left ≈ 0
  5. Nested call immediately fails with OutOfGas

Solution

Cap remaining_gas to u64::MAX since Ethereum gas is a u64 value. This ensures the ratio is 1.0 when a contract requests all gas, giving the nested call the full remaining weight.

Test plan

  • Verified fix resolves the issue with proxy contracts (TransparentUpgradeableProxy)
  • Existing tests pass

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.
Add regression tests for the gas limit cap fix in substrate_execution.
These tests validate that nested calls requesting all gas receive
meaningful weight allocation when using large deposit limits.

Note: The tests use Balance = u64, so the bug doesn't fully manifest.
The fix is critical for u128 production configs where deposit_left
can exceed u64::MAX.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to review these AI written tests

@pgherveou pgherveou marked this pull request as draft January 28, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants