# Audit report

> Re-audit the `imd-flop` folder only, at commit 3ae1cdf. It is a follow-up to audit job 8a0a3abd, so check whether each of those findings is fixed, especially the payer fail-open (run.ts:219), the reservation left after a pre-send refusal (run.ts:250), and receipt --refresh after a timeout (cli.ts:418). Treat every other folder as out of scope. Work offline and read-only. Give each finding a file and line, its impact, and steps to reproduce it.

| | |
|---|---|
| Repository | https://github.com/uxp-labs/flop-devnet-lab.git |
| Commit | `3ae1cdfa55707dd8e02678acdba57faec5aa50bf` |
| Job | `825bade0-b4e7-489c-bbe1-3be9998f00cc` |
| Judged | 2026-11-10 16:44 UTC |
| Findings | 2 medium · 8 low · 4 info |

Four agents audited the code as it is at `3ae1cdf`, each in one area (math, permissions, economics, control flow),
and a judge reproduced, merged and ranked what they found, then read the code once more itself. Nothing in the repository was changed or deployed.

## Findings

### 1. Medium: receipt --refresh: a fresh HTTP 200 read that is not an identity-matched settlement erases the booked spend and copies the receipt's state into the ledger (v8 item 6 / X1 fix is incomplete)

`imd-flop/src/cli.ts:451`

```
              const spend = fresh ? settledKnown : prev.spend;
```

Commit 1cbdbfc (v8 item 6) says only a fresh, identity-matched read may change the booked spend, but the guard tests `fresh` alone (HTTP 200 with an object body). `settledKnown` (cli.ts:441) is null whenever identityOk is false, the state is not settled/released, or settled_spend is null/invalid. In all those cases `spend` becomes null and `nextState` (cli.ts:449) is taken from the receipt, so the row is appended (cli.ts:453-455) because `spend !== prev.spend`. A booked settlement of 0.05 is replaced by spend null, and for a foreign receipt the ledger state becomes that other request's state (for example 'released'). cap_charge is kept (cli.ts:448), so the daily cap is not loosened; the damage is to the ledger of record: a proven settlement is erased, `receipt`/`status` show spend blank, and a settled attempt regresses to a non-final state. A gateway replica lag, a cached receipt, or a lookup that returns another request's receipt is enough. The same adoption of a non-matching receipt's state exists in run.ts:333 (`state: classified.state ?? "sent"` regardless of identityOk). Status of 8a0a3abd item 6: fixed only for non-200 reads (test/audit-v8.test.ts X1 passes); fresh-but-unproven reads remain open. Fix: `const trusted = fresh && identityOk; const spend = trusted && stateSettles ? settledKnown : prev.spend; const nextState = trusted ? (state ?? prev.state) : prev.state;` and do not regress a settled/released row on a non-terminal read (or raise cap_charge back to quote_padded if regression is accepted). Merged from audit_math #2, audit_permissions #1, audit_flow #1, audit_economics #3 and #4 (same line, same mechanism).

**Reproduction**

Scratch vitest on 3ae1cdf (test copy with node_modules installed; mock providers only). Setup: init --seat 9001, link --token 9001 --agent 7, cap set 5; `run --seat 9001 --job j1 --prompt 'Say hi' --max-tokens 8 --provider mock --json` -> request_id R (padded quote 0.186); `receipt R --refresh --json` with readReceipt returning {http:200, receipt:{request_id:R, state:'settled', settled_spend:0.05, reserved_spend:0.186}} -> latest ledger row for R is [settled, 0.05, 0.05] (correct). Then one more `receipt R --refresh --json`, three variants: (A1) readReceipt returns {http:200, receipt:{request_id:'imdflop-9001-someoneelse', state:'released', settled_spend:0.07}}; (A2) {http:200, receipt:{request_id:R, state:'estimated', settled_spend:null, reserved_spend:0.186}}; (A3) {http:200, receipt:{request_id:R, state:'settled', settled_spend:null}}. Expected in all three: exit 0 and the latest row unchanged [settled, 0.05, 0.05], ledger_spend 0.05 (what the X1 test requires for a 503). Actual: A1 exit 0, latest row ['released', null, 0.05], --json ledger_spend null, match {mismatch:[receipt identity mismatch; chain-final green blocked]}; A2 exit 0, latest row ['estimated', null, 0.05]; A3 exit 0, latest row ['settled', null, 0.05]. Vitest assertion `expect([l.state, l.spend, l.cap_charge]).toEqual(['settled', 0.05, 0.05])` fails in all three.

### 2. Medium: run --provider flop: the --timeout-ms timer firing during the pre-flight (chain check, child-key mint) is booked as timeout_unknown with the padded quote held against the daily cap, although no infere

`imd-flop/src/providers.ts:140`

```
      await assertPaidNetwork(this.net, this.ethRpc, this.f);
```

run.ts starts the --timeout-ms timer (run.ts:244, default 60000 ms) before provider.complete() is called. FlopProvider.complete() first runs assertPaidNetwork() (eth_chainId, faucet /chain, RPC block 0: three independent 15 s timeouts) and mintChildKey() (another 15 s timeout, providers.ts:146), and neither takes req.signal. If the timer fires during that pre-flight, the abort is only noticed when createChatCompletion() is called with an already-aborted signal: fetch rejects before a connection is opened, the thrown error is the TimeoutError DOMException (not a FlopHTTPError and not a PreSendError), and run.ts:252 classifies it as timedOut. The ledger gets a timeout_unknown row with cap_charge = padded quote (run.ts:261), the run exits 6 saying 'Spend is UNKNOWN', and the seat's daily cap capacity is reduced by a call that never happened. Nothing can release it: `receipt --refresh` on a request the gateway never saw gets a 404, which is a non-fresh read that keeps prev.cap_charge. A single-use child key with max_spend = padded quote is also minted and left unused (300 s expiry). With defaults the pre-flight can legitimately take up to ~60 s against a 60 s timer; with a --timeout-ms shorter than the RPC/faucet latency it happens every time. Fix: pass req.signal into assertPaidNetwork/mintChildKey (AbortSignal.any with their own timeouts) so the pre-flight stops when the timer fires, and immediately before createChatCompletion() `if (req.signal.aborted) throw new PreSendError('aborted before send')` so run.ts books refused_local (cap_charge 0) via the existing pre-send path. Kept from audit_economics #1.

**Reproduction**

Scratch vitest on 3ae1cdf. (I1, unit) seats/9001/gateway.key (mode 600) containing 'flop_sk_SYNTHETICPARENT0123456789'; fake fetch: 'http://eth.test' -> {result:'0x1'}, faucet /chain -> {genesisHash: NETWORKS.devnet.genesisHash}, /keys/ephemeral -> sleeps 150 ms then 201 {token:'flop_ek_SYNTHETICCHILD0123456789'}, /chat/completions -> throws init.signal.reason if the signal is already aborted (what real fetch does per spec); fake WebSocket answering chain_getBlockHash(0) with the pinned genesis. `const p = new FlopProvider(NETWORKS.devnet, keyPath, fakeFetch, 'http://eth.test'); const ac = new AbortController(); setTimeout(() => ac.abort(new DOMException('no answer within 50 ms','TimeoutError')), 50); await p.complete({model:'m', messages:[{role:'user',content:'hi'}], max_tokens:8, requestId:'imdflop-9001-aa', correlationId:'imd-job-j1', maxCostFlop:0.186, signal: ac.signal})`. Expected: a PreSendError and no inference. Actual: mint count 1, thrown error name 'TimeoutError', `instanceof PreSendError` false; the completion fetch was entered with an aborted signal and rejected immediately. (I2, end to end through run.ts with the same mechanism) seat 9001 ready with cap 0.2, mock provider whose complete() sleeps 120 ms then `if (req.signal.aborted) throw req.signal.reason`; `run --seat 9001 --job j1 --prompt 'Say hi' --max-tokens 8 --provider mock --timeout-ms 50` (padded 0.186). Expected: exit 1 'nothing sent', latest row refused_local with cap_charge 0, next run allowed. Actual: exit 6, latest row ['timeout_unknown', null, 0.186]; `run --job j2` exits 3 'padded quote 0.186 FLOP is over the remaining daily cap 0.014'; `receipt <rid> --refresh` with readReceipt returning {http:404} exits 0 and leaves cap_charge 0.186.

### 3. Low: run: a pre-send refusal whose release row cannot take the ledger lock strands the full reservation for the day (residual of v8 item 2 / TS-b)

`imd-flop/src/run.ts:261`

```
    appendLedger(h, { ...sent, ts: new Date().toISOString(), state: timedOut ? "timeout_unknown" : preSend ? "refused_local" : "error", reason, spend: null, cap_charge: preSend ? 0 : sent.cap_charge, http });
```

The v8 item 2 fix releases a pre-send reservation by appending a refused_local row with cap_charge 0. That append takes the ledger lock itself with a 5 s budget (ledger.ts:130) and throws LedgerLockError if ledger.jsonl.lock is held by a live owner (a live contender is never reclaimed; a dead one only after 30 s). The catch block at run.ts:248 does not handle that error, so main() exits 1 with the bare 'ledger lock timeout' (no request_id, no hint), the pre-call `sent` row with cap_charge = padded quote stays the latest line, and nothing was minted or spent. No command can release it afterwards: `receipt --refresh` for a never-minted request gets a 404 (non-fresh, keeps prev.cap_charge), and `status` shows it as a pending paid attempt. The README's exit-code note covers lock timeouts after a paid call; here the process knew the attempt was pre-send and spend is provably zero. Fix: wrap the release append in its own try; on LedgerLockError in the preSend case retry with a longer budget (the paid call is over, waiting is safe) and, if it still fails, exit with a CliError naming the request_id and stating that nothing was sent and the reservation is held, with a way to release it. Merged from audit_flow #2 and audit_economics #2.

**Reproduction**

Scratch vitest on 3ae1cdf (5.0 s). Setup: seat 9001 ready with `cap set 0.186` (one padded quote). Mock provider whose complete() first writes <home>/ledger.jsonl.lock containing {pid: process.pid, host: os.hostname(), token:'other'} (a live owner) and then throws PreSendError('eth_chainId mismatch'). `run --seat 9001 --job m1 --prompt 'Say hi' --max-tokens 8 --provider mock`. Expected: exit 1 'nothing sent', latest row for the request refused_local with cap_charge 0, and after the lock file is removed `run --job m2` exits 0. Actual: after ~5 s exit 1, stderr 'imd-flop: ledger lock timeout'; latest row state 'sent', cap_charge 0.186; after removing the lock file `run --job m2` exits 3 'refused locally, nothing sent: daily cap reached (0.186/0.186 FLOP today, UTC)'.

### 4. Low: receipt --refresh after a timeout: one failed read writes a receipt file with request_id "" and state null, so the attempt leaves status's pending list and shows as an unidentifiable mismatch (residua

`imd-flop/src/cli.ts:426`

```
            : { ...ident, ...saved, ...c, request_id: saved?.request_id ?? "", state: saved?.state ?? null, reserved: saved?.reserved ?? null, settled: saved?.settled ?? null, chain_final: saved?.chain_final ?? false, last_known_at: saved?.observed_at ?? null };
```

After a timeout there is a ledger row but no receipt file. On the non-fresh branch (HTTP 503, http 0, 401) request_id comes from `saved?.request_id ?? ""`, and saved is null, so cli.ts:428 writes receipts/<rid>.json with request_id "" and state null. From then on `status` leaves the attempt out of pending_receipts because a receipt file exists (cli.ts:361), and lists it under recent_receipts with a blank request_id and match=mismatch(ledger_row_missing) because matchReceipt looks the ledger row up by the empty id. A failed read proves nothing, yet it turns a pending timed-out paid attempt into an unidentifiable mismatch until a later refresh succeeds. Fix: on the non-fresh branch with no saved file either skip writing the file, or set request_id to rid (the ledger's own id, not a gateway value) so the attempt stays pending and identifiable. Kept from audit_permissions #2.

**Reproduction**

Scratch vitest on 3ae1cdf. Setup: seat 9001 ready (cap 5). `run --seat 9001 --job j1 --prompt 'Say hi' --max-tokens 8 --provider mock --timeout-ms 50` with a complete() that never answers: exit 6, no receipts/<rid>.json, `status --seat 9001 --json` has one pending_receipts entry (match pending). Then `receipt <rid> --refresh --json` with readReceipt returning {http:503, error:'HTTP 503', receipt:null}. Expected: the attempt stays pending; no receipt file with an empty id. Actual: exit 0, match {mismatch:['receipt identity mismatch; chain-final green blocked']}; receipts/<rid>.json now exists with request_id "" and state null; `status --json` has pending_receipts [] and recent_receipts [["", {match:'mismatch', fields:['ledger_row_missing']}]].

### 5. Low: run: every response-file write failure is treated as a secret-scan hit; a filesystem error (ENOTDIR/EACCES/ENOSPC) discards the paid completion, skips the receipt read and leaves the ledger at `sent`

`imd-flop/src/run.ts:281`

```
    withheld = (e as Error).message;
```

The catch at run.ts:279 assumes writeJsonSafe failed because of the secret scan and only retries the same path with redacted content (run.ts:288, 294). For a filesystem error the third write throws out of runJob: the completion that was paid for is neither saved nor printed (--json prints nothing, exit 1 with the raw ENOTDIR message), readReceipt (run.ts:298) never runs so no receipt file exists, and the final ledger row (run.ts:333) is never appended, so the attempt stays `sent` with the padded reservation and is shown as pending forever. The receipt-file catch at run.ts:312 has the same shape: with receipts/ unwritable the response is saved but the final row is skipped and the run exits 1 after a successful paid call. Fix: distinguish the scan's CliError from other errors (`e instanceof CliError`); for other errors print the text (or write to a fallback path), and still read the receipt and append the final ledger row so a paid result is never discarded. Kept from audit_flow #3.

**Reproduction**

Scratch vitest on 3ae1cdf. Setup: seat 9001 ready (cap 5); create <home>/responses as a regular file (`echo x > $IMD_FLOP_HOME/responses`). `run --seat 9001 --job j1 --prompt 'Say hi' --max-tokens 8 --provider mock --json`. Expected: the completion is shown or saved, the receipt is read, and the ledger ends in a non-`sent` state. Actual (E1): provider.calls 1, exit 1, stdout empty, stderr 'imd-flop: ENOTDIR: not a directory, open .../responses/mock-9001-<hex>.json.tmp-<pid>', receipts/ absent, latest ledger row ['sent', null, 0.186]. Variant (E2) with <home>/receipts as a regular file: response file written, exit 1 ENOTDIR, latest ledger row still ['sent', null, 0.186].

### 6. Low: init: a seat tokenId of 64 or more decimal digits (accepted by validateSeat) is rejected by the 64-hex secret scan after flop.key is written, leaving a seat that can be neither used nor re-initialised

`imd-flop/src/keys.ts:114`

```
  writeJsonSafe(identityFile(h, seat), identity, "identity.json");
```

validateSeat (keys.ts:34) accepts /^[0-9]{1,78}$/, any uint256 tokenId. The HEX64 rule in secrets.ts:52 matches any run of 64+ [0-9a-fA-F] characters, which a 64..78-digit decimal id is. initSeat writes flop.key first (keys.ts:112) and only then identity.json, which the scan refuses under field `seat`. Result: flop.key exists and identity.json does not; a second `init` says the seat already has an identity (unknown) and demands --rotate; `--rotate` calls loadSigner, which fails because identity.json is missing. The only recovery is deleting seats/<id> by hand. The same id would also be refused in every ledger row (`seat`, and request_id = imdflop-<seat>-...) and in link.json, so hash-derived tokenIds (76-78 digits, common in ERC-721 collections) cannot be used at all. Fix: reject ids longer than 63 digits in validateSeat with a clear message before anything is written (or allowlist digit-only `seat`/`tokenId`/`request_id` values in the scan), and write identity.json before, or atomically with, the key file. Kept from audit_flow #4.

**Reproduction**

Scratch vitest on 3ae1cdf. `imd-flop init --seat 1000000000000000000000000000000000000000000000000000000000000000` (64 decimal digits). Expected: exit 0 with a did/ss58, or a usage error before any file is written. Actual: exit 5 'secret scan blocked writing identity.json: seat: 64-or-more-hex (key-shaped) value'; seats/<id>/flop.key exists, seats/<id>/identity.json does not. Then `init --seat <same>` -> exit 5 'already has a FLOP identity (unknown)... pass --rotate'; `init --seat <same> --rotate` -> exit 2 'no FLOP key for seat <id>; run imd-flop init --seat <id>'.

### 7. Low: Seat ids are not canonicalised: '7' and '07' are separate local seats for the same NFT, so one tokenId can hold several live DIDs and several independent daily caps

`imd-flop/src/keys.ts:34`

```
  if (seat === UNASSIGNED || /^[0-9]{1,78}$/.test(seat)) return seat;
```

validateSeat accepts leading zeros and returns the string unchanged. Every per-seat structure is keyed by that raw string: seats/<seat>/ (paths.ts:9), the one-DID guard in initSeat (keys.ts:77), cfg.caps[seat], the spentToday filter (ledger.ts:74, e.seat === seat) and the checkLinkForRun comparison (run.ts:104). The chain-facing side normalises to a number: readSeatOwner encodes BigInt(tokenId) (gateway.ts:275) and the EIP-712 link signs BigInt(tokenId), so '7' and '07' are the same NFT on chain and both pass ownerOf and the wallet check. Impact: rule 2 (one DID per seat) is bypassed, `init --seat 7 --rotate` revokes only the DID under '7' so a compromised key's alias stays live, and the daily cap for one NFT becomes N caps. The actor is the seat holder or whoever runs the tool with the holder's wallet signature, so this breaks a stated invariant rather than giving a third party access. Fix: canonicalise in validateSeat (reject leading zeros with /^(0|[1-9][0-9]{0,77})$/ or return BigInt(seat).toString()) and reject values above 2^256-1. Kept from audit_math #3.

**Reproduction**

Scratch vitest on 3ae1cdf. (K1) fresh IMD_FLOP_HOME: `init --seat 7 --json` exit 0, then `init --seat 07 --json`. Expected: exit 5 'seat already has a FLOP identity. One DID per seat'. Actual: exit 0, a second did:key (different from seat 7's), seats/07/flop.key exists. (K2) `init/link/cap set 0.2` for seat 7 and the same for seat 07 (`link --token 07 --agent 7`, `cap set 0.2 --seat 07`), then four mock runs `run --seat 7 --job a`, `--seat 7 --job b`, `--seat 07 --job c`, `--seat 07 --job d` (padded 0.186 each). Expected: exits [0,3,3,3] (one NFT, one 0.2 FLOP/day cap). Actual: exits [0,3,0,3]: 0.372 FLOP booked against NFT 7 in one day.

### 8. Low: Daily cap can be exceeded by up to ~5e-7 FLOP: booked spend is rounded to nearest, not up, and the remaining balance is rounded to nearest, not down

`imd-flop/src/run.ts:220`

```
      const left = Math.round((cap.daily - spentBefore) * 1e6) / 1e6;
```

spentBefore comes from sumCharges (ledger.ts:70, `return round6(sum)` with round6 = Math.round(n*1e6)/1e6), which can under-count the true booked spend by up to 5e-7, and `left` at run.ts:220 (holder) and run.ts:225 (requester) rounds the remainder to the nearest 1e-6. Both roundings favour the spender, so `q.padded > left` can admit a quote larger than the true remaining cap. cap_charge values with more than 6 decimals are ordinary: a settled_spend from a gateway receipt (knownSettledSpend accepts any finite value >= 0) or a reported cost_flop (run.ts:328) goes into the ledger unrounded. The overrun is bounded by about 5e-7 FLOP per cap window, hence low, but a fail-closed spend guard should round spent up and remaining down. The specialist's second variant (remaining rounded up with cap 0.3720005 and quotes 0.186 + 0.186001) did not reproduce: the float subtraction lands just under the half and the second run is refused with exit 3. Fix: compare unrounded (refuse if rawSpent + q.padded > cap.daily) or use ceil for spent and floor for left, at both run.ts:220 and run.ts:225. Kept (first variant only) from audit_math #1.

**Reproduction**

Scratch vitest on 3ae1cdf. Setup: seat 9001, `cap set 1` (daily 1, perCall 1), provider estimate {estimated_cost_flop:0.066, estimated_input_tokens:3, estimated_output_tokens:8} (padded 0.186). Five mock runs (jobs j0..j4) whose readReceipt returns state 'settled' with settled_spend 0.1628, 0.1628, 0.1628, 0.1628, 0.1628004 (each below its 0.186 reservation, so run.ts:330-333 books the settled value). Sum of the latest cap_charge per request = 0.8140004 (true remaining 0.1859996 < 0.186). Sixth run `run --seat 9001 --job j6 --prompt 'Say hi' --max-tokens 8 --provider mock`. Expected: exit 3 (padded 0.186 over the remaining cap). Actual: exit 0 (spentToday = round6(0.8140004) = 0.814, left = 0.186, `0.186 > 0.186` false); total booked today 1.0000004 > daily cap 1.

### 9. Low: receipt --refresh seeds seat/did/ss58/network from the ledger row only when no receipt file exists, so a receipt file written before 8ca1fbb without those fields stays a permanent mismatch (residual o

`imd-flop/src/cli.ts:419`

```
          const ident = saved ? {} : (() => {
```

v8 item 3 fixed the first refresh after a timeout by seeding the identity fields from the ledger row when there is no receipt file. The defect it fixed had already produced receipt files without seat/did/ss58/network for anyone who refreshed a timed-out request on the earlier code. For those files `saved` is non-null, `ident` is {}, and the merge never fills the missing fields, so matchReceipt keeps reporting mismatch on seat, did, seat(link), did(link) on every refresh while the settlement is booked, exactly the symptom the fix was meant to remove. Fix: seed `ident` whenever saved lacks seat or did and a ledger row exists (`const ident = saved?.seat && saved?.did ? {} : fromLedgerRow()`). Kept from audit_flow #5.

**Reproduction**

Scratch vitest on 3ae1cdf. Setup: seat 9001 ready (cap 5); `run --seat 9001 --job j1 --prompt 'Say hi' --max-tokens 8 --provider mock --json` -> R; edit receipts/R.json to delete the keys seat, did, ss58 and network (the shape the pre-8ca1fbb refresh-after-timeout wrote). `receipt R --refresh --json` with readReceipt returning {http:200, receipt:{request_id:R, state:'settled', settled_spend:0.05}}. Expected: match {matches, []} and the file gains seat/did/ss58/network from the ledger row, as happens when no file exists. Actual: exit 0, match {mismatch, ['seat','did','seat(link)','did(link)']}, the file still has no `seat` key, and every later refresh gives the same result.

### 10. Low: Requester job budget is per invocation, not per job: a later run may pass a larger --job-budget and spend past the budget already recorded for that job, while the daily cap does not count these calls

`imd-flop/src/run.ts:225`

```
      const left = Math.round((o.jobBudget! - spentBefore) * 1e6) / 1e6;
```

The README says --job-budget 'caps the total requester-paid spend on that job' and that the FLOP still comes out of the seat's own gateway key. In requester mode spentToday() is not consulted (run.ts:213), and the only limit is o.jobBudget, supplied fresh on every invocation. Every ledger row records job_budget, but lockedCheck never compares the new value with the budget already recorded on that job's rows, so the budget can be raised after it is used up, and a new job id starts from 0. The actor is whoever runs the CLI on the holder's machine (the same operator who can edit config.json), so this is a documented-behaviour gap and a trust assumption rather than a third-party bypass: `config set payer requester` switches the seat's funds from the daily cap to a per-run, operator-chosen limit with only the per-call cap left. Fix that keeps the design: bind the budget to the job (keep the first job_budget recorded for a job and refuse a run whose --job-budget differs, or charge against the recorded value), or state in the README that the budget is per invocation and that the daily cap does not protect the seat in requester mode. Merged from audit_permissions #3 and audit_economics #5 (trust assumption).

**Reproduction**

Scratch vitest on 3ae1cdf. Setup: seat 9001, `cap set 0.2` (daily 0.2, perCall 0.2), config.json payer edited to 'requester'. Three runs `run --seat 9001 --job j1 --prompt 'Say hi' --max-tokens 8 --provider mock --job-budget B` with B = 0.2, 0.2, 0.4 (padded 0.186 each). Expected: exits [0,3,3], j1 never exceeds its recorded 0.2 budget. Actual: exits [0,3,0], two completions, j1's rows show job_budget 0.2, 0.2, 0.4, 0.4 with total cap_charge 0.372 > 0.2; `status --json` reports today_utc.mock 0 because requester rows are excluded from spentToday.

### 11. Info: receipt --refresh on a flop receipt needs --live, which the help text and README omit, and the refusal message says the read-only refresh would spend FLOP

`imd-flop/src/cli.ts:90`

```
    if (!opts.live) throw new CliError("--provider flop spends real devnet FLOP: it needs --live, a cap, a fully signed link and an enrolled gateway key", EXIT.REFUSED_RULE);
```

The HELP line for receipt (cli.ts:44) is `receipt <request_id> [--refresh] [--json]` and the README table says the same, but makeProvider (cli.ts:409 -> cli.ts:90) refuses provider flop without --live. A receipt read uses the parent bearer and a GET only and spends nothing, yet the holder following the documented command on a real timed-out attempt gets exit 5 with a message about spending FLOP. The run timeout hint (run.ts:263) says 'Check later with imd-flop receipt <rid>', which without --refresh --live can never clear a timeout_unknown reservation. Fix: construct FlopProvider for receipt --refresh without the --live gate (or accept --live only for complete()), document --live for receipt, and make the timeout hint include --refresh. Merged from audit_flow #6 and audit_economics #6.

**Reproduction**

Scratch vitest on 3ae1cdf. Setup: seat 9001 ready (cap 1); append to ledger.jsonl a timeout_unknown row with provider 'flop', request_id 'imdflop-9001-deadbeef00000000', seat '9001', cap_charge 0.186 (what a real timed-out paid run leaves). `receipt imdflop-9001-deadbeef00000000 --refresh --json`. Expected: a gateway read, or a usage message naming --live for receipt reads. Actual: exit 5, stderr 'imd-flop: --provider flop spends real devnet FLOP: it needs --live, a cap, a fully signed link and an enrolled gateway key'; `imd-flop help` prints the receipt line without --live.

### 12. Info: Verified fixed at 3ae1cdf: 8a0a3abd item 1 (TS-a), payer fail-open formerly at run.ts:219

`imd-flop/src/run.ts:161`

```
  if (cfg.payer !== "holder" && cfg.payer !== "requester") {
```

A config.json payer outside holder|requester is refused with exit 3 before the estimate (run.ts:161-163), and the requester branch additionally refuses a non-finite remaining budget (run.ts:226). The NaN comparison that let every call through is unreachable. Trust assumption unchanged: config.json is holder-owned and hand-editable; the check fails closed on any value it does not recognise. Reported by audit_flow #7 and audit_economics #7; both confirmed.

**Reproduction**

Full suite in a scratch copy of 3ae1cdf: `npx vitest run` -> 14 files, 165/165 tests pass, including test/audit-v8.test.ts 'v8 item 1' x5 (payer 'sponsor', 'Holder', '', null, 7: three runs with cap 0.2 give exits [3,3,3], 0 estimates, 0 completions, 0 `sent` rows) plus the two controls (holder [0,3,3] with one completion; requester with --job-budget 0.2 [0,3]).

### 13. Info: Verified fixed at 3ae1cdf on the main path: 8a0a3abd item 2 (TS-b), reservation left after a pre-send refusal formerly at run.ts:250

`imd-flop/src/run.ts:259`

```
    const preSendWithheld = preSend && scanForSecrets({ reason }).length > 0;
```

A PreSendError from complete() now appends a refused_local row with cap_charge 0 for the same request_id (run.ts:261); a key-shaped message (bare 64-hex, 78-digit decimal, Bearer, flop_ek_) is replaced by a fixed string first so the secret scan never refuses the release row, stderr carries the same withheld text, and the next run proceeds. Two residuals are reported separately: the release append can itself fail under ledger lock contention (low finding at run.ts:261), and a --timeout-ms abort during the flop pre-flight is not classified as pre-send (medium finding at providers.ts:140). Reported by audit_flow #8 and audit_economics #8; both confirmed.

**Reproduction**

Full suite in a scratch copy of 3ae1cdf passes 165/165, including test/audit-v8.test.ts 'v8 item 2' x6: seat 9001 with cap 0.186, complete() throwing PreSendError with each of 'eth_chainId error: ' + 'ee'x32, 'Ethereum chain id <78-digit> is not 1', 'rpc error: Bearer SYNTHETICNOTAKEY0123456789', 'rpc error: flop_ek_SYNTHETICNOTAKEY0123456789' and two clean controls: exit 1, latest row refused_local with cap_charge 0, none of the key-shaped strings in ledger.jsonl or stderr, and `run --job m2` exits 0 with one completion.

### 14. Info: Verified fixed at 3ae1cdf for new receipt files: 8a0a3abd item 3 (TS-c), receipt --refresh after a timeout formerly at cli.ts:418

`imd-flop/src/cli.ts:421`

```
            return { seat: ledgerRow!.seat, did: ledgerRow!.did, ss58: id && id.did === ledgerRow!.did ? id.ss58 : null, network: ledgerRow!.network };
```

When a timed-out run has a ledger row but no receipt file, the first refresh seeds seat, did, network from the ledger row and ss58 from identity.json only when its DID equals the row's DID, on both the fresh and non-fresh branches, so the receipt file matches on every refresh and the settlement is booked. Residuals reported separately: a receipt file written by the earlier code without those fields is never seeded (low finding at cli.ts:419), and a failed first refresh writes a file with request_id "" that drops the attempt from status's pending list (low finding at cli.ts:426). Item 6 (X1) is fixed for failed reads only; see the medium finding at cli.ts:451. Reported by audit_flow #9 and audit_economics #9; both confirmed.

**Reproduction**

Full suite in a scratch copy of 3ae1cdf passes 165/165, including test/audit-v8.test.ts 'v8 item 3': `run --job j1 --timeout-ms 50` against a hanging mock (exit 6, no receipts/R.json), then `receipt R --refresh --json` twice with a settled 0.05 receipt: match {matches}, file has seat 9001, did and ss58 equal to identity.json, network devnet; `status` shows no mismatch; ledger latest [settled, 0.05, 0.05]. 'v8 item 6' x4 (HTTP 503 and http 0 after a normal and a timed-out run) also pass.

---

Judge's submission `9a806c9125be4cfa1b4bc94d914bb37f7688acfae7f6ca9296b9093a86da220c`, accepted on the IdentityMD network. Acceptance means the report met the job's checks;
it is not a guarantee that the code has no other defects.
