Fix #199: Mitigate front-running vulnerability in Ticket Contract via commit-reveal scheme#266
Open
GEEKYFOCUS wants to merge 2 commits intoGatheraa:mainfrom
Open
Conversation
…nning vulnerability
Contributor
|
@GEEKYFOCUS resolve conflicts. |
Contributor
|
@GEEKYFOCUS resolve conflicts. |
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.
Summary of Changes
This PR addresses the Issue #199 front-running vulnerability present in the Gatheraa ticket purchasing flow (
ticket_contract). By observing the mempool/pending transactions, malicious actors could previously front-run user ticket purchases. Becausepurchasedynamically evaluated the asset price at execution time usingget_ticket_price(), this allowed for price slippage exploitation or sniping the last available tickets.To mitigate this, I implemented a complete Commit-Reveal Scheme with delay mechanisms, price slippage protection, and suspicious activity monitoring.
1. Commit-Reveal Scheme Implementation
PurchaseCommitmentto storage_types.rs.commit_purchase: Buyers submit acommitment_hashequal toSHA-256(buyer || tier_symbol || max_price || nonce). This logs their intent to purchase and timestamps it at the current ledger sequence, completely hiding their targeted tier and maximum acceptable price from observers.reveal_purchase: Once the delay has passed, the buyer provides the raw parameters. The system recalculates the hash to prove ownership, ensures the ticket tier matches, and executes the purchase securely.2. Minimum Delay Mechanism
MinRevealDelay(default 5 ledgers) enforced betweencommit_purchaseandreveal_purchase.3. Suspicious Transaction Monitoring
FrontRunMonitorto track per-address activity limits.check_front_run_monitorandupdate_front_run_monitor.MAX_FAILED_REVEALS(5) or attempts to submit an abnormal amount of commitments within the rollingMONITOR_WINDOW_LEDGERS(60), the address is temporarily blocked from purchasing for two full monitor windows.4. Controlled Randomization (VRF)
VRFEngineandAllocationEngine(Lottery Mode) withinticket_contractfor highly contested/critical random operations. Our fix pairs optimally with this by securing the direct-sale channel (purchase).Validation
Next Steps
set_min_reveal_delay(defaults to 5) per the deployment environment capability.commitment_hashlocally via SHA-256 for the user before firingreveal_purchaseseconds later.