The invariants the tests enforce, the threat model, and what v0 deliberately does not do.
Counterbook's v0 contracts are not professionally audited. They have had one independent review, described below, and are not deployed on any chain. An external audit comes before the vault takes outside deposits. Planned (v1)
These properties are enforced by unit, fuzz and invariant tests in contracts/test (133 tests). The invariant campaign runs with fail_on_revert, so any unexpected revert fails it.
| Id | Invariant |
|---|---|
| I1 | beforeSwap never reverts because of a HyperCore read: covers an empty return, a revert, all forwarded gas burned, and a zero value. |
| I2 | Every beforeSwap return has OVERRIDE_FEE_FLAG set, and fee ≤ maxFee ≤ maxFeeCap. |
| I3 | Only the vault can add liquidity to the pool. |
| I4 | No function lets the curator, or anyone else, move vault assets to an arbitrary address. |
| I5 | The CoreAgent only encodes actions 1, 11 and 13, within their constraints. Fuzzed over all inputs. |
| I6 | NAV-priced vault actions revert whenever a guard they depend on fails: reads, basis and spread for all of them; the gap for deposit, redeem and crystallize; a transfer in flight for deposit, sweep and crystallize. |
| I7 | NAV per share is conserved across deposit and redeem, within the rounding of NAV itself: the position is valued with floor rounding, so one operation can move NAV by about one raw unit of each token. |
| I8 | At most one order dispatch per block, and never a second order while the first may still be live. |
| Liabilities (outstanding claims) never exceed assets. |
| Threat | Mitigation |
|---|---|
| Manipulating the pool in the same block, then depositing or redeeming | NAV uses the HyperCore reference price, which EVM transactions cannot move within a block. Deposits, redemptions and crystallisation also require the pool price to be within gapTolerance of it whenever the pool price can change the position's composition. |
| Manipulating the HyperCore spot book to move the reference price | The mandate requires a perp: the basis check against the perp oracle trips DISLOCATED. Orders are priced relative to the reference and bounded by maxOrderDeviation. |
| Stale or failed reads | Fallback fee on swaps; vault actions revert |
| Starving the reads of gas to force the fallback fee | beforeSwap requires 100,000 gas up front; each read gets a fixed 30,000 |
| Adverse selection on delayed maker orders | Passive offset behind the touch, TTL cancel, reprice cancel, size cap, IOC past the hard band as the escape hatch |
| Silent order rejection, or a CoreWriter delay longer than the cooldown | Accounting reads balances, not order status. The order record is kept until HyperCore shows nothing on hold, an unchanged balance is treated as a rejection only after ttlBlocks, and a new order goes out only when nothing rests on either side. |
| Rate-limit exhaustion on HyperCore | Cooldown with an immutable floor, threshold dispatch, cancel before place |
| Curator misconfiguration | Immutable bounds, including ceilings on the dislocation caps that also gate vault actions, a parameter delay, and every depositor can exit during it |
| Curator theft | No curator function moves funds; the CoreAgent cannot transfer to arbitrary addresses or add an API wallet |
| Precompile gas griefing | READ_GAS cap per read; the fast loop is skipped when gasleft() is below minGasForLoop; stipends on every external call in the loop |
| CoreAgent not yet a HyperCore user | 0x810 check; the loop skips without reverting |
| Bridging in flight | NAV counts a transfer only until the credit is observed on the other venue, so nothing is counted twice. Deposits, crystallisation and further sweeps wait for it; redemptions, claims and recentering do not. |
| Keeping the vault locked with dust redemptions and sweeps | The lock ends on observed credit, sweep() has a cooldown of 4 × transitBlocks blocks, and a claims pull moves at least 10 USDC of value |
| An empty pool's price moved for free | recenter() moves the empty pool back to the reference inside its own unlock and never leaves zero liquidity; the gap guard is skipped when the pool price cannot change the position's composition |
| Transfers back to HyperEVM failing for lack of HYPE on HyperCore | A HYPE reserve on HyperCore that orders and claims never spend; USDC pulls only while free HYPE covers twice the transfer cost at the current base fee |
| Share inflation on the initial deposit | Dead shares minted on the initial deposit |
| Reentrancy | PoolManager lock, plus nonReentrant on vault entry points |
| Licence | Uniswap's PoolManager is under the Business Source License. Mainnet uses Uniswap's listed deployment on 999; a self-deployed PoolManager is used on testnet only. |
Before any deployment, the contracts had one independent review (not a professional audit). It found one high, three medium and three low-severity issues, plus informational notes. Each was confirmed with a proof-of-concept test, fixed, and kept as a regression test in contracts/test/audit/AuditRegression.t.sol.
| Finding | Fix |
|---|---|
| A redeemer could take full principal while the HyperCore claims were short, leaving the shortfall to the remaining depositors | The redeemer bears its share of a shortfall, and orders never spend HyperCore balances owed to claimants |
| A deposit in any mix followed by a redemption was a fee-free swap at the reference mid | Deposits are proportional to the vault's composition |
| Repeated small sweeps could keep the vault locked | Only deposits and crystallisation wait for transfers, the lock ends on observed credit, and sweeps have a cooldown and a minimum size |
| A recenter could leave zero liquidity, letting anyone move an empty pool's price for free | Recenter never leaves zero liquidity and moves an empty pool to the reference inside its own unlock |
| Lower-severity items | No double count of funds in transit, the HODL benchmark re-split when the target weight changes, partial claims, no duplicate orders, ceilings on the curator's guard caps, transfer-cost checks, perp size decimals for the oracle price |
The full list, with the test for each fix, is in the contracts README.
What v0 does not do, by design or for now:
claim() pays it as far as HyperEVM balances allow, first come, first served; a sweep brings the rest back from HyperCore.ttlBlocks.sweep() cannot move funds out of the position, so the fast loop can stall at a skew the float cannot correct until a recenter.maxOrderFraction of NAV (10% at most by code, 2% in the presets) and HyperCore's minimum order is 10 USDC. A vault below about 105 USDC of NAV can never place an order; at the preset 2% it needs about 500 USDC.poke(). Wallet-estimated swaps usually carry less gas than minGasForLoop.