fix(script): don't panic when a broadcast sequence and its sensitive-cache file desync - #16580
Open
gomesalexandre wants to merge 1 commit into
Open
Conversation
…cache file desync fill_sensitive() indexed sensitive.transactions[i] directly with no bounds check. save() writes the broadcast file then the sensitive-cache file as two separate writes; an interruption between the two (Ctrl-C, disk full) leaves them with a different number of entries, and the next load() panicked on the out-of-bounds index instead of erroring. Fixed to validate the entry counts match exactly before any mutation - catching both a shorter AND a longer cache, not just the shorter case, and never partially filling transactions before reporting the mismatch. The same bug shape existed one level up in multi_sequence.rs::load() for multi-chain deployments, fixed the same way. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
gomesalexandre
marked this pull request as ready for review
September 2, 2026 20:57
gomesalexandre
requested review from
0xrusowsky,
DaniPopes,
figtracer,
grandizzy,
mablr,
mattsse and
stevencartavia
as code owners
September 2, 2026 20:57
Contributor
✅ Changelog foundThe deterministic check will validate the changed entry. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
fill_sensitive()indexedsensitive.transactions[i]directly with no bounds check:save()writes the broadcast file, then the sensitive-cache file, as two separate writes after every transaction. A Ctrl-C or a full disk landing between those two writes leaves them with a different number of entries. The nextload()then panics with an out-of-bounds index instead of erroring.The same bug shape existed one level up in
multi_sequence.rs::load()(sensitive_sequence.deployments[i]) for multi-chain deployments, fixed the same way since it callsfill_sensitiveand needed updating for the signature change anyway.Fix
fill_sensitivenow returnsResult<()>and validates the two entry counts match exactly before touching anything — catching a longer sensitive-cache file (e.g. a stale leftover from a prior, longer run), not just a shorter one, and never partially fillingself.transactionsbefore reporting the mismatch. An earlier draft of this fix only guarded the shorter case with a per-index.get(), which a synchronous adversarial review (Codex) caught as one-sided and capable of partial mutation before erroring — fixed by moving to an upfront length check.Testing
ScriptSequencewith 2 transactions and aSensitiveScriptSequencewith only 1 entry — confirmed the original code path panics on this input, confirmed the fix errors cleanly instead.crates/script-sequence/src/sequence.rs: shorter cache errors (and doesn't partially mutate), longer cache errors, and a synced cache still fills correctly.cargo test -p forge-script-sequence: 5/5 passing.cargo check -p forge-script-sequence -p forge-script --tests: clean.cargo clippy -p forge-script-sequence --tests -- -D warnings: clean. (-p forge-scriptpulls in a pre-existing, unrelated clippy failure in theanvilcrate via dev-dependencies — confirmed viagit stashthat it reproduces identically on unmodifiedorigin/master, nothing to do with this diff.)cargo fmt --check: clean.closes nothing — filed independently, no corresponding issue was open (dupe-checked; the only related hit, #9095/#9096, is a distinct nonce/RPC-latency desync bug, not this indexing panic).