Add MEV protection for subscription charges#443
Open
TUPM96 wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds an opt-in MEV protection model for subscription charges by introducing a commit–reveal pathway, configurable fee/gas bounds, and on-chain monitoring alerts.
Changes:
- Document MEV threat model and recommended operational flow for subscription charging.
- Add new shared types and storage keys for MEV config, charge commitments, and alerts.
- Implement commit–reveal charge endpoints in the subscription contract and proxy, plus integration tests and updated snapshots.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/security.md | Documents the MEV threat model, configuration knobs, and recommended commit–reveal operation. |
| contracts/types/src/lib.rs | Adds MEV-related contracttypes and storage keys for config/commitments/alerts. |
| contracts/subscription/src/lib.rs | Implements MEV config, commitment hashing, commit/reveal endpoints, guarded charging, and alert recording. |
| contracts/proxy/src/lib.rs | Exposes the new MEV functions through the proxy contract interface. |
| contracts/proxy/tests/integration_soroban.rs | Adds integration tests covering commit–reveal, fee bounds, and private-mempool requirement. |
| contracts/proxy/test_snapshots/*.json | Updates snapshots to account for additional storage reads/events introduced by MEV config lookups. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+318
to
+325
| if max_charge_amount != i128::MAX { | ||
| assert!(max_charge_amount >= plan.price, "Charge exceeds max bound"); | ||
| let configured_bound = max_charge_with_fee_bound(plan.price, mev_config.max_fee_bps); | ||
| assert!( | ||
| max_charge_amount <= configured_bound, | ||
| "Max fee bound exceeds configured tolerance" | ||
| ); | ||
| } |
| } | ||
|
|
||
| let mut count: u64 = storage_instance_get(env, storage, StorageKey::MevAlertCount).unwrap_or(0); | ||
| count += 1; |
| } | ||
|
|
||
| if max_charge_amount != i128::MAX { | ||
| assert!(max_charge_amount >= plan.price, "Charge exceeds max bound"); |
| threshold, | ||
| detected_at: env.ledger().timestamp(), | ||
| }; | ||
| storage_persistent_set(env, storage, StorageKey::MevAlert(count), alert.clone()); |
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
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.
Closes #430.
Summary
Validation