forked from foundry-rs/foundry
-
Notifications
You must be signed in to change notification settings - Fork 6
[issues/358] - Capped PVM max gas #359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
filip-parity
wants to merge
17
commits into
master
Choose a base branch
from
issues/358
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alexggh
reviewed
Oct 28, 2025
Collaborator
|
I was thinking rather to use dry-run for gas calculation. I think we should put it on hold as we have again gas changes in pallet-revive with updated gas limits. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Limit the PVM per-call gas cap using the runtime’s Normal-class per‑extrinsic weight (BlockWeights minus base_extrinsic) and a storage deposit cap derived from the caller’s free balance minus existential deposit and value sent. The cap is encoded via the runtime’s EthGasEncoder and clamped by the transaction’s gas_limit to align execution with runtime constraints and keep gas reporting accurate.
Motivation
PVM calls were capped using unbounded values, which could exceed Substrate runtime limits and account constraints. This PR aligns the PVM gas cap with the runtime’s per‑extrinsic weight rules and storage deposit requirements to ensure realistic execution limits and consistent gas reporting.
Solution
The max gas capping flow when a contract CREATE or CALL happens in PVM mode:
Step 1: Compute system maximum weight
We read the blockchain's configuration for normal user transactions, get the maximum weight allowed per transaction, and subtract the base overhead cost, the resulting value being the max ceiling.
Step 2: User's gas request validation
We take the user's requested gas limit from their transaction, convert it into Substrate's Weight format where ref_time equals the gas amount and proof_size is set to u64::MAX, then take the minimum between the user request and system allowance.
UPDATE: The system converts requested gas into Substrate weight using runtime calculations, accounts for base extrinsic overhead to prevent block limit violations, scales proof size, and calculates storage deposit caps from actual available balance.
Step 3: Compute available balance for storage
We get the caller's account balance and subtract the minimum balance that must remain (existential deposit) and the value being sent with the transaction, with the leftover value representing the maximum storage deposit they can afford.
UPDATE: improved solution: available = free_balance - existential_deposit - value_sent
Step 4: Execute the contract
We call the revive pallet with the computed weight_limit and storage_deposit_cap from steps 2 and 3.
Step 5: Record actual gas used
After execution, we get the consumed weight and convert it back to gas units using the same ref_time mapping, then clamp this to the transaction gas limit and record it as the gas cost for the transaction.