@advanced_security
Best PracticesThe @advanced_security attribute provides
intelligent MEV detection that:
The system distinguishes between:
Monitoring Code ✅ Allowed
find_*, detect_*,
analyze_*, monitor_*, get_*Protected Execution ✅ Allowed
Unprotected Execution ⚠️ Blocked (if @advanced_security enabled)
@advanced_security
service AnalyticsService {
fn find_price_differences() -> list<map<string, any>> {
// ✅ Allowed - monitoring function
// System detects "find_" prefix = monitoring code
return self.analyze_prices();
}
fn detect_arbitrage_opportunities() -> list<map<string, any>> {
// ✅ Allowed - monitoring function
// System detects "detect_" prefix = monitoring code
return [];
}
fn monitor_liquidity_health() -> map<string, any> {
// ✅ Allowed - monitoring function
return {};
}
}
@advanced_security
service ProtectedDeFiService {
fn execute_protected_swap(...) {
// ✅ Allowed - protection patterns detected:
// - commit-reveal pattern
// - slippage protection
// - oracle price validation
let commitment_hash = crypto::hash(...); // Protection detected
let min_amount_out = ...; // Slippage protection detected
let oracle_price = self.get_oracle_price(...); // Oracle detected
}
}
@advanced_security
service VulnerableService {
fn execute_swap(token_in: string, token_out: string, amount: float) {
// ❌ Blocked: "MEV pattern detected. Consider adding protection patterns"
// No protection patterns found
// Unprotected swap code
}
}
Fix: Add protection patterns (see manual MEV protection guide)
✅ Good (Monitoring):
fn find_price_differences() // ✅ Detected as monitoring
fn detect_opportunities() // ✅ Detected as monitoring
fn analyze_market() // ✅ Detected as monitoring
⚠️ Avoid (Ambiguous):
fn arbitrage() // ❌ Looks like execution
fn trade() // ❌ Looks like execution
For execution code, always add protection:
@advanced_security
service DeFiService {
fn execute_swap(...) {
// ✅ Protection patterns:
// 1. Commit-reveal (for large swaps)
// 2. Slippage protection
// 3. Oracle price validation
let commitment_hash = crypto::hash(...);
let min_amount_out = self.calculate_min_output(...);
let oracle_price = self.get_oracle_price(...);
}
}
✅ Good Pattern:
@advanced_security
service Service {
// Monitoring (allowed)
fn find_opportunities() -> list<any> {
return [];
}
// Execution (needs protection)
fn execute_protected_swap(...) {
// Has protection patterns
}
}
@advanced_securityThe system automatically detects these protection patterns:
commit_reveal, commit-revealcommitment_hash, commitmentreveal_swap, commit_swapslippage, min_amount_out,
max_slippageslippage_protection, slippage_checkoracle_price, get_oracle_priceprice_oracle, oracle_validationfair_batch, fair_orderingbatch_pool, shuffletime_delay, delayed_executionexecute_delayed@advanced_security // Monitor mode (warn only, allow monitoring)
Behavior:
// No @advanced_security = no MEV detection
service AnalyticsService {
fn find_opportunities() {
// No MEV detection runs
}
}
Before (Blocked everything):
@advanced_security
service Service {
fn find_arbitrage() { // ❌ Blocked
}
}
After (Smart detection):
@advanced_security
service Service {
fn find_price_differences() { // ✅ Allowed (monitoring)
}
fn execute_protected_swap() { // ✅ Allowed (has protection)
}
fn execute_unprotected_swap() { // ⚠️ Blocked (needs protection)
}
}
Best Design: Monitor, Warn, Guide - Don't Block Legitimate Code
Result: Developers can write monitoring/analytics code freely, while still getting protection for actual execution code.
Last Updated: February 2026 Status: Implemented