11 Mandatory Invariants & Testing
Formal mathematical invariants (INV-1 through INV-11), 16+ adversarial attack tests, and stateful cross-market Foundry fuzzing.
Every state transition in BinaryEngine is continuously checked against 11 formal security invariants inside contract/test/invariants/BinaryEngine.invariant.t.sol.
The 11 Mandatory Formal Invariants
INV-1: Global Cross-Market Solvency (Critical Singleton Gate)
Across any number of concurrent markets and any interleaved sequence of launches, trades, pauses, disputes, sweeps, bond updates, and redemptions:
INV-2: Per-Market Solvency & Cross-Market Isolation
Complete-set conservation holds after every operation, redemption liabilities never exceed markets[marketId].collateral, and mutating market leaves every field of market bit-for-bit unchanged.
INV-3: Probability Unity & Virtual TWAP Cutoff
At every block, PRICE_SCALE and PRICE_SCALE. Triggering Void days after cutoffTime yields the exact TWAP frozen at .
INV-4: Anti-Void Front-Running
A large 1-block buy immediately preceding pause() never yields positive net arbitrage profit upon TWAP Void redemption.
INV-5: Overflow Immunity, Exact Conversion & Hint Equivalence
Zero arithmetic overflows at extreme reserves; every external USDT transfer is an exact multiple of ; multi-outcome sell hints (V1.1) match deterministic bisection.
INV-6: Strict sweep() Non-Interference
resolvePriceMarketAndSweep(), finalizeAndSweep(), arbitrate(), and voidIf*() never reduce markets[marketId].collateral below the sum of unclaimed user entitlements.
INV-7: MarketKey Cryptographic Integrity & Saturating netCostBasis
Mutating any single bit in MarketKey reverts with MarketNotInitialized. Profitable sells saturate netCostBasis to 0 without arithmetic underflow.
INV-8: Unstoppable Exits & Full-Exit Exemption
Even under total AdapterRegistry failure (revert, OOG, or malformed return), sell(), redeem(), redeemVoid(), redeemBatch(), and withdrawBond() succeed 100% of the time. Full exits (type(uint40).max) bypass MIN_TRADE_AMOUNT.
INV-9: Strict Share Non-Transferability
No internal or external code path permits transferring position shares between distinct addresses.
INV-10: Leaky-Bucket Circuit Breaker & Vault Loss Bound
Rolling 7-day net Vault debits never exceed maxOutflowPerWindow plus linear time recovery, and net Vault loss on any single market never exceeds key.seed.
INV-11: Absolute Liveness (Zero Permanent Deadlocks)
Every non-terminal state (Active, Paused, TradingClosed, Proposed, Disputed) has a verified permissionless timeout path to Final or Void.
Verification Suites & Attack Coverage
- Unit & Library Tests (
contract/test/unit/*.t.sol): Exact fuzz & unit coverage forBinaryEngine,AdapterRegistry,BinaryFpmmLib,BinaryTwapLib,FeeMathLib, andLeakyBucketLib. - 16 Adversarial Attack Scenarios (
BinaryEngineAttacks.t.sol): Dust buy revert, full-exit dust sell,MarketKeybit-flipping, cross-market EIP-1153 reentrancy, duplicateredeemBatch, zero-volume fallback proposer reward, 7-day post-cutoff TWAP freeze,phaseId + 1Chainlink rollover, second-dispute rejection, stalled Guardian/Arbiter timeouts, and totalAdapterRegistryoutage. - 10 Audit Regression Tests (
BinaryEngineAuditRegressions.t.sol): Proves every fix (M-01–M-03,L-01–L-02), assemblylog3differential parity, dirty calldata upper-bit immunity, 85-checkpoint ring wraparound, and unsolicited 1-wei USDT donations. - Live Anvil + Viem E2E (
verify-anvil-e2e.ts&app/test/integration/anvil-e2e.test.ts): Verifies Viem decoding of assemblylog3MarketCreatedand unit-for-unit quote-vs-onchain parity.
Open Decisions & Pre-Mainnet Gates
Complete sign-off record of locked V1 parameters (OD-1 through OD-12) and remaining pre-mainnet external gates (EXT-1).
V1 BinaryEngine Audit Report
Executive summary, remediated findings (M-01 through L-02), assembly verification, and deep invariant fuzzing results for BinaryEngine V5.0.