feat: implement MEV protection and commit-reveal for subscription cha…#640
Open
wagmiiii wants to merge 1 commit into
Open
feat: implement MEV protection and commit-reveal for subscription cha…#640wagmiiii wants to merge 1 commit into
wagmiiii wants to merge 1 commit into
Conversation
|
@wagmiiii Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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:
This PR introduces robust Miner Extractable Value (MEV) protection to the subscription contracts to safeguard
users against frontrunning and sandwich attacks when their subscriptions are charged. It implements a commit-reveal
scheme, gas bidding analysis, and allows for private mempool integration.
What Changed:
ChargeCommitmentandMevAttackDetectedtypes tocontracts/types/src/lib.rs.commit_chargefunction that hashes and stores pending payload details in transient storage (TTL-based).
charge_subscriptioninto a backwards-compatible wrapper that delegates toreveal_charge.reveal_chargefor charges exceeding theLargeChargeThreshold.contracts/subscription/THREAT_MODEL.mdto formally document the MEV threat model.contracts/subscription/src/test.rs.Key Design Decisions:
set_large_charge_thresholdso that it can adapt dynamically to network/market conditions.integration," Soroban smart contracts do not have native execution awareness of the transaction lifecycle's origin
mempool. We accommodated this by enforcing that users commit to an
is_private_mempoolflag, which off-chainclients/SDKs must respect when routing the transaction.
temporary_setfor the commit hash. This prevents storage bloatfrom orphaned commitments and avoids expensive ledger fees.
Acceptance Criteria Checklist:
Security Note:
The
commit_chargepayload utilizesenv.crypto().sha256(). Temporary commitments are automatically wiped outupon successful execution to prevent replay attacks, while
sub.subscriber.require_auth()guarantees that no thirdparty can initiate the reveal on behalf of an unwilling subscriber.