Skip to content

Add MEV protection for subscription charges#443

Open
TUPM96 wants to merge 1 commit into
Smartdevs17:mainfrom
TUPM96:codex/mev-protection-430
Open

Add MEV protection for subscription charges#443
TUPM96 wants to merge 1 commit into
Smartdevs17:mainfrom
TUPM96:codex/mev-protection-430

Conversation

@TUPM96
Copy link
Copy Markdown

@TUPM96 TUPM96 commented May 25, 2026

Closes #430.

Summary

  • adds configurable MEV protection for subscription charges, including a hash-based commit-reveal path for large charges
  • enforces reveal-time max charge bounds, optional private mempool routing, and gas-price alert monitoring
  • exposes proxy helpers/getters and documents the MEV threat model for operators
  • updates integration coverage and proxy snapshots for the new guarded charge path

Validation

  • cargo test --manifest-path contracts\Cargo.toml --workspace
  • cargo build --manifest-path contracts\Cargo.toml --workspace --target wasm32v1-none --release

Copilot AI review requested due to automatic review settings May 25, 2026 11:52
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Protect against frontrunning and sandwich attacks on subscription charges

2 participants