Repository navigation
fix(contracts): don't let a paused FeeRouter freeze the settleChannel client refund (#849) - #889
Conversation
… client refund (#849) settleChannel pays the client refund, then routes the provider's settle leg through FeeRouter.routeSettlement, which is whenNotPaused. A paused router reverted the whole call — trapping the already-computed client refund on a Closing channel that reclaimExpired cannot rescue, contrary to PaymentChannel's "exits always open" intent. Branch the provider leg on FeeRouter.paused() (explicit view, not try/catch, so unexpected router reverts still propagate): when paused, mark the channel settlementDeferred and leave the provider share in the contract; the client refund and close proceed unconditionally. Anyone can later call the new permissionless flushDeferredSettlement to route the deferred share (and its served bytes, preserving ADR-036 weight) once the router is unpaused — recomputed from the frozen closed channel, so it routes exactly once. Scope is settleChannel only; the identical _route in withdraw() reverts under pause too but strands no client funds (provider just retries) and is tracked separately. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Gas snapshotGas changes vs baseRun: 27488987824 |
Contracts coverageLine coverage: 89.97% (1883/2093 lines) |
There was a problem hiding this comment.
Code Review
This pull request introduces a deferred settlement mechanism in PaymentChannel.sol to prevent a paused FeeRouter from freezing channel exits. When the router is paused, the client refund is still processed, and the provider's settlement leg is deferred to be flushed later via flushDeferredSettlement. The feedback suggests wrapping the paused() call in a try/catch block to ensure robustness against future router upgrades that might not implement this view function. Additionally, it is recommended to align the parameter order of the new events (SettlementDeferred and DeferredSettlementFlushed) with ChannelSettled (amount before bytes) to maintain consistency and prevent integration errors.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| // `paused()` is a staticcall to the trusted governance-set router under | ||
| // `nonReentrant`; the only state set afterward is a bookkeeping bool, no | ||
| // funds move (aderyn reentrancy-state-change FP). | ||
| // aderyn-ignore-next-line(reentrancy-state-change) | ||
| if (IFeeRouterSettlement(feeRouter).paused()) { | ||
| settlementDeferred[channelId] = true; | ||
| emit SettlementDeferred(channelId, ch.provider, settleBytes, settleAmount); | ||
| } else { | ||
| _route(ch.provider, settleBytes, settleAmount); | ||
| } |
There was a problem hiding this comment.
The explicit staticcall to IFeeRouterSettlement(feeRouter).paused() will revert the entire transaction if the governance-set feeRouter does not implement the paused() view function (e.g., due to a future upgrade, a different router implementation, or a mock router in testing). This would unconditionally brick settleChannel for all closing channels, even if the router is not paused and fully capable of routing settlements.\n\nTo ensure maximum robustness and forward/backward compatibility, wrap the paused() call in a try/catch block and default to false (not paused) if the call reverts. If the router is actually paused or fails, the subsequent _route call will still revert safely, preserving the intended behavior. (Also updated the event emission parameter order to match ChannelSettled).
bool isPaused;
try IFeeRouterSettlement(feeRouter).paused() returns (bool p) {
isPaused = p;
} catch {
isPaused = false;
}
if (isPaused) {
settlementDeferred[channelId] = true;
emit SettlementDeferred(channelId, ch.provider, settleAmount, settleBytes);
} else {
_route(ch.provider, settleBytes, settleAmount);
}
There was a problem hiding this comment.
Declined the try/catch on the hot path, with a config-time conformance probe added instead (3c6ec25).
Rationale: the bug this PR fixes is a properly paused router, where paused() returns true cleanly with no revert — so try/catch changes nothing for that case. Where it does change behavior is on a router whose paused() reverts: defaulting to false then falls through to _route, whose revert re-traps the client refund — i.e. it re-introduces the exact #849 freeze. It also silently swallows an unexpected router revert, which the explicit-view choice here deliberately avoids.
The legitimate concern — a governance-set router implementing routeSettlement but not paused() (setFeeRouter only checks code.length) — is now handled by _requireRouterExposesPausedView: the constructor and setFeeRouter static-probe the paused() selector once and revert with FeeRouterMissingPausedView if it's absent. Fail-fast and loud at config time, rather than a per-call silent catch. (Event arg order in the suggestion is also applied — see the other threads.)
| event SettlementDeferred( | ||
| bytes32 indexed channelId, address indexed provider, uint256 settleBytes, uint256 settleAmount | ||
| ); | ||
| event DeferredSettlementFlushed( | ||
| bytes32 indexed channelId, address indexed provider, uint256 settleBytes, uint256 settleAmount | ||
| ); |
There was a problem hiding this comment.
The parameter order in SettlementDeferred and DeferredSettlementFlushed is (settleBytes, settleAmount), whereas in ChannelSettled it is (routedAmount, bytesDelivered) (amount then bytes). This inconsistency can easily lead to integration errors for off-chain indexers or frontends. It is highly recommended to make the parameter order consistent across all settlement events by placing the amount before the bytes.
event SettlementDeferred(
bytes32 indexed channelId, address indexed provider, uint256 settleAmount, uint256 settleBytes
);
event DeferredSettlementFlushed(
bytes32 indexed channelId, address indexed provider, uint256 settleAmount, uint256 settleBytes
);
There was a problem hiding this comment.
Applied in 3c6ec25 — both events realigned to (settleAmount, settleBytes) to match the amount-before-bytes convention used by ChannelSettled (routedAmount, bytesDelivered), ChannelWithdrawn, and ChannelCloseInitiated.
| function flushDeferredSettlement(bytes32 channelId) external nonReentrant { | ||
| if (!settlementDeferred[channelId]) revert NoDeferredSettlement(); | ||
| Channel storage ch = channels[channelId]; | ||
|
|
||
| uint256 settleAmount = ch.claimedAmount - ch.withdrawnAmount; | ||
| uint256 settleBytes = ch.claimedBytes - ch.withdrawnBytes; | ||
|
|
||
| // Clear before the external route (checks-effects-interactions): a paused | ||
| // router reverts the whole tx and restores the flag for a later retry. | ||
| settlementDeferred[channelId] = false; | ||
| _route(ch.provider, settleBytes, settleAmount); | ||
|
|
||
| emit DeferredSettlementFlushed(channelId, ch.provider, settleBytes, settleAmount); | ||
| } |
There was a problem hiding this comment.
Update the event emission parameter order in flushDeferredSettlement to match the consistent (settleAmount, settleBytes) order.
function flushDeferredSettlement(bytes32 channelId) external nonReentrant {
if (!settlementDeferred[channelId]) revert NoDeferredSettlement();
Channel storage ch = channels[channelId];
uint256 settleAmount = ch.claimedAmount - ch.withdrawnAmount;
uint256 settleBytes = ch.claimedBytes - ch.withdrawnBytes;
// Clear before the external route (checks-effects-interactions): a paused
// router reverts the whole tx and restores the flag for a later retry.
settlementDeferred[channelId] = false;
_route(ch.provider, settleBytes, settleAmount);
emit DeferredSettlementFlushed(channelId, ch.provider, settleAmount, settleBytes);
}
There was a problem hiding this comment.
Applied in 3c6ec25 — flushDeferredSettlement now emits (settleAmount, settleBytes), consistent with the reordered event declaration.
…aused() conformance probe - Reorder SettlementDeferred / DeferredSettlementFlushed event params to (settleAmount, settleBytes), matching the amount-before-bytes convention of ChannelSettled / ChannelWithdrawn / ChannelCloseInitiated (gemini medium). - Declined the suggested per-call try/catch around paused() (it would silently swallow an unexpected router revert and, on a paused()-less router, route into _route and re-trap the client refund — the exact #849 bug). Instead probe the router's paused() selector once at config time (constructor + setFeeRouter) via _requireRouterExposesPausedView; a non-conforming router reverts loudly with FeeRouterMissingPausedView rather than bricking settleChannel later. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a deferred settlement mechanism in PaymentChannel to prevent client refunds from being blocked when the FeeRouter is paused. When a channel is settled while the router is paused, the provider's share is deferred and can be flushed later via flushDeferredSettlement once the router is unpaused. Additionally, a configuration-time check _requireRouterExposesPausedView is added to ensure the router supports the paused() view. The review feedback highlights that _requireRouterExposesPausedView should explicitly validate that the returned 32-byte value is a valid boolean (0 or 1) to prevent decoding reverts in settleChannel if a non-boolean value is returned.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| function _requireRouterExposesPausedView(address router) internal view { | ||
| // Static-probe the selector: a router missing `paused()`, or one whose | ||
| // fallback returns no bool-sized value, fails the success/length check. | ||
| (bool ok, bytes memory ret) = router.staticcall(abi.encodeCall(IFeeRouterSettlement.paused, ())); | ||
| if (!ok || ret.length < 32) revert FeeRouterMissingPausedView(router); | ||
| } |
There was a problem hiding this comment.
The _requireRouterExposesPausedView function checks that the staticcall to paused() succeeds and returns at least 32 bytes. However, it does not validate that the returned 32-byte word is a valid boolean value (i.e., exactly 0 or 1).
If the configured router has a fallback function or another implementation that returns a non-boolean 32-byte value (such as a non-zero uint256 or an address), ret.length < 32 will pass, but any subsequent call to IFeeRouterSettlement(feeRouter).paused() in settleChannel will revert due to strict Solidity boolean decoding rules. This would re-introduce the exact fund-freeze issue this PR aims to prevent.
To make this check robust and fail-fast, we should explicitly validate that the returned value is either 0 or 1 using inline assembly.
function _requireRouterExposesPausedView(address router) internal view {
// Static-probe the selector: a router missing `paused()`, or one whose
// fallback returns no bool-sized value, fails the success/length check.
(bool ok, bytes memory ret) = router.staticcall(abi.encodeCall(IFeeRouterSettlement.paused, ()));
if (!ok || ret.length < 32) revert FeeRouterMissingPausedView(router);
uint256 val;
assembly {
val := mload(add(ret, 32))
}
if (val > 1) revert FeeRouterMissingPausedView(router);
}
There was a problem hiding this comment.
Accepted — fixed in 7ec0625. The probe now also rejects a non-canonical bool word:
if (abi.decode(ret, (uint256)) > 1) revert FeeRouterMissingPausedView(router);This mirrors the strict bool decode that settleChannel's high-level paused() call performs (which reverts on a word > 1), so a router passing the probe is guaranteed to decode cleanly there. Used abi.decode rather than inline assembly — it's the codebase idiom (e.g. SlashJudge), assembly is reserved here for crypto/bit-packing helpers, and slither's assembly detector isn't excluded so asm would add informational noise. ret.length < 32 is kept (not != 32) since the high-level decoder tolerates excess returndata. Covered by test_setFeeRouter_revertsOnNonBooleanPausedReturn.
…ol (PR #889 review) The config-time conformance probe checked the paused() staticcall succeeded and returned >=32 bytes, but not that the word was a canonical bool. A router whose paused() returns a non-bool word (e.g. 2) passed the probe, yet settleChannel's high-level paused() call strict-decodes a bool and reverts on word > 1 — re-trapping the client refund the probe exists to protect. Add `abi.decode(ret, (uint256)) > 1` rejection (codebase-idiomatic decode rather than inline assembly), mirroring the high-level decode; excess returndata stays tolerated. Covered by test_setFeeRouter_revertsOnNonBooleanPausedReturn. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…recovery (PR #889 review) Multi-agent review found no bugs but flagged test depth and observability gaps: - Add test_flushDeferredSettlement_partialWithdraw_routesRemainderOnly: the load-bearing case where a prior withdraw means the deferred/flushed share must be claimed−withdrawn, not the full claim (every prior test had withdrawn==0). - Add test_settle_deferred_channelIsClosed_cannotResettleOrDispute: a deferred settle still closes the channel; second settle/dispute revert ChannelNotClosing. - Add test_flushDeferredSettlement_afterRouterRepoint_routesToNewRouter: flush after setFeeRouter routes the held share through the new router. - Pin the still-paused flush revert to the router's pause cause string. - NatSpec: document that deferred channels are discoverable only via the SettlementDeferred event (off-chain-indexer recovery; no on-chain enumeration), that outstanding deferrals follow a setFeeRouter re-point, plus two clarity tweaks (the Closed→Closing rollback counterfactual; "safe to retry" wording). No logic changes. Follow-up issue tracks optional on-chain enumeration. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Ran a multi-agent review (code / tests / silent-failures / comments) on this branch. No bugs or CI-breaking issues — accounting, CEI, and the pause/probe logic checked out. Applied the actionable findings in fe83cf2 (no logic changes):
Full local gate still green: |
) (#926) Resolve #890 (option a): keep `withdraw` reverting under a paused `FeeRouter` rather than deferring like `settleChannel`. Unlike the `settleChannel` fund-freeze fixed in #889, `withdraw` strands no client funds — the channel stays `Open` and a revert rolls back the claim- and withdrawal-watermark writes, so nothing is trapped; the provider simply re-submits the same voucher after unpause. Documents the deliberate asymmetry in NatSpec + the pause-control section comment, and adds a regression test pinning revert-under-pause (with zero state drift) followed by a clean identical-voucher retry. No behavior change. Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Summary
Closes #849.
PaymentChannel.settleChannelpays the client refund, then routes the provider's settle leg throughFeeRouter.routeSettlement, which iswhenNotPaused. When the router is paused, that revert unwound the entiresettleChannelcall — trapping the already-computed client refund on aClosingchannel thatreclaimExpiredcannot rescue (it requiresStatus.Open). This reintroduced a fund-freeze for already-closing channels, contrary to PaymentChannel's "exits always open" intent.Fix
settleChannelnow branches the provider leg onFeeRouter.paused()(an explicitview, not atry/catch, so genuinely unexpected router reverts still propagate):settlementDeferred, leaves the provider's un-withdrawn share in the contract, emitsSettlementDeferred. The client refund andstatus = Closedproceed unconditionally.flushDeferredSettlement(channelId)(new, permissionless) routes the deferred share — and its served bytes, preserving ADR-036 vote weight — once the router is unpaused. Amount/bytes are recomputed from the frozen closed channel (nowithdrawis possible afterClosed), so it routes exactly once; CEI clears the flag before the external call, so a still-paused router reverts the whole tx and leaves it retryable.IFeeRouterSettlementgains apaused()view (the realFeeRouteris Pausable)._requireRouterExposesPausedView): the constructor andsetFeeRouterstatic-probe the router'spaused()selector once and revertFeeRouterMissingPausedViewif it is absent or returns a non-canonical bool word (> 1, mirroring the strict decodesettleChannel's high-level call performs). A misconfigured router fails loud at config time rather than bricking exits — without a per-call silent catch.Scope
settleChannelonly. The identical_routeinwithdraw()reverts under pause too, but strands no client funds (provider just retries) — tracked in #890. Deferred channels have no on-chain enumeration (recovery is via the indexedSettlementDeferredevent); documented in NatSpec, with optional on-chain enumeration tracked in #902.Tests
test/PaymentChannel.t.sol(full suite green, 541 passed):claimed − withdrawn), not the full claim, and the run reconciles (300 withdraw + 400 flush == 700 claimed);flushDeferredSettlementafter unpause routes the exact share/bytes once; second flush revertsNoDeferredSettlement;setFeeRouterre-point routes through the new router;settleChannel/disputeChannel(ChannelNotClosing);setFeeRouter/constructor reject a router missingpaused()and one returning a non-bool word (FeeRouterMissingPausedView).Verification
forge fmt --check,FOUNDRY_PROFILE=ci forge build --deny warnings,forge test(541 passed),aderyn(no high),slither(exit 0) — all pass locally.Review notes
A multi-agent review (code / tests / silent-failures / comments) found no bugs or CI-breaking issues; its findings (test depth, observability docs, comment clarity) are folded in above. gemini-code-assist's event-param-order comments were applied (events realigned to amount-before-bytes, matching
ChannelSettled/ChannelWithdrawn); its suggestion to wrap the hot-pathpaused()intry/catchdefaulting tofalsewas declined — it would silently swallow router reverts and, on apaused()-less router, route into_routeand re-trap the refund (the exact #849 bug); the config-time probe (plus the accepted bool-canonicality check) addresses the underlying concern instead.🤖 Generated with Claude Code