1---2name: aiken-dex-security-audit3description: Adversarial security audit playbook for Plutus V3 Aiken DEX contracts (threat model, invariants, findings, tests, tx repro shapes).4---56# aiken-dex-security-audit78## When to use9- Auditing Plutus V3 Aiken contracts for a DEX (validators + minting policies)10- You need a rigorous report: threat model, invariants, findings, and reproducible exploit tx shapes1112## Non-negotiable rules13- No hallucinations. If something isn't in the repo or inputs, say **unknown** and list exactly what's missing.14- Assume a hostile attacker can craft arbitrary transactions: multi-input, multi-action, weird datums, weird token bundles.15- Never ask for or handle seed phrases / private keys.16- Prefer evidence over vibes: minimal tx shape + failing test + fix + passing test.1718## Required inputs (ask for anything missing)191) Script list + purpose (spend/mint/reward/cert) and which are critical path for swaps/liquidity202) Datum/redeemer schemas (Aiken types + encoding expectations)213) Parameters/config: policy IDs, script hashes, upgrade/admin controls, oracle deps (if any)224) Off-chain tx builder(s) in scope (where swaps/liquidity txs are constructed)235) Network assumptions (mainnet/preprod) + constraints (tx size, exunits, reference scripts, inline datums)2425## Audit workflow (do ALL)261) Build a system model27 - Map state UTxOs, assets, script addresses, and transitions (inputs/outputs/mint/burn/signees/time).282) Extract explicit invariants (testable)29 - Value conservation, LP supply rules, fee bounds/rounding, auth rules, "exactly-one state UTxO", bounded datum/value growth.303) Threat model & attack surface31 - Attacker capabilities in eUTxO; trusted roles; upgrade/emergency keys; oracles; economic/griefing vectors.324) Manual on-chain review33 - For each validator/policy branch: what must be true about inputs/outputs/minted/signers/time?34 - Hunt: double satisfaction, fake-state UTxOs, asset-class mismatches, optional datum gotchas, unbounded growth, time-range bugs, division/rounding/negative amounts, "exactly one" enforcement bugs.35 - For each issue: minimal exploitable tx shape + why it works (use tx-shapes template).365) Off-chain review (if in scope)37 - Ensure builder cannot construct valid-but-unsafe txs or mis-hash datums or mis-handle mint fields.386) Evidence suite (Aiken-first)39 - Add unit tests + property tests for each invariant + each exploit regression test.407) Budget & DoS analysis41 - Identify evaluation hotspots and griefing paths; recommend safe refactors.428) Report43 - Use `templates/audit-report.md` and include: scope, assumptions, invariants, findings table, patches, tests, deployment checklist.4445## Files to use46- Full framework prompt: `references/audit-framework.md`47- Report template: `templates/audit-report.md`48- Invariants checklist: `templates/invariants-checklist.md`49- Minimal exploit tx shapes: `templates/tx-shapes.md`