{"item":"house-swarmfeed","commit":"ff1c192b3798542997f600091f2dc73ff05e4c40","forge":"1.8.3 (older than 1.9: --use solar unavailable; ran with solc 0.8.38 from svm, in a feeds-only side project)","verdict":"findings","findings":[{"id":"F1","severity":"low","title":"One attestation (and one second) can put the feed two caps from a value a consumer held: no per-window bound on the price/spot/seat/depth leaves","property":"P1 (measured from any value held in the window) and P3 (never two caps from what it held while every step is within the cap of its reference)","claim":"P1,P3","files":["src/house/feeds/SwarmFeed.sol:583-587","src/house/feeds/SwarmFeed.sol:597-608","src/house/feeds/SwarmFeed.sol:723-757","src/house/feeds/SwarmFeeds.sol:83-107"],"sequence":"c=2000, maxAge=3600. t0: first value 1.0 (epoch 1 opens, anchor 1.0). t0+maxAge-1: target 1.2 -> stored 1.2 (in cap). t0+maxAge: epoch 2 opens anchored at stored 1.2, target 3.0 -> stored 1.44. A consumer that held 1.0 one second earlier reads 1.44 (+44%). After a >=maxAge+1h silence on a leaf with the 2x stale base (spot, seat legs, depth; the price and NHI leaves override _staleMultiple to 1): 1.0 -> 1.4 (wide step) -> 1.68 (same epoch, one cap from anchor) -> 2.016 at the next epoch's first second = +101.6% within ~maxAge. Only the NHI leaf (_carriesAnchor) bounds windows; the price legs, spot, seat, depth do not.","expected":"<= 1.2 x held (one cap) for every single attestation relative to any value held in the preceding window","actual":"1.44e18 from 1.0e18 held 1 s earlier; 2.016e18 after a silence. The code comment (SwarmFeed.sol:61-65) states this bound as (1+c)^2-1 / (1+2c)(1+c)^2-1, so it is written, but it is not in README known issues and contradicts the sheet's P1/P3 wording.","reachableAtDeploy":true,"fix":"Carry the previous anchor on every leaf (_carriesAnchor true, as NHI), or replace epochs with a time-based slew bucket (see C4). Otherwise change P1/P3 to the (1+c)^2 statement and size consumer margins on it.","test":{"source":"contract H1 is SwarmFeed { // price/NHI-like: no widening\n    constructor(uint256 age, uint256 c) SwarmFeed(address(1), address(this), 1, 3, age, c) {}\n    function acc(uint256 t) external { _accept(t, uint64(block.timestamp)); }\n    function _staleMultiple() internal pure override returns (uint256) { return 1; }\n}\ncontract SF is Test { uint256 constant AGE=3600; uint256 constant E18=1e18;\nfunction test_P3_twoCapsAcrossEpochBoundary() public {\n        vm.warp(1_000_000);\n        H1 f = new H1(AGE, 2000);\n        f.acc(E18);                       // epoch 1 opens, anchor 1.0\n        vm.warp(1_000_000 + AGE - 1);\n        (uint256 held,) = f.latestValue(); // consumer holds 1.0\n        vm.warp(1_000_000 + AGE - 1);\n        f.acc(1.2e18);                    // epoch 1: 1.0 -> 1.2 (one cap)\n        vm.warp(1_000_000 + AGE);\n        f.acc(3e18);                      // epoch 2 opens at 1.2 -> 1.44 (one cap of its anchor)\n        (uint256 now_,) = f.latestValue();\n        emit log_named_uint(\"held\", held); emit log_named_uint(\"read one second later\", now_);\n        assertLe(now_, held * 12 / 10, \"P3: value two caps from one held 1 second earlier\");\n    }\n}\ncontract H is SwarmFeed {\n    uint256 mult;\n    bool carry;\n    constructor(uint256 age, uint256 c, uint256 m, bool cr) SwarmFeed(address(1), address(this), 1, 3, age, c) { mult = m; carry = cr; }\n    function acc(uint256 t) external { _accept(t, uint64(block.timestamp)); }\n    function _staleMultiple() internal pure override returns (uint256) { return 2; }\n}\n// in contract SF:\nfunction test_P3_afterSilence() public {\n        vm.warp(1_000_000);\n        H f = new H(AGE, 2000, 2, false);\n        f.acc(E18);\n        vm.warp(1_000_000 + AGE + 3600 + 1); // silent a lifetime + an hour\n        (uint256 held,) = f.latestValue();\n        f.acc(9e18);                          // wide step 1.4\n        vm.warp(block.timestamp + AGE - 1);\n        f.acc(9e18);                          // 1.68\n        vm.warp(block.timestamp + 1);\n        f.acc(9e18);                          // epoch 2: 2.016\n        (uint256 now_,) = f.latestValue();\n        emit log_named_uint(\"read\", now_);\n        assertLe(now_, held * 12 / 10, \"value two caps+ from held within one lifetime\");\n    }\n","ran":"RAN locally (no fork), forge 1.8.3 (no --use solar); solc 0.8.38 from local svm, via_ir off, mini project (feeds only); harness H/H1 call internal _accept(target, now) = submitAttestation after the checks; relayer=self","result":"[FAIL: P3: value two caps from one held 1 second earlier: 1440000000000000000 > 1200000000000000000] test_P3_twoCapsAcrossEpochBoundary; [FAIL: value two caps+ from held within one lifetime: 2016000000000000000 > 1200000000000000000] test_P3_afterSilence"}},{"id":"F2","severity":"low","title":"P2 (honest price re-accepted within two epochs after any push sequence) fails: a relayer landing first in each epoch slows an honest reversal to 0.96x per epoch","property":"P2","claim":"P2","files":["src/house/feeds/SwarmFeed.sol:559-567","src/house/feeds/SwarmFeed.sol:753-755"],"sequence":"Stored 1.0, honest level 0.5, c=20%. Each epoch (spaced maxAge): first relay is a target 5.0 (a pushed level, attested honestly, or any in-cap attester value) -> stored +20%; then the honest 0.5 relays, but _clampRange floors it at high x (1-c) = 1.2 x 0.8 = 0.96 x anchor. Net 0.96x per epoch. After 4 epochs stored = 0.849 (honest-only reaches 0.41 < 0.5 in 4); about 17 epochs are needed to reach 0.5.","expected":"honest 0.5 reached (or the stored value within one cap of it) in a bounded, short number of epochs; no sequence of earlier attestations can slow it","actual":"0.849346e18 after 4 epochs. The residual is written in SwarmFeed.sol:83-89 (0.96x per epoch) but is not in the README and contradicts the sheet's P2 and the in-code P2 ('no lock-out: no sequence of earlier attestations can ... move the value away from its target').","reachableAtDeploy":true,"fix":"Drop the range clamp (it is what gives a first relayer the lever) and rely on the carry/slew bucket in C4; or let a later attestation with a higher issuedAt/toBlock re-clamp from the epoch anchor only when it is in the direction of the last target.","test":{"source":"contract H1 is SwarmFeed { // price/NHI-like: no widening\n    constructor(uint256 age, uint256 c) SwarmFeed(address(1), address(this), 1, 3, age, c) {}\n    function acc(uint256 t) external { _accept(t, uint64(block.timestamp)); }\n    function _staleMultiple() internal pure override returns (uint256) { return 1; }\n}\n// in contract SF:\nfunction test_P2_firstRelayerSlowsHonest() public {\n        vm.warp(1_000_000);\n        H1 f = new H1(AGE, 2000);\n        f.acc(E18);\n        uint256 H = 0.5e18; uint256 honestAfterAge;\n        for (uint256 i; i < 4; ++i) {      // 4 epochs: no attacker would need ceil(ln2/ln1.25)=4 to reach 0.5 -> 0.41 floor\n            vm.warp(block.timestamp + AGE);\n            f.acc(5e18);                   // pushed level, first in epoch (+20%)\n            f.acc(H);                      // honest\n        }\n        (uint256 v,) = f.latestValue();\n        emit log_named_uint(\"after 4 epochs, honest 0.5e18, stored\", v);\n        assertLe(v, 0.6e18, \"P2: honest price not reached in 2-4 epochs\");\n    }\n","ran":"RAN locally, forge 1.8.3 (no --use solar); solc 0.8.38 from local svm, via_ir off, mini project (feeds only); harness H/H1 call internal _accept(target, now) = submitAttestation after the checks; relayer=self","result":"[FAIL: P2: honest price not reached in 2-4 epochs: 849346560000000000 > 600000000000000000] test_P2_firstRelayerSlowsHonest()"}}],"claims":[{"id":"C1","result":"refuted","evidence":"No way-back exists at this commit: grep for _returnAnchor/returnAnchor/wayBack finds only the history note SwarmFeed.sol:83. The only memory is the live epoch's anchor, _epochLow/_epochHigh, _carryAnchor (NHI only) and _attested (SwarmFeed.sol:230-243). Attestations are never rejected for their value (clamped), so there is no N-push lock-out of acceptance; the equivalent effect (honest price delayed) is F2 (0.96x/epoch), needing one first-in-epoch push per epoch, not boundary timing. At N=3 pushes the honest value is still accepted (testFuzz_stepsAndRecovery: 256 runs, any 6 pushes then honest-only reaches H within ceil(ln/ln1.2)+2 epochs)."},{"id":"C2","result":"holds","evidence":"There are no recorded anchors: the anchor is the stored value when an epoch opens (SwarmFeed.sol:723-724, _epoch 582-587), set only in _follow (the single writer, with _accept). Nothing a push records outlives its epoch except the stored value. Walking is possible only at one cap per epoch by design (F1/F2), 256-run fuzz of 6-step sequences found no step beyond the within-epoch range."},{"id":"C3","result":"refuted","evidence":"Incomplete as written: the gate (SwarmFeed.sol:494) is only active when attestationChainId != blockClockChainId. blockClockChainId = 1 on Ethereum AND on 4663 (SwarmFeed.sol:319), and all shipped leaves attest chain 1 (SwarmFeeds.sol DATA_CHAIN=1), so it is inert on 4663 too; only a chain other than 1/4663 (Base) is gated, and no config deploys a swarm leaf there (script/house/DeployConfig.sol: swarm nodes in Ethereum house config and RobinhoodConfig). Also not the only one-shot: the first value sets originBlock/originAt and clock (495) and the first epoch anchor with no clamp (713-717); README:1271 covers that. On 4663 the first value is bounded only by the block-clock recency rule (457-461, block.number = Ethereum's head: NOT RUN on fork)."},{"id":"C4","result":"refuted","evidence":"ONE INVARIANT: for every pair of times s<t with t-s <= maxAge, |ln(stored(t)/stored(s))| <= c, for all stored values at times in the window (a sliding-window slew bound), implemented as a log-space budget B(t) = min(c, B(last) + c*(t-last)/maxAge) spent by |ln(new/old)|, no epochs, no anchors, no range, target clamped to the budget at each acceptance. Today's design does not hold it (F1: epochs abut and only NHI carries). Can clamp+memory hold P1-P2 against a compromised attester key plus a pusher? P1 yes only with the sliding bound above (c per window, 2c at most is then unavoidable across consecutive windows); P2 (honest re-accepted within two epochs) cannot hold for ANY on-chain rule if the adversary relays an in-cap value every epoch: the contract sees honest and in-cap values as identical signed answers, so a last/first relayer decides each epoch (F2, SwarmFeed.sol:83-89). Smallest replacement: the budget design above plus relayer-independent ordering (issuedAt/toBlock monotone, already enforced) and response by lowerLine; liveness then is c per maxAge at best, honest and adversary symmetric, i.e. the residual becomes 'k epochs of attack take k epochs to undo', not 'less'."},{"id":"P4-binding","result":"holds","evidence":"submitAttestation recomputes expectedQuestionHash(fromBlock,toBlock) from a frozen per-leaf prefix (SwarmFeed.sol:445-467) and the digest covers questionHash, chainId, answerType and the feed address (EIP-712 domain). Fuzz 256 runs (testFuzz_P4_wrongQuestion): any other questionHash, and the SPOT prefix hash on the price leaf, reverts; the right hash is taken."}],"holds":[{"property":"P4 question binding","tried":"256-run fuzz over fromBlock/toBlock/span/questionHash with a signed attestation on a real SwarmPricePolicy leaf; cross-leaf prefix (SPOT on PRICE); other writers/readers: _accept is the only writer (submitAttestation; no other src/ or script/ caller of _accept/submitAttestation, grep). Cross-feed/chain replay excluded by DOMAIN_SEPARATOR(chainid,address); requestId replay by usedRequests (set before _requireQuestion, a revert undoes it)."},{"property":"P1 inside one epoch (any order, same block)","tried":"256-run fuzz, 6 steps with random dt in [1,2 maxAge] and targets 1..1e24: each stored value stays in [high(1-c), low(1+c)] of the epoch's range, and in one cap of the previous stored value across an epoch open; same-block steps included (dt>=1 only, same-timestamp covered by range clamp). Holds; the failure is only across epoch boundaries (F1)."},{"property":"No lock-out of acceptance / honest liveness without an adversary","tried":"Same fuzz: after any 6-step history the honest target H in [1e16,1e20] is stored exactly within ceil(ln(max/min)/ln1.2)+2 epochs of honest relays. Wide step after silence (2c, then c) checked: matches comment bounds (1.4, 1.68, 2.016)."},{"property":"Writers/readers of the memory state","tried":"Writers: _follow/_accept only (state: _value,_updatedAt,_acceptedAt,_movedAt,_anchor*,_epoch*,_carryAnchor,_attested), reached only via submitAttestation (the leaves expose no other path; seat/depth leaves override _onFigure only). Readers: Pricer/RateFeed/SeatFeed/ProductFeed via latestValue/converged/acceptedAt (SeatJoin.sol:504). Casts checked: uint128 (value<2^128, clamp results lie between anchor and target), uint40/uint24 exact; _clamp lower edge saturates at 0 for c=10000 (2c=20000)."}],"notRun":["[fork] first-value / block-clock behaviour on Robinhood Chain 4663 (block.number = Ethereum head): NOT RUN, no RPC used","Consumers (Pricer twin rule, seat auction) not tested; F1/F2 impact on them reasoned from code only","Full-repo build with via_ir and --use solar: NOT RUN (forge 1.8.3; side project used)"]}