Skip to content

fix(verify): do not panic when constructor args are longer than the bytecode - #16366

Open
mkzung wants to merge 3 commits into
foundry-rs:masterfrom
mkzung:fix/verify-bytecode-args-longer-than-code
Open

fix(verify): do not panic when constructor args are longer than the bytecode#16366
mkzung wants to merge 3 commits into
foundry-rs:masterfrom
mkzung:fix/verify-bytecode-args-longer-than-code

Conversation

@mkzung

@mkzung mkzung commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Motivation

forge verify-bytecode panics instead of reporting a mismatch when --constructor-args is longer than the code at the address.

is_partial_match strips the args off the end of both buffers without checking either is that long:

bytecode = &bytecode[..bytecode.len() - constructor_args.len()];
local_bytecode = &local_bytecode[..local_bytecode.len() - constructor_args.len()];

Both operands are usize, and the args come from the command line while the on-chain side is whatever the address holds, so the subtraction underflows:

thread '...' panicked at crates/verify/src/utils.rs:194:28:
attempt to subtract with overflow

mablr raised this on #16054.

Solution

checked_sub on both, returning false when either is too short. A pair like that is a mismatch, and the caller already treats false as one.

The test asserts None from match_bytecodes with four bytes of local code, two on chain and 32 bytes of args. It panics on master and passes with the change, and reverting only the checked_sub with the test kept brings the panic back. forge-verify goes from 56 tests to 57, all passing.

Not addressed here, because it is a behavioural call rather than a crash: the stripped suffix is still never compared with the args that were supplied, so two different sets of the same length read alike. That is the wider half of mablr's point. Happy to follow it up separately if you want the matcher to check the suffix.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

✅ Changelog found

The deterministic check will validate the changed entry.

@stevencartavia
stevencartavia force-pushed the fix/verify-bytecode-args-longer-than-code branch from 0128ba6 to 91004c5 Compare August 25, 2026 17:55
@stevencartavia
stevencartavia enabled auto-merge (squash) August 25, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants