SECURITY

Security Architecture

Flywheel Protocol is designed with defense-in-depth. Every layer incorporates multiple security mechanisms — from oracle validation and reentrancy guards to economic incentives and access control. No single point of failure can compromise user funds.

Oracle Security

Chainlink Data Feeds

All price data comes from decentralized Chainlink oracles. No single entity controls the price feed. Multiple independent node operators submit price observations, and the aggregator contract computes a median value — resistant to individual node manipulation.

Staleness Checks

Every oracle query includes a timestamp check. If the latest round data is older than maxPriceAge (default: 1 hour), the transaction reverts. This prevents settlement against stale prices during oracle downtime or chain congestion.

Round Completeness

The protocol checks that the oracle round has actually completed (answer > 0) before using price data. Incomplete or zero-value rounds are rejected.

Smart Contract Security

Reentrancy Protection

All state-mutating functions that interact with external contracts use OpenZeppelin's ReentrancyGuard. State changes occur before external calls (checks-effects-interactions pattern). No function that transfers tokens can be re-entered.

Access Control

Administrative functions use role-based access control (RBAC). Each privileged operation has its own role — no single "owner" key can perform all actions. Roles include: KEEPER_ROLE for triggering conversions, TREASURY_ROLE for parameter changes, and PAUSER_ROLE for emergency stops.

Pausability

Critical functions (deposits, withdrawals, conversions) can be paused in an emergency. The pause mechanism is time-bounded — any pause automatically expires after a configurable duration unless renewed. This prevents permanent lockout if the pauser key is compromised.

Integer Overflow Protection

Solidity ^0.8.x provides built-in overflow/underflow protection. All arithmetic operations revert on overflow. High-precision fixed-point math uses uint256 with explicit PRECISION constants to avoid rounding exploits.

Economic Security

Slippage Protection

Every DEX swap is bounded by oracle-verified minimum output amounts. An attacker would need to manipulate both the DEX price AND the Chainlink oracle simultaneously — which requires compromising the majority of Chainlink node operators, a cryptoeconomically infeasible attack.

Penalty Alignment

The early withdrawal penalty creates a natural disincentive for short-term manipulation. Any attack that requires depositing tokens would incur a 5% cost if unwound within the penalty window. This makes many economic attacks unprofitable.

Activation Delay

The 1-hour activation period prevents flash-loan-based attacks. Deposited tokens must remain in the vault for the activation period before earning rewards, eliminating the ability to deposit, claim, and withdraw within a single transaction or block.

Withdrawal Cooldown

The 48-hour withdrawal cooldown prevents front-running of reward distributions. Depositors cannot exit immediately before or after a large reward deposit — they must commit to staying through the cooldown period.

Operational Security

Keeper Network

Conversion triggers are permissionless — any address can call the trigger function. If the designated keeper is offline, the community can step in. The protocol is designed to function without reliance on any single infrastructure provider.

Upgrade Path

Each layer is independently upgradeable. If a vulnerability is discovered in one component, only that component needs to be replaced — the rest of the protocol continues operating. Upgrades require multi-sig governance with timelock delays.

Monitoring

All critical protocol events emit on-chain events: deposits, withdrawals, claims, conversions, and parameter changes. These events enable real-time monitoring and alerting through standard blockchain indexing infrastructure.

Audit Philosophy

Flywheel Protocol follows a “security by construction” approach. Every contract uses battle-tested OpenZeppelin libraries. Every conversion is oracle-verified. Every state change emits an event for off-chain verification. The reference implementation (Bullion) is open-source and publicly verifiable. Formal audits are recommended for each deployment and will be published as they become available. In the meantime, the protocol's simplicity and use of standard, audited components provides strong baseline security.