Smart Contract Security

MegaTAO employs multiple layers of security in its smart contract architecture. This page details the technical design patterns and safeguards built into the protocol.

Upgradeability

UUPS Proxy Pattern

The protocol uses the UUPS (Universal Upgradeable Proxy Standard) proxy pattern, allowing the core logic to be upgraded while preserving all user state and balances.

  • Proxy contract holds all storage and receives all calls

  • Implementation contract contains the business logic

  • Only addresses with the UPGRADER_ROLE can trigger upgrades

  • Upgrades go through a governance review process before deployment

ERC-7201 Namespaced Storage

All contract storage uses the ERC-7201 namespaced storage pattern. This prevents storage collisions between different modules and ensures safe upgradeability.

  • Each module (Margin, Position, Market, Order, Funding, Vault, Fee) has its own isolated storage namespace

  • Storage slots are deterministically computed, eliminating collision risk across upgrades

Position Security

Flash Loan Protection

Positions cannot be opened and closed within the same block. This prevents flash loan attacks where an attacker could manipulate prices within a single transaction to extract value from the protocol.

Simulate-Before-Execute

All write operations are simulated before execution. If the simulation fails (e.g., due to insufficient margin, invalid parameters, or contract reverts), the transaction is not submitted to the network. This protects users from wasting gas on transactions that would fail.

One Position Per Market

Each trader can hold at most one position per market. This is enforced at the contract level through deterministic position IDs derived from the trader's address and the market address.

Oracle Security

Reserve-Based Pricing

Alpha token prices are derived from on-chain pool reserves using a dedicated price oracle contract. The oracle reads directly from Bittensor's Alpha token precompile, ensuring prices reflect actual on-chain liquidity.

Multi-Oracle Design

The oracle architecture supports multi-source consensus to protect against price manipulation. This includes:

  • Primary reserve-based pricing from on-chain data

  • Support for additional oracle sources as fallbacks

  • Price validation to reject anomalous values

Risk Controls

Circuit Breakers

The protocol includes circuit breakers that automatically activate when risk thresholds are exceeded:

  • Vault utilization limits: Trading is restricted when vault exposure reaches critical levels

  • Maximum aggregate exposure: Caps total protocol exposure across all markets

  • Per-market position limits: Configurable maximum position size per trader per market

Liquidation Safeguards

  • Maintenance margin of 10% ensures positions are closed well before insolvency

  • Keeper incentives (5% liquidation fee) ensure timely liquidation of unhealthy positions

  • Partial liquidation support for large positions to minimize market impact

  • Emergency deleverage capability for extreme market conditions

Market Pause

Individual markets can be paused independently in response to anomalous conditions, without affecting trading on other markets.

Insurance Fund

The protocol maintains an insurance fund to cover bad debt from positions that become insolvent before liquidation. This protects vault depositors from losses due to extreme market moves.


For details on specific audit findings and remediations, see Audit Reports.

Last updated