# Audit report

> Audit src/seats/SeatJoin.sol, src/seats/SeatAccount.sol, src/feeds/SeatFeed.sol, at the pinned commit, for a capped mainnet beta. Read whatever else in src/ these depend on, but report on this scope.
>
> imdUSD v2 is a multi-collateral CDP stablecoin; this is its capped mainnet beta on Ethereum. Positions are NFT ids; borrowers set their own interest rate and redemptions take from the lowest rates first; liquidation is mark then bite, with a standing bid from Backstop sleeves; the peg pool is a Uniswap v4 pool with our own hook; prices come from Chainlink and from swarm-attested feeds (EIP-712 attestations bound to pinned questions). README.md gives the scope, the key invariants, the trust model and the known issues: read it first.
>
> BUILD AND TEST (required; Foundry, solc 0.8.26 via_ir per foundry.toml). Never build or test the whole project: with every suite it needs about 49 GB and the compiler will be killed. Run only this panel's tests: `forge test --match-path 'test/unit/{Seats,ReviewSeats,SeatDigest,PanelSeatTransfer}.t.sol'` (measured: about 3.0 GB peak, 5 minutes). One build at a time on your machine. Write each proof as a new file test/unit/Proof<Name>.t.sol, add it to the glob and run it; paste it with its output into the finding, then delete it: your submission must leave the tree unchanged. With Foundry 1.9 or later, `forge test --use solar --no-match-path 'test/fork/*'` builds everything and runs all 1,179 tests in seconds under 1 GB (Solar accepts a little syntax solc refuses: confirm a proof with the solc command).
>
> Answer each numbered question, including the ones where nothing is wrong:
> 1. CUSTODY (deposit, withdraw, holderOf, units per holder, onPositionTransfer, rescue, the holder-bound rule). Take a seat you do not own, or count units twice.
> 2. AUCTION (open, take, takeFloor, reopen, cancel; the priced clock _elapsed, AUCTION_LIFE, the decay). Sell below the intended price, block a sale, or settle the wrong debt.
> 3. SEAT ACCOUNT (ERC-1271 pairing, custodyEpoch, send and SEND_GAS, registerAgent, release). A worker authorisation that survives a change of custody, or a signature that can be misused.
> 4. REWARDS (onRewards, owed, collect, yieldFee, lastHolder). Credit rewards to the wrong holder, or create a credit with nothing behind it.
> 5. SEAT FEED (the fall cap, poke, the ring, median30dAgo, trend and factor). Move the seat price faster than the caps allow.
>
> Not findings: anything listed under README.md 'Known issues and accepted risks' (say so if you find it worse than written); src/bridge, src/dex, src/earn/LoopVault.sol and src/stocks (after the beta) unless a question names them; test/ and its mocks; gas optimisations unless they change behaviour.
>
> For every finding: severity by impact; file, line and the lines copied; the call sequence from an external caller; a concrete failing input or state with expected against actual; whether it is reachable with the values in script/DeployConfig.sol (BetaConfig); the smallest fix; and a Foundry test that fails on this commit, RUN as BUILD says and pasted in full in the finding with its output (the judge reruns it). The test/ tree has harnesses to reuse (test/utils/System.sol, the unit suites). Answer every numbered question, including those where nothing is wrong. Give a coverage row (holds, finding or unreached, with a reason) for every external function of the contracts in scope. Also report every comment or NatSpec that claims a property the code does not have.

| | |
|---|---|
| Repository | https://github.com/fa11up/imdusd-v2-audit.git |
| Commit | `2875ffb22a726f041bd6891f32f35ddc7cdb983d` |
| Job | `3d73817d-9b86-45c4-b371-4e179fb3bb38` |
| Judged | 2026-11-10 21:07 UTC |
| Findings | 2 medium · 2 low · 3 info |

Four agents audited the code as it is at `2875ffb`, 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: Auction clock counts the hours the median was stale as priced time when a late-relayed attestation lands: the sale jumps to the floor (Q2)

`src/seats/SeatJoin.sol:470`

```
            uint256 end = Math.min(t, Math.max(freshUntil, uint256(newAt) + life));
            if (end > from) ran += end - from;
```

Merged from four specialist reports (audit_math a76defcc, audit_flow f1275fcb, audit_economics de24a03a): the same root cause in both branches of _elapsed. SeatJoin._elapsed (lines 459-480) rebuilds PRICED time from the median leaf's updatedAt. For a swarm leaf that is the attestation's signed issuedAt (SwarmFeed.submitAttestation -> _accept(value, a.issuedAt), SwarmFeed.sol:324). submitAttestation accepts any issuedAt that is still within maxAge (26 h in BetaConfig, SEAT_MAX_AGE, DeployConfig.sol:711) and not older than the current one. The relay time is kept only in the private _acceptedAt. Branch 1 (line 470, newAt <= freshUntil) counts from..min(t, newAt+life) as fresh. Take an attestation issued before the old one aged out but relayed after it did: the whole stale gap is counted. During that gap take/takeFloor/reopen revert NotPriced (Liquidator.settle -> _requireUnhealthy). The gap branch (lines 476-478, from2 = max(from, newAt)) does the same thing for an attestation issued during the gap and relayed later. A tick during the gap does not help: it sets lastTick but the later relay still counts from it. Impact: in the relay's block the Dutch price jumps from where priced time left it to the 0.7 x start floor. The relayer (relaying is permissionless; attestations can be bought) can take() in the same transaction, or trigger takeFloor. The borrower loses up to 30% of the fall-capped median per seat out of the surplus that take pays them (_settle line 592: toBorrower = left - penalty). At the beta's $4,000 seat that is up to $1,200 per seat, $3,600 for a 3-seat position. A counted gap of 24 h or more voids the auction instead of pausing it. The defect contradicts SeatJoin.sol:53-54 ('a missed daily refresh pauses the sale instead of running it to the floor unseen') and SeatJoin.sol:456 ('the clock only ever runs slow, never fast'). Reachable with BetaConfig: the seat type is on, maxAge is 26 h and refreshes are daily, so any late refresh opens the window. Smallest fix: start the new window at the moment the chain first saw the attestation, not at its issuedAt. Expose SwarmFeed._acceptedAt through an acceptedAt() view (passed through by the leaf). In _elapsed use start = max(newAt, acceptedAt) for the new window, in both branches; in branch 1, when acceptedAt > freshUntil, count the old window only to freshUntil. Without a new view, count the new window from block.timestamp of the first read that sees it: the clock then runs slow, as documented.

**Reproduction**

State (attached proof, mocks: a leaf whose updatedAt = issuedAt with maxAge 26 h; ETH/USD 3000e18; median 1e18 wei): the Liquidator opens auction 1 at T0, while the live median attestation was issued at T0-25h. Start price is 3000e18. At T0+11h the median has been stale for 10 h and elapsed(1) == 3600: correct, the clock is paused. Input: relay an attestation issued at T0+1h (10 h old, accepted by SwarmFeed). Expected: elapsed(1) == 3600 and price(1) == 2850e18. Actual: elapsed(1) == 39600 and price(1) == 2100e18 (the floor), with expired(1) == false, so take(1, 2100e18) settles at the floor. Run (Foundry 1.8.3, solc 0.8.26 via_ir per foundry.toml): the four specialist proofs copied to test/scratch/ and run with `forge test --match-path 'test/scratch/*.t.sol'` (3m22s): 0 passed, 4 failed. Output for this proof: '[FAIL: priced time must not include the hours the chain was stale: 39600 != 3600] test_heldAttestationRunsTheAuctionClockThroughStaleHours() (gas: 391406)'. The branch-1 variant (audit_flow proof Proof_f1275fcbd380) also fails: auction opened with 1 h of life left, 12 h stale gap, then an attestation issued at T0+20h is relayed: '[FAIL: the clock ran during the stale gap: 46800 > 3600] test_lateRelayCountsStaleGapAsPricedTime() (gas: 449614)'. After the fix (window counted from the relay), elapsed stays 3600 and both pass.

**Proof**: a Foundry test that fails on this code and passes once it is fixed.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import {Test} from "forge-std/Test.sol";
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {SeatJoin} from "src/seats/SeatJoin.sol";
import {IImdAgentAdapter} from "src/seats/SeatAccount.sol";
import {SeatFeed} from "src/feeds/SeatFeed.sol";
import {IFeed} from "src/interfaces/IFeed.sol";
import {ParametersBase} from "src/ParametersBase.sol";

/// @dev A swarm leaf as SeatJoin sees it: `latestValue` returns the attestation's `issuedAt` (SwarmFeed sets
/// `_updatedAt = a.issuedAt`, and accepts an attestation up to `maxAge` after it was issued). `acceptedAt` is the
/// block time of the relay (SwarmFeed keeps it privately as `_acceptedAt`): what a fix needs to read.
contract MockLeaf is IFeed {
    uint256 public value;
    uint64 public updatedAt;
    uint64 public acceptedAt;
    uint256 public figure;
    uint256 public immutable maxAge;

    constructor(uint256 maxAge_) {
        maxAge = maxAge_;
    }

    function set(uint256 v, uint64 issuedAt) external {
        value = v;
        updatedAt = issuedAt;
        acceptedAt = uint64(block.timestamp);
    }

    function setFigure(uint256 f) external {
        figure = f;
    }

    function latestValue() external view returns (uint256, uint64) {
        return (value, updatedAt);
    }

    function isStale() external view returns (bool) {
        return value == 0 || block.timestamp > uint256(updatedAt) + maxAge;
    }

    function latestFigure() external view returns (uint256) {
        return figure;
    }
}

contract MockParams {
    ParametersBase.Config internal _c;
    address public governor = address(0xA11CE);

    function setMedian(IFeed m) external {
        _c.median = m;
    }

    function config(bytes32) external view returns (ParametersBase.Config memory) {
        return _c;
    }
}

contract MockLedger {
    address public params;
    address public treasury;
    address public token;
    address public liquidator;

    constructor(address p, address t, address tok, address l) {
        params = p;
        treasury = t;
        token = tok;
        liquidator = l;
    }
}

/// @notice SeatJoin._elapsed counts the new attestation's window from its `issuedAt`, which SwarmFeed lets a relayer
/// hold for up to `maxAge` (26 h in BetaConfig) before relaying. Hours in which the chain was STALE (no sale could
/// settle: Liquidator.settle requires `priced`) are then counted as priced time once the held attestation lands,
/// so the Dutch clock jumps and the sale is takeable at the floor, against the documented pause.
contract ProofSeatClockTest is Test {
    uint256 constant T0 = 1_800_000_000;
    address constant LIQUIDATOR = address(0x11);
    address constant MARKER = address(0x22);

    MockLeaf median;
    MockLeaf spot;
    MockLeaf eth;
    SeatFeed feed;
    SeatJoin join;

    function setUp() public {
        vm.warp(T0);
        median = new MockLeaf(26 hours); // SEAT_MAX_AGE in BetaConfig
        spot = new MockLeaf(26 hours);
        eth = new MockLeaf(365 days);
        // The median attestation live at the opening was issued 25 h ago: fresh for one more hour.
        median.set(1e18, uint64(T0 - 25 hours));
        median.setFigure(100);
        spot.set(1e18, uint64(T0));
        eth.set(3000e18, uint64(T0));
        feed = new SeatFeed(median, spot, eth);
        MockParams params = new MockParams();
        params.setMedian(IFeed(address(feed)));
        MockLedger ledger = new MockLedger(address(params), address(0x33), address(0x44), LIQUIDATOR);
        join = new SeatJoin("SEAT", IERC721(address(0x55)), IImdAgentAdapter(address(0x66)), address(this), 25, 3);
        join.wire(address(ledger));
    }

    function test_heldAttestationRunsTheAuctionClockThroughStaleHours() public {
        vm.prank(LIQUIDATOR);
        join.open(1, MARKER);
        uint256 start = join.price(1);
        assertEq(start, 3000e18);

        // One priced hour, then ten hours in which the median leg is stale on chain: no take can settle.
        vm.warp(T0 + 11 hours);
        assertTrue(feed.isStale());
        assertEq(join.elapsed(1), 1 hours, "while stale the clock is paused, as documented");

        // A relayer now relays an attestation ISSUED at T0 + 1 h (10 h old, inside SwarmFeed's maxAge) and takes in
        // the same transaction. The chain was unpriced for those ten hours.
        median.set(1e18, uint64(T0 + 1 hours));
        assertFalse(feed.isStale());
        assertFalse(join.expired(1), "11 h < AUCTION_LIFE: the auction is takeable");

        // Expected: 1 h of priced time, price 0.95 x start. Actual on this commit: 11 h, the floor (0.7 x start).
        assertEq(join.elapsed(1), 1 hours, "priced time must not include the hours the chain was stale");
        assertEq(join.price(1), start * 95 / 100, "the sale must not be at the floor");
    }
}
```

### 2. Medium: SeatFeed's liquidity term reads the attested figure with no bound: one attestation moves both priced legs past every fall cap (Q5)

`src/feeds/SeatFeed.sol:168`

```
        uint256 n = ISeatFigure(address(median)).latestFigure();
        return Math.min(1e18, Math.mulDiv(n, 1e18, FULL_LIQUIDITY));
```

Merged from audit_math c3eb2b0a and audit_flow 46ef0bf1. Both legs the Pricer reads for SEAT are price x factor: SeatFeed.latestValue (line 237) and SeatSpotLeg.latestValue (line 263). factor = liquidity x trend, and liquidity = min(1, figure/100) is read straight from the median leaf's latestFigure(). SwarmSeatFeed._onFigure (src/feeds/SwarmFeeds.sol:111-113) stores the signed figure with no bound. SwarmFeed's deviation/epoch cap bounds only the answer, and SeatFeed's 20% MAX_FALL_PER_UPDATE_BPS bounds only acceptedMedian. An attestation that keeps the price and drops the figure (150 -> 10) therefore cuts both legs by 90% in one step. Because both legs carry the same factor, the Pricer's skew check (agree) still passes. Because acceptedMedian is unchanged, the fall cap sees no fall. Every seat position becomes liquidatable at once: at mat 250%, any position under about 90% of max borrow. A figure of 0 makes the value 0 (unpriced), which freezes the type. A figure rise likewise loosens LTV past the caps (50 -> 100 doubles the value). Liquidator.bark/bite then open auctions at medianUsd() (no factor), so borrowers lose the chop penalty plus up to 30% Dutch discount. This contradicts the SeatFeed header (lines 35-40: falls bounded at 20% per update) and the README trust model (an attester 'can move those feeds within the cap per epoch'). An honest figure is a 7-day distinct-seat count and can also drop sharply when a burst of sales ages out of the window. Reachable with BetaConfig: the seat type is on, and SEAT_MEDIAN_CAP_BPS 3000 caps the answer only. Smallest fix: cap the liquidity term per new attestation the way the median is capped. Record the accepted figure in Cap (base/raw like the median) and have liquidity() read _capped(figure, acceptedFigureBase), so it falls at most MAX_FALL_PER_UPDATE_BPS per attestation. Alternatively, bound the figure's step against the previous figure in SwarmSeatFeed._onFigure.

**Reproduction**

State (attached proof, mock leaves): median 2e18 wei with figure 150, spot 2e18, ETH/USD 2000e18. Both SeatFeed.latestValue() and SeatSpotLeg.latestValue() are 4000e18. Input: one new median attestation with the same value 2e18 and figure 10, then poke(). Expected: no leg falls more than the widest cap any leaf grants (2 x 30% = 60%), so both legs >= 1600e18. Actual: both legs read 400e18 (-90%), and acceptedMedian() is still 2e18. Run (Foundry 1.8.3, solc 0.8.26 via_ir per foundry.toml): the four specialist proofs copied to test/scratch/ and run with `forge test --match-path 'test/scratch/*.t.sol'` (3m22s): 0 passed, 4 failed. Output: '[FAIL: median leg fell past every cap in one attestation: 400000000000000000000 < 1600000000000000000000] test_oneAttestationMovesThePricedValueNinetyPercent() (gas: 471399)'; logs: median leg before 4000e18, median leg after one attestation 400e18, spot leg after one attestation 400e18. audit_math's variant (figure 100 -> 20, latestValue 3000e18 -> 600e18) also fails: '[FAIL: one attestation moved the seat price past the 20% fall cap: 600000000000000000000 < 2400000000000000000000]'.

**Proof**: a Foundry test that fails on this code and passes once it is fixed.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import {Test} from "forge-std/Test.sol";
import {SeatFeed, SeatSpotLeg} from "src/feeds/SeatFeed.sol";
import {IFeed} from "src/interfaces/IFeed.sol";

/// @dev A seat leaf as SwarmSeatFeed exposes it: a value (bounded by the swarm's per-epoch cap, 30% in BetaConfig)
/// and a signed `figure` (the distinct seats sold) that `_onFigure` stores with no bound at all.
contract Leaf is IFeed {
    uint256 public value;
    uint64 public at;
    uint256 public maxAge = 26 hours;
    uint256 public latestFigure;

    function set(uint256 v, uint256 figure) external {
        value = v;
        latestFigure = figure;
        at = uint64(block.timestamp);
    }

    function latestValue() external view returns (uint256, uint64) {
        return (value, at);
    }

    function isStale() external view returns (bool) {
        return value == 0 || block.timestamp - at > maxAge;
    }
}

contract ProofSeatFigureUncapped is Test {
    Leaf median;
    Leaf spot;
    Leaf ethUsd;
    SeatFeed feed;
    SeatSpotLeg spotLeg;

    function setUp() public {
        vm.warp(1_800_000_000);
        median = new Leaf();
        spot = new Leaf();
        ethUsd = new Leaf();
        median.set(2e18, 150); // $4,000 per seat, 150 distinct seats sold: liquidity = 1
        spot.set(2e18, 150);
        ethUsd.set(2000e18, 0);
        feed = new SeatFeed(median, spot, ethUsd);
        spotLeg = new SeatSpotLeg(feed);
    }

    /// The trust model bounds a compromised or wrong attestation to the per-epoch cap (30% on the seat leaves, 20%
    /// per update on the accepted median). The seat type's priced value also carries `liquidity = min(1, figure/100)`,
    /// and the figure is not capped anywhere: one attestation with the same price and a figure of 10 moves BOTH
    /// legs the Pricer reads down 90%, so every seat position is unhealthy at once.
    function test_oneAttestationMovesThePricedValueNinetyPercent() public {
        (uint256 before,) = feed.latestValue();
        (uint256 spotBefore,) = spotLeg.latestValue();
        assertEq(before, 4000e18);
        assertEq(spotBefore, 4000e18);

        vm.warp(block.timestamp + 1 hours);
        median.set(2e18, 10); // the price is unchanged, the figure falls from 150 to 10
        feed.poke();

        (uint256 after_,) = feed.latestValue();
        (uint256 spotAfter,) = spotLeg.latestValue();
        emit log_named_uint("median leg before", before);
        emit log_named_uint("median leg after one attestation", after_);
        emit log_named_uint("spot leg after one attestation", spotAfter);
        assertEq(feed.acceptedMedian(), 2e18, "the fall cap sees no fall at all");
        // Expected: no leg falls past the widest cap any swarm leaf allows per epoch (2 x 30% = 60%).
        assertGe(after_, before * 40 / 100, "median leg fell past every cap in one attestation");
        assertGe(spotAfter, spotBefore * 40 / 100, "spot leg fell past every cap in one attestation");
    }
}
```

### 3. Low: Fall cap is inert until the first poke: over an empty cap state every attestation is accepted raw, not only the first, and the beta deploy never pokes (Q5)

`src/feeds/SeatFeed.sol:120`

```
        return t > c.at ? _capped(m, _capped(c.raw, c.base)) : _capped(m, c.base);
```

Merged from audit_math 8c93eb9b and audit_economics d8d15887. The constructor records nothing when the median leaf is empty (lines 99-100). The beta deploys the seat legs empty (script/DeployConfig.sol:657), and no script under script/ calls poke(): `grep -rn 'poke()' script/` returns nothing. While cap == (0,0,0), acceptedMedian computes _capped(m, _capped(0, 0)). The lowest bound is 0, so the live reading passes raw. That is intended for the seed attestation, but it stays true for every later attestation until someone pokes. Until then, the only bound on a fall is SwarmFeed's epoch cap (30%, widened up to 2x after staleness), not the 20% per update. SeatJoin._open starts auctions at that uncapped median. This contradicts SeatFeed.sol:50-53 ('an unpoked fall is capped harder ..., never looser') and lines 96-98 (only 'the first attestation relayed is accepted raw'). It is limited to the window before the first permissionless poke, hence low. Smallest fix: in _record and acceptedMedian, treat an empty cap with a nonzero live reading as anchored on that reading: record (raw=m, base=m, at=t) at the first poke, and call seatFeed.poke() in the deploy stage right after the seed relay. Or deploy SeatFeed after the seed relay so the constructor anchors it.

**Reproduction**

SeatFeed constructed over an empty median leaf, ETH/USD 2000e18. Relay a seed of 2e18 (acceptedMedian 2e18, raw as intended). One day later, with no poke, relay 1e18. Expected: acceptedMedian() == 1.6e18. Actual: 1e18. Control: with poke() between the two relays the result is 1.6e18 (PASS). Run: `forge test --match-path 'test/scratch/*.t.sol' --match-test 'proof|Poke' -vv` -> 'Ran 2 tests for test/scratch/ProofCapBeforePoke.t.sol:ProofCapBeforePoke [PASS] test_control_withPokeTheCapBinds() (gas: 259077) [FAIL: fall cap did not bind before the first poke: 1000000000000000000 != 1600000000000000000] test_secondAttestationBeforeFirstPokeIsNotCapped() (gas: 163895) Logs: acceptedMedian: 1000000000000000000'.

**Proof**: a Foundry test that fails on this code and passes once it is fixed.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import {Test} from "forge-std/Test.sol";
import {SeatFeed} from "src/feeds/SeatFeed.sol";
import {IFeed} from "src/interfaces/IFeed.sol";

contract CapLeaf is IFeed {
    uint256 public value;
    uint64 public at;
    uint256 public constant maxAge = 26 hours;

    function set(uint256 v) external {
        value = v;
        at = uint64(block.timestamp);
    }

    function latestValue() external view returns (uint256, uint64) {
        return (value, at);
    }

    function isStale() external view returns (bool) {
        return value == 0 || block.timestamp - at > maxAge;
    }

    function latestFigure() external pure returns (uint256) {
        return 100;
    }
}

/// SeatFeed deployed over an EMPTY median leaf (the beta deploy, script/DeployConfig.sol:657); no deploy stage pokes.
contract ProofCapBeforePoke is Test {
    CapLeaf median;
    CapLeaf spot;
    CapLeaf eth;
    SeatFeed feed;

    function setUp() public {
        vm.warp(1_800_000_000);
        median = new CapLeaf();
        spot = new CapLeaf();
        eth = new CapLeaf();
        eth.set(2000e18);
        feed = new SeatFeed(median, spot, eth);
    }

    function test_secondAttestationBeforeFirstPokeIsNotCapped() public {
        median.set(2e18); // the seed relay: accepted raw, as documented
        assertEq(feed.acceptedMedian(), 2e18);
        vm.warp(block.timestamp + 1 days);
        median.set(1e18); // the next daily attestation, a 50% fall, nobody has poked yet
        emit log_named_uint("acceptedMedian", feed.acceptedMedian());
        assertEq(feed.acceptedMedian(), 1.6e18, "fall cap did not bind before the first poke");
    }

    function test_control_withPokeTheCapBinds() public {
        median.set(2e18);
        feed.poke();
        vm.warp(block.timestamp + 1 days);
        median.set(1e18);
        assertEq(feed.acceptedMedian(), 1.6e18);
    }
}
```

### 4. Low: A borrower under auction can swap the pledged seat for another one in the same block: take delivers whatever seats end the owner's list (Q1/Q2)

`src/seats/SeatJoin.sol:505`

```
        uint256[] storage list = _seats[owner];
        for (uint256 i; i < n; ++i) {
            uint256 tokenId = list[list.length - 1];
            _unlist(tokenId, owner);
            SeatAccount(_accountFor(tokenId, false)).release(msg.sender);
```

From audit_permissions 3e4ba1f1, reproduced. take and takeFloor deliver the last n entries of _seats[owner] at execution time. withdraw (line 296) only needs a wallet unit and holderOf; it does not check whether the holder's position is under auction. A borrower whose position is on sale and who owns a spare seat (perBorrower 3 in BetaConfig) can call deposit(spare), which mints a unit, then withdraw(pledged, self), which burns it and unlists the pledged seat. The position still holds 1e18 units and the auction stays live. take then releases the spare to the taker, who priced the sale on seatsOf(owner) and cannot bind tokenIds in take(id, maxPrice). Solvency is not affected, because the oracle prices all seats alike and the header (lines 29-31, 60-62) declares units fungible among a holder's seats. The taker gets a seat that was never pledged, possibly a less valuable one, and the borrower keeps the one they wanted to keep. The same swap can front-run takeFloor and change which seat the Treasury keeps. Smallest fix: refuse withdraw while any of the holder's positions has a live auction (the join knows auctions by position id; the Ledger's cancel hook already exists). Or let take/takeFloor take the expected tokenIds (or a hash of the list) and revert on mismatch.

**Reproduction**

Harness test (inherits test/unit/Seats.t.sol, so it cannot go in the self-contained proof field): alice pledges seat 1 (debt 1,500 imdUSD), the median and spot crash to 1.6 ETH, and liquidator.liquidate(id) opens the auction. seatsOf(alice)[0] == 1. Alice calls seatJoin.deposit(2) then seatJoin.withdraw(1, alice). Bob calls seatJoin.take(id, max). Expected: nft.ownerOf(1) == bob. Actual: ownerOf(1) == alice and ownerOf(2) == bob. Source:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import {SeatsTest} from "../unit/Seats.t.sol";
import {SeatAccount} from "../../src/seats/SeatAccount.sol";
import {_pid} from "../utils/Pid.sol";

contract ProofHarness is SeatsTest {
    function test_proof_borrowerSwapsPledgedSeatBeforeTake() public {
        _pledge(alice, 1, 1_500e18);
        _crash();
        uint256 id = _pid(SEAT, alice);
        liquidator.liquidate(id);
        assertEq(seatJoin.seatsOf(alice)[0], 1, "taker prices seat 1");
        vm.startPrank(alice);
        seatJoin.deposit(2);
        seatJoin.withdraw(1, alice);
        vm.stopPrank();
        _cash(bob, 5_000e18);
        vm.startPrank(bob);
        usd.approve(address(seatJoin), type(uint256).max);
        seatJoin.take(id, type(uint256).max);
        vm.stopPrank();
        emit log_named_address("owner of seat 1 (pledged)", nft.ownerOf(1));
        emit log_named_address("owner of seat 2 (never pledged)", nft.ownerOf(2));
        assertEq(nft.ownerOf(1), bob, "taker should receive the seat that was pledged");
    }

    function test_proof_syncOfSeatCollectionBooksUnpayableCredit() public {
        vm.prank(alice);
        SeatAccount acct = SeatAccount(seatJoin.deposit(1));
        acct.sync(address(nft));
        emit log_named_uint("reported[nft]", acct.reported(address(nft)));
        emit log_named_uint("owed[1][nft][alice]", seatJoin.owed(1, address(nft), alice));
        vm.expectRevert(SeatAccount.SendFailed.selector);
        seatJoin.collect(1, address(nft), alice);
        assertEq(nft.ownerOf(1), address(acct));
        assertEq(seatJoin.owed(1, address(nft), alice), 0, "the seat is custody, not a reward: no credit");
    }
}

Output: '[FAIL: taker should receive the seat that was pledged: 0x328809Bc894f92807417D2dAD6b7C998c1aFdac6 != 0x1D96F2f6BeF1202E4Ce1Ff6Dad0c2CB002861d3e] test_proof_borrowerSwapsPledgedSeatBeforeTake() (gas: 3509268) Logs: owner of seat 1 (pledged): 0x3288...(alice); owner of seat 2 (never pledged): 0x1D96...(bob)'.

### 5. Info: SeatAccount.sync accepts the seat collection itself and books a credit that can never be paid (Q4)

`src/seats/SeatAccount.sol:201`

```
    function sync(address token) public {
        uint256 bal = IERC20(token).balanceOf(address(this));
        uint256 seen = reported[token];
        if (bal <= seen) return;
        reported[token] = bal;
        ISeatJoinForAccount(join).onRewards(tokenId, token, bal - seen);
```

From audit_permissions d56d2783, reproduced. claim refuses target == nft, but sync has no such guard, and ERC-721 balanceOf(address) shares the ERC-20 selector. sync(address(nft)) on an account that holds its seat (plus any strays) reads 1, sets reported[nft] = 1 and credits owed[tokenId][nft][holder] = 1. collect then calls nft.transfer(address,uint256). The IDMD collection (BetaConfig IDMD 0x0000eC93127BAA929E58E97dd0095A2BFb38ec1D) has no such function: eth_getCode on chain 1 returns 10,464 hex chars with PUSH4 0x23b872dd and 0x6352211e but no 0xa9059cbb. So collect reverts SendFailed. The result is a credit with nothing payable behind it and a misleading Rewarded event, not a custody bypass. On a collection that did implement transfer(address,uint256), collect would move the seat out of custody. Fix: in sync, revert when token == address(nft) or token == join.

**Reproduction**

Same harness file as the previous finding: alice deposits seat 1, and anyone calls acct.sync(address(nft)). Logs: reported[nft] = 1, owed[1][nft][alice] = 1. collect(1, nft, alice) reverts SendFailed, and the seat stays in the account. Output: '[FAIL: the seat is custody, not a reward: no credit: 1 != 0] test_proof_syncOfSeatCollectionBooksUnpayableCredit() (gas: 528492)'.

### 6. Info: NatSpec and comments that claim properties the code does not have

`src/seats/SeatJoin.sol:33`

```
/// SALE. `Liquidator.bite` opens a Dutch auction: the raw 7-day median, decaying to
```

(1) SeatJoin.sol:33 says the auction starts at 'the raw 7-day median'. _open (line 402) uses SeatFeed.medianUsd(), the fall-capped median, as lines 68 and 389-391 say (merged: audit_flow 5b450431, audit_permissions 05f2fecf). (2) SeatJoin.sol:53-54 and 456 ('pauses the sale instead of running it to the floor unseen'; 'the clock only ever runs slow, never fast'): false for a late-relayed attestation (medium finding above). (3) SeatFeed.sol:50-53 ('an unpoked fall is capped harder ..., never looser'): false before the first poke (low finding above). (4) SeatFeed.sol:30-31 says the ring slot holds 'the raw USD median first poked that day'. poke (line 219) stores medianUsd(), the fall-capped median. (5) SeatFeed.sol:18 and 39 ('a rise never loosens'; 'the trend term already keeps a rise from loosening the LTV'): trend only keeps factor <= 1. A median rise raises latestValue 1:1, bounded only by the leaf's epoch cap (30%, up to 2x after staleness), and the later fall back is throttled at 20% per attestation (audit_permissions f999d444). (6) SeatFeed.sol:35-38 and README trust model: the per-update cap is stated as the bound on the seat price, but the factor is not under it. The figure is unbounded (medium finding above). The trend term, computed in USD, compounds a capped 20% median step into a 36% value step (0.8 x 0.8), and an ETH/USD move enters both through ethUsd and through trend (audit_math 8c5e3dc2; design question, not a separate defect). (7) SeatJoin.sol:616 calls lastHolder 'the operator who earned it'. Credit goes to whoever holds the seat when the arrival is REPORTED (header lines 42-44): a taker who re-deposits and syncs in the same transaction is credited unreported arrivals from the previous tenure (audit_flow 397f53ef; documented behaviour, so the comment overclaims). (8) SeatAccount.sol:170-171 'once': agentId is never cleared on release/bump, so a later holder can never re-register (AlreadyRegistered) while the previous holder's URI stays bound (audit_permissions 5442909f; whether that matters depends on the off-chain registry).

**Reproduction**

(1) Median attested 2 ETH, then 1.2 ETH, at ETH $2,000: rawMedianUsd() == 2400e18 but medianUsd() == 3200e18, and an auction opened then has price(id) == 3200e18 (the test suite's test_auctionWithBadDebt also shows the stepped acceptedMedian). (4) poke() writes ring[today].value = medianUsd(), line 219-224. (5) median 2 -> 2.6 ETH: latestValue 4000e18 -> 5200e18, trend() == 1e18. (2) and (3) are reproduced by the tests in the findings above.

### 7. Info: Answers to Q1-Q5, coverage of every external function in scope, and specialist leads dropped

`src/seats/SeatJoin.sol:64`

```
contract SeatJoin is TransientReentrancyGuard, IHolderJoin, IAuctionJoin {
```

ANSWERS.
Q1 CUSTODY: holds, except the low finding (the pledged seat can be swapped out before a take).
- deposit: SeatJoin calls nft.transferFrom(msg.sender, account, id), so only the token's owner (with SeatJoin approved) can deposit, and ownerOf == account is checked afterwards. holderOf is set to msg.sender and one unit is minted.
- withdraw: needs holderOf == msg.sender and burns one wallet unit, so a seat you do not hold cannot be taken.
- onPositionTransfer: onlyLedger. It moves n seats with the position, within perBorrower, and bumps each seat's epoch.
- rescue: governor only. It refuses an account's own seat while holderOf != 0, and SeatAccount.rescue refuses its own tokenId.
- Units are not counted twice. _settle retires exactly n x UNIT: the pool is set to poolBefore - n x UNIT, the treasury and marker cut units are restored, and totalSupply -= n x UNIT. takeFloor mints n x UNIT to the Treasury for the n seats it _assigns. seatCount moves only on deposit/withdraw/take and across the Treasury boundary.
- The invariant 'wallet + Ledger units == 1e18 x seats' holds through the swap scenario, which is why the swap is a taker-facing low and not a custody break.
Q2 AUCTION: FINDING (medium): a late-relayed attestation runs the clock through stale hours. Otherwise holds:
- _price decays linearly from startPrice to 0.7 x startPrice over 6 h of priced time (mulDiv, no overflow).
- take pays n x p. Liquidator.settle re-checks unhealthy and the sequencer grace. liquidatePosition settles the bound version's debt and chop: chop is read from position(id).version before settling, so penalty = repaid x chop matches.
- takeFloor needs run >= AUCTION_TIME, a fresh raw spot >= p, and the budget.
- open: Liquidator only. It replaces only an expired auction.
- reopen: on a live auction it needs the floor plus a newer attestation; on an expired one, priced and unhealthy.
- cancel: needs healthy-and-priced, or no debt.
- AUCTION_LIFE 24 h < maxAge 26 h.
- Dropped lead (audit_permissions 8fec9b3b, a borrower's reopen front-runs a take at the floor): the restart is at the protocol's own current fall-capped median. Every taker valuing the seats between median and floor can take during the 6 h decay. Restarting a stuck sale from a fresh median is the stated purpose of reopen and of the life limit, and the README known issue covers decay not reaching the raw spot when the cap binds. No value is lost, so this is not a defect.
Q3 SEAT ACCOUNT: holds.
- authorizeWorker: onlyHolder. The struct is checked (wallet == this, tokenId, unexpired, account owns the seat), the digest is computed on-chain, and the pairing is stored with epoch = custodyEpoch.
- isValidSignature: VALID only for a stored, unexpired digest of the current epoch while the account owns the seat, so no Permit or order can validate.
- Every custody change bumps the epoch: release on withdraw/take/rescue-own, and bump in _assign (onPositionTransfer, takeFloor, Treasury transfer). No pairing survives a custody change.
- send: onlyJoin, with SEND_GAS 1,000,000 and a strict return check. A shortfall in caller gas makes the call fail and revert, and the credit stays.
- registerAgent: once per account. See NatSpec item (8).
- release/bump/rescue/initialize: onlyJoin.
Q4 REWARDS: holds, apart from the info finding (sync(nft) dangling credit).
- onRewards accepts only accountOf(tokenId). It credits holderOf, else lastHolder (set in _unlist), else the Treasury.
- sync reports only the balance above `reported`, and send lowers `reported` by what leaves, so for a standard token every credit has balance behind it.
- collect zeroes the credit before paying and takes the yieldFee in kind (none on the Treasury's own credit).
- Custody never moves reward tokens.
- Credit-at-report-time is documented (header lines 42-44). See NatSpec item (7).
Q5 SEAT FEED: FINDING (medium): the figure is uncapped. FINDING (low): the cap is inert before the first poke. Otherwise holds:
- _capped bounds a fall at 20%

**Reproduction**

Not a defect: the numbered answers and coverage rows are the deliverable for the questions where nothing else is wrong. Each 'holds' row was checked by reading the code path named; the reproduced findings above carry their own tests.

---

Judge's submission `51e58170b83810861a0ec831f89c9816ed9e53e685b3143b6da2716c1a2eaf86`, 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.
