fix(safe): refuse execution of future-nonce proposals by default (EXSC-690) - #2127
fix(safe): refuse execution of future-nonce proposals by default (EXSC-690)#21270xDEnYO wants to merge 2 commits into
Conversation
…C-690) confirm-safe-tx warned about a future-nonce proposal and still offered to broadcast it, even though execTransaction is a guaranteed GS026 revert at that point. The stale-nonce branch a few lines above already hard-refuses the same class of guaranteed revert; this makes the future case consistent. The decision now lives in safe-utils as the pure predicate canExecuteWithNonceStatus, which has a test file (confirm-safe-tx does not and is not unit-testable as written). ALLOW_FUTURE_NONCE_EXECUTION=true is the escape hatch for the one legitimate case: an RPC reporting an out-of-date on-chain nonce, which makes an executable proposal look like a future one. Signing is unaffected — only execute actions consult the gate, so signatures can still be collected while the blocking proposal is pending. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 27 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
WalkthroughChangesSafe nonce execution gating
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
script/deploy/safe/confirm-safe-tx.ts (1)
663-714: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winDo not report a guaranteed revert when the override permits execution.
future-nonce-overrideenters this branch withcanExecute: true, yet the output still says execution “WILL REVERT” and recommends recreating a blocking proposal. Split the refusal diagnostics from the override path; the latter should state that the configured RPC reports a nonce gap and execution is proceeding by explicit override.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@script/deploy/safe/confirm-safe-tx.ts` around lines 663 - 714, Update the nonceDecision handling around the `GS026` warnings so the guaranteed-revert/refusal diagnostics are emitted only when `nonceDecision.canExecute` is false. For the `canExecute` override path, report that the configured RPC indicates a nonce gap and execution is proceeding because `ALLOW_FUTURE_NONCE_EXECUTION=true`, without recommending a blocking proposal or claiming the transaction will revert.
🧹 Nitpick comments (1)
script/deploy/safe/safe-utils.test.ts (1)
551-584: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winParameterize the nonce-decision matrix.
These cases repeat the same invocation/assertion shape. Use a table-driven test so each status/override/result is one row and the test follows Arrange-Act-Assert consistently.
As per coding guidelines, “Use parameterized tests to reduce code duplication when testing multiple scenarios” and “Follow Arrange-Act-Assert (AAA) pattern.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@script/deploy/safe/safe-utils.test.ts` around lines 551 - 584, Refactor the canExecuteWithNonceStatus test suite into one table-driven test containing a row for each status, allowFutureNonce setting, and expected result. For each row, arrange the inputs, invoke canExecuteWithNonceStatus, then assert the result, preserving all existing stale, future, override, and current-nonce outcomes.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@script/deploy/safe/confirm-safe-tx.ts`:
- Around line 663-714: Update the nonceDecision handling around the `GS026`
warnings so the guaranteed-revert/refusal diagnostics are emitted only when
`nonceDecision.canExecute` is false. For the `canExecute` override path, report
that the configured RPC indicates a nonce gap and execution is proceeding
because `ALLOW_FUTURE_NONCE_EXECUTION=true`, without recommending a blocking
proposal or claiming the transaction will revert.
---
Nitpick comments:
In `@script/deploy/safe/safe-utils.test.ts`:
- Around line 551-584: Refactor the canExecuteWithNonceStatus test suite into
one table-driven test containing a row for each status, allowFutureNonce
setting, and expected result. For each row, arrange the inputs, invoke
canExecuteWithNonceStatus, then assert the result, preserving all existing
stale, future, override, and current-nonce outcomes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 644e71eb-3468-4984-83cf-c9ed73000c04
📒 Files selected for processing (4)
.env.examplescript/deploy/safe/confirm-safe-tx.tsscript/deploy/safe/safe-utils.test.tsscript/deploy/safe/safe-utils.ts
- emit the GS026 guaranteed-revert diagnostics only when execution is refused; the override path now states it proceeds on the assumption of an out-of-date RPC nonce (CodeRabbit review) - add a refusal hint to re-run after the blocking proposal was executed elsewhere (the on-chain nonce is fetched once per run) - parameterize the canExecuteWithNonceStatus test matrix (CodeRabbit nitpick) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Which Linear task belongs to this PR?
EXSC-690
Why did I implement it this way?
confirm-safe-tx.tsprinted a GS026 warning for a proposal whose nonce is ahead of the Safe'son-chain nonce and then still offered
Proceed anyway? (will revert with GS026). Taking thatoption broadcasts a transaction that cannot succeed — gas is spent on a guaranteed revert and the
resulting failure is confusing to read back. Five lines above, the stale-nonce branch (the same
class of guaranteed revert) already hard-refuses with no override, so the two branches disagreed
about the same problem.
Consistency with the stale-nonce branch. The future-nonce execute path now refuses by default,
matching the stale branch. The stale branch itself is unchanged in behaviour.
Escape hatch for the stale-RPC case. The one legitimate reason to broadcast anyway is a lagging
RPC under-reporting the Safe's on-chain nonce, which makes an already-executable proposal look like
a future one.
ALLOW_FUTURE_NONCE_EXECUTION=truere-enables execution for that case only; it doesnot unlock the stale branch, because a stale reading would require an RPC reporting a nonce ahead
of consensus. The flag follows the existing
DRAIN_PARKED_TASKS/isDrainEnabled()convention —a small predicate helper (
isFutureNonceExecutionAllowed()), not an inlineprocess.envread — andis documented in
.env.example.Predicate placed in safe-utils for testability.
confirm-safe-tx.tshas no test file and is notunit-testable as written (interactive prompts, MongoDB and RPC side effects). The decision is
therefore a pure exported function in
safe-utils.ts, which has a colocatedsafe-utils.test.ts:The console UX (messages, colours, the blocking-proposal lookup) stays in
confirm-safe-tx.ts,which just switches on
reason.safe-utils.tsgains no import fromsafe-decode-utils.ts(rule 201 unaffected).
Signing is still permitted — only execution is refused. The action list is built before the
gate and always offers
Signfor an unsigned proposal, independent of nonce status. Only the fourexecute actions consult the predicate, so signatures can keep accumulating on a future-nonce
proposal while the blocking one is still pending. The refusal message says so explicitly and points
at the override flag.
Governance impact (rule 105): none. This does not change any Safe threshold, timelock delay,
role, owner set, or transaction authorization path. It only prevents broadcasting a transaction
that would revert on-chain; which transactions are authorized, and by whom, is untouched.
Verification (worktree,
origin/main@ 358c2b9):bun test script/deploy/safe/safe-utils.test.ts-> 42 pass, 0 fail (8 new)bunx eslinton the three changed.tsfiles -> exit 0bunx tsc-files --noEmiton the three changed.tsfiles -> exit 0Checklist before requesting a review
Checklist for reviewer (DO NOT DEPLOY and contracts BEFORE CHECKING THIS!!!)