-
Notifications
You must be signed in to change notification settings - Fork 12
fee-payer: enforce call pattern and gas policy #135
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| pympp: minor | ||
| --- | ||
|
|
||
| Added fee payer policy enforcement for sponsored Tempo transactions, validating gas limits, fee caps, total fee budgets, validity windows, and access lists against per-chain policy defaults. Added call pattern validation to restrict sponsored transactions to approved selectors (transfers, and optionally an approve+swap prefix via the stablecoin DEX). |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| """Fee payer policy defaults for sponsored Tempo transactions.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Mapping | ||
| from dataclasses import dataclass | ||
|
|
||
| from mpp.methods.tempo._defaults import CHAIN_ID, TESTNET_CHAIN_ID | ||
|
|
||
|
|
||
| @dataclass(frozen=True, slots=True) | ||
| class Policy: | ||
| max_gas: int | ||
| max_fee_per_gas: int | ||
| max_priority_fee_per_gas: int | ||
| max_total_fee: int | ||
| max_validity_window_seconds: int | ||
|
|
||
|
|
||
| DEFAULT_POLICY = Policy( | ||
| max_gas=2_000_000, | ||
| max_fee_per_gas=100_000_000_000, | ||
| max_priority_fee_per_gas=10_000_000_000, | ||
| max_total_fee=50_000_000_000_000_000, | ||
| max_validity_window_seconds=15 * 60, | ||
| ) | ||
|
|
||
|
|
||
| POLICY_BY_CHAIN_ID: dict[int, Policy] = { | ||
| CHAIN_ID: DEFAULT_POLICY, | ||
| TESTNET_CHAIN_ID: Policy( | ||
| max_gas=DEFAULT_POLICY.max_gas, | ||
| max_fee_per_gas=DEFAULT_POLICY.max_fee_per_gas, | ||
| max_priority_fee_per_gas=50_000_000_000, | ||
| max_total_fee=DEFAULT_POLICY.max_total_fee, | ||
| max_validity_window_seconds=DEFAULT_POLICY.max_validity_window_seconds, | ||
| ), | ||
| } | ||
|
|
||
|
|
||
| def get_policy(chain_id: int, overrides: Mapping[str, int] | None = None) -> Policy: | ||
| base = POLICY_BY_CHAIN_ID.get(chain_id, DEFAULT_POLICY) | ||
| if not overrides: | ||
| return base | ||
|
|
||
| return Policy( | ||
| max_gas=overrides.get("max_gas", base.max_gas), | ||
| max_fee_per_gas=overrides.get("max_fee_per_gas", base.max_fee_per_gas), | ||
| max_priority_fee_per_gas=overrides.get( | ||
| "max_priority_fee_per_gas", base.max_priority_fee_per_gas | ||
| ), | ||
| max_total_fee=overrides.get("max_total_fee", base.max_total_fee), | ||
| max_validity_window_seconds=overrides.get( | ||
| "max_validity_window_seconds", base.max_validity_window_seconds | ||
| ), | ||
| ) |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_validate_transaction_payloadis called for every charge flow (_verify_transaction, line 721), but it now always invokes_validate_normalized_calls, which enforces the sponsored-only approve/swap/transfer pattern and rejects any extra calls. This introduces false negatives for non-fee-payer (methodDetails.feePayer == false) transactions that still include a valid payment transfer, because they are now rejected before broadcast even though downstream receipt verification could succeed. The new scope restriction should be conditioned on sponsored requests to avoid breaking existing unsponsored transaction patterns.Useful? React with 👍 / 👎.