mirror of
https://github.com/luxfi/precompile.git
synced 2026-09-24 00:26:21 +00:00
dex: pin what margin, perps, teleport and vaults actually do
Four files at 0% coverage, now 99.6 / 100 / 95.1 / 100. Tests only; no source line changed. 51 of 52 mutations caught, the survivor proven equivalent rather than assumed: at profit == 0 the fall-through computes a zero fee, a zero net, a no-op add and returns a fresh zero, which is byte-identical to the early return no test can separate. The reachability verdict comes first, because it decides how to read the rest. Nothing dispatches to any of it. MarginEngine, TeleportBridge, OmnichainRouter, VaultManager and PerpetualEngine have zero references outside their own files, the five registered modules reach none of them, and all four are pure in-memory Go with no StateDB anywhere -- so they cannot take part in a state transition even if something did call them. Every defect below is latent. Two of them are the same shape that produced three universal forgeries in zk this week: a length check returned as a verdict. verifyWarpMessage is `return len(message) > 0`, so any non-empty byte string authorises a mint, and it never looks at the teleport id it is handed. Alongside it, bridge signatures are counted and never examined -- three copies of one byte satisfy a threshold of three. Seven public entry points panic on arithmetic: division by a zero leverage, zero size, zero margin, zero index price, zero total assets, and a CreateVault that slices a strategy name to ten bytes without checking its length -- the engine's own LP_YIELD is eight, so creating a vault over it is an unconditional panic. RouteTransfer takes the write lock and then calls GetBestRoute, which takes the read lock on the same non-reentrant mutex, so every routed transfer deadlocks permanently. The margin constants are all ten times their documented values, which is one root cause with three consequences: above 20x a long's liquidation price sits above its entry, the long/short ordering inverts, and fees at 750bps exceed maintenance at 500bps -- so the full-fee liquidation branch is dead code and every liquidation is a socialised loss. Also latent: a daily transfer limit stored and never enforced, admin actions with no caller argument at all and an operator list nothing reads, a fee floor that can exceed the amount transferred, an over-close that pays PnL on phantom size, a withdrawal solvency check that restates what the caller already proved, and a leverage ceiling bypassed by a uint64 truncation. Three uncovered blocks, each provably unreachable and named in the report: one is unreachable precisely because the check guarding it is vacuous.
This commit is contained in: