{
 "commit": "03dc2d5a727b1195ec82857a98506f632529e280",
 "lens": "funds and accounting",
 "verdict": "findings",
 "counts": {
  "high": 1,
  "medium": 2,
  "low": 2,
  "info": 0
 },
 "findings": [
  {
   "id": "funds-1",
   "severity": "high",
   "title": "Success without a provable result document freezes the site and the pool for good (proveJob costs ~370-420 gas/byte, cap is 262,144 bytes)",
   "where": "src/Changeme.sol: _head() NeedsProof, retry(), proveJob(), MAX_RESULT_DOC_BYTES",
   "scenario": [
    "Deploy; Alice contributes 0.5 IMD; round 1 is sent as attempt 1.",
    "Intake reports success: onResult stores resultHash, head becomes NeedsProof.",
    "Nobody can supply a document that proveJob accepts. Cases: the document is larger than about 85-95 KB, so proveJob needs more than a block of gas; the writer's hash does not match a retrievable document; the document does not parse as the strict top-level jobId shape. Intake does not check the hash or document, per docs/intake.md.",
    "retry() reverts HeadNeedsProof, skip() reverts NothingToRecover (activeAttempt is 0), dispatch()/contribute() return false. Contributions keep pooling and nothing can ever be sent."
   ],
   "impact": "Permanent freeze: no build ever again and all pooled IMD stays stranded, with no refund path. This breaks the rule that nothing may freeze the site for good. The repo's own test testUnusableSuccessProofLeavesQueuedRoundBlockedAfterOneDay asserts this behavior. Whether a real result document exceeds the gas limit is unknown until a live build, but the 262,144 cap is above what a block can process.",
   "proof": "Own tests in test/scratch/F.t.sol. testNeedsProofFreezeForever passed: after success without proof and a warp of 3650 days, retry reverts HeadNeedsProof, skip reverts NothingToRecover, dispatch() is false and 5 IMD sits in openPool. Gas of proveJob alone (revert-message readout): 64,000-byte document 23,790,874 gas; 250,000-byte document 93,014,096 gas; ~22 KB document of 2000 small objects 9,340,243 gas. All were accepted by the 262,144 cap but are above or near the block gas limit at the larger sizes.",
   "fix": "In _head(), when the newest attempt Succeeded, has no jobId and block.timestamp >= settledAt + RECOVERY_DELAY, return (Unknown,\"\",false). Then retry(parent) works after one day with a caller-supplied parent. I applied it in my clone: runtime 24,362 -> 24,430 bytes (+68, 146 spare). My test FixCheck.testRetryAfterProofTimeout passed: early retry reverts, retry at +1 day works, pool untouched. The old repo test above then needs updating. Also lower MAX_RESULT_DOC_BYTES to about 65,536 (a constant, 0 bytes).",
   "liveOnly": true
  },
  {
   "id": "funds-2",
   "severity": "medium",
   "title": "Cheap front-run of a sponsored retry with a wrong parent job id burns the round and locks recovery",
   "where": "src/Changeme.sol: retry() with HeadMode.Unknown",
   "scenario": [
    "Build 2 fails (status 2): the head is Unknown and the round is retryable at once.",
    "An honest sponsor prepares retry(correctParent).",
    "An attacker front-runs with retry(any well-formed UUID that is not the project head), paying 0.5 IMD.",
    "The attempt is Pending: the honest retry reverts NotRecoverableYet until the Intake reports, or for up to one day if it never does. The attacker's attempt fails or is refused.",
    "Repeat at 0.5 IMD per cycle."
   ],
   "impact": "Temporary freeze and delay of every recovery, at a cost of one job price per cycle to the attacker. Contributors lose nothing and the pool is untouched.",
   "proof": "testWrongParentGrief passed: after a failure, SPONSOR calls retry with a bogus UUID (accepted), then ALICE's retry(JOB1) reverts with NotRecoverableYet.",
   "fix": "No small safe fix found. Options: document it, or only let the first retry after a failure name a parent once per day (extra storage, ~100+ bytes, untested). I judge it acceptable if the README says so.",
   "liveOnly": false
  },
  {
   "id": "funds-3",
   "severity": "medium",
   "title": "A full open round (50 wishes) can be bought for about 5 IMD that is not lost, blocking honest contributions during a build",
   "where": "src/Changeme.sol: contribute() RoundFull, MAX_ROUND_WISHES",
   "scenario": [
    "A build is running or the head is not dispatchable (active attempt, NeedsProof, Unknown).",
    "The attacker makes 50 contributions of 0.1 IMD each with spam wishes.",
    "contribute() by anyone else reverts RoundFull until the build ends and the round can be sent. The 5 IMD stays in openPool and pays for later builds, so the attacker's net cost is low."
   ],
   "impact": "Temporary denial of contribution and capture of the next build's wishes, at low net cost. No IMD is lost.",
   "proof": "testSpamFill passed: after a round-2 build starts, 50 contributions of 0.1 IMD fill round 3 and an honest contribute reverts RoundFull.",
   "fix": "Untested idea: in contribute(), when the round is full, seal it and open the next round instead of reverting. This costs about 100-200 bytes, with the 214 byte budget being tight. Alternative: only document it.",
   "liveOnly": false
  },
  {
   "id": "funds-4",
   "severity": "low",
   "title": "A late success for an abandoned attempt is ignored: IMD is spent, the build exists, but no version is recorded",
   "where": "src/Changeme.sol: onResult stale branch, retry()/skip() after 1 day",
   "scenario": [
    "Attempt is sent and the Intake is slow for over one day.",
    "Anyone calls skip() or retry().",
    "The success callback arrives and only emits StaleCallback."
   ],
   "impact": "Wishes were built off-chain but the contract does not show them as a version. Anyone can rebuild (sponsor pays). Bounded by the one day delay.",
   "proof": "Existing tests testSilentRetryAtOneDay... and testSilentSkipAtOneDay... assert this (versionCount stays 1). I read them and did not write my own.",
   "fix": "Document it. No code change.",
   "liveOnly": false
  },
  {
   "id": "funds-5",
   "severity": "low",
   "title": "IMD sent directly, or pooled while the Intake price is retired or very high, cannot be recovered",
   "where": "src/Changeme.sol: no sweep or refund; _livePrice(), _tryDispatch()",
   "scenario": [
    "Someone transfers IMD to the contract directly: it is not in openPool and nothing can move it.",
    "Or the Intake owner raises the price above openPool, or returns 0 or reverts for the actions: dispatch never happens and the pool cannot be withdrawn."
   ],
   "impact": "Stranded IMD. The direct transfer is the sender's own act and accounting is unaffected; the price case is trust in the Intake owner. The README admits the direct-transfer case.",
   "proof": "testDirectStranded passed: balance 1 IMD, openPool 0. The price case I reasoned from _tryDispatch (returns false when price is 0 or above the pool); I did not run a test.",
   "fix": "None without adding a withdrawal path, which the rules forbid. Document it.",
   "liveOnly": false
  }
 ],
 "checked": [
  "Invariant totalContributed+totalSponsored == openPool+totalSpent: every path updates both sides (contribute adds to contributed and pool; retry adds to sponsored and, via _send, spent; _tryDispatch moves price from pool to spent). Existing fixture account() asserts it, and the pool balance, payee balance and zero allowance.",
  "Exact approval: IntakeBinding.submit zeroes any old allowance, approves exactly the live price, then requires zero remaining. It also re-reads the price and compares it to the expected price.",
  "_pull only pulls from msg.sender and checks the balance delta; IMD sent directly does not enter the accounting and cannot break the delta check.",
  "Pool spend: _tryDispatch requires openPool >= price and subtracts only the price; surplus carries to the next round. retry never touches the pool.",
  "maxPrice: contribute and retry revert the whole transaction if the price is above maxPrice; dispatch() and skip() spend only pooled IMD (maxPrice is unlimited by design).",
  "Narrowing casts: uint128(amount), uint128(price), uint64 round and token ids, uint40 timestamps: all are bounded by the IMD supply and by realistic values. I found none that truncates.",
  "Reentrancy: all entry points that move IMD are nonReentrant. The callbacks cannot run inside _send because the request id is recorded after submit and unknown ids revert. The IMD token has no hooks.",
  "No double spend: each attempt is settled once (status Pending check and activeAttempt match); a replayed or stale callback only emits an event.",
  "Callback gas: onResult and onFailure do bounded storage writes. The fixture requires lastDelivered within the 200,000 stipend and passes.",
  "Request body size: 50 wishes of 140 escaped bytes plus the brief is about 15 KB, below the 16,384 cap, so a full round cannot be paid and then rejected for size.",
  "Recovery paths other than funds-1: Failed or Refused attempts can be retried or skipped at once; a silent attempt after one day; skip dispatches the next round if the head is known."
 ],
 "commands": [
  "git clone https://github.com/identity-md-launches/goal-3599-have-swarm-build-test and git checkout 03dc2d5a727b1195ec82857a98506f632529e280: ok",
  "forge test --offline (original suite): 88 passed, 0 failed",
  "forge test --offline --match-path test/scratch/F.t.sol: testNeedsProofFreezeForever, testWrongParentGrief, testSpamFill, testDirectStranded passed; gas readouts as in funds-1",
  "forge build --sizes --offline: Changeme runtime 24,362 bytes at the commit, 24,430 with my fix",
  "forge test --offline with my fix applied: FixCheck.testRetryAfterProofTimeout passed; the repo test testUnusableSuccessProofLeavesQueuedRoundBlockedAfterOneDay then fails, as expected, because it asserts the freeze",
  "No transaction was sent and no order placed; no live chain was used."
 ]
}