Repository navigation
Conversation
…ping Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ara-stock
requested review from
0xrusowsky,
DaniPopes,
figtracer,
grandizzy,
mablr,
mattsse,
onbjerg and
stevencartavia
as code owners
October 20, 2026 12:31
mablr
reviewed
Oct 22, 2026
| } | ||
|
|
||
| // Replace all __$xxx$__ placeholders with 32 zero bytes | ||
| // Replace all __$xxx$__ placeholders with 20 zero bytes |
Member
There was a problem hiding this comment.
nit: the inline comment in strip_bytecode_placeholders (L353) still says "32 zero bytes"; could fix or drop it while here.
| pub fn replace_placeholders_and_decode(s: &str) -> Result<Vec<u8>, hex::FromHexError> { | ||
| let re = regex::Regex::new(r"_\$.{34}\$_").expect("invalid regex"); | ||
| let s = re.replace_all(s, "00".repeat(40)); | ||
| let re = regex::Regex::new(r"__\$[0-9a-fA-F]{34}\$__").expect("invalid regex"); |
Member
There was a problem hiding this comment.
nit: the regex is recompiled on every call; a static LazyLock<Regex> would avoid that.
| BytecodeObject::Unlinked("60__".into()) | ||
| ); | ||
| } | ||
| #[test] |
Member
There was a problem hiding this comment.
nit: missing blank line before #[test].
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.
Problem
replace_placeholders_and_decode(used byBytecodeObject::strip_bytecode_placeholders) uses the pattern_\$.{34}\$_. A solc library placeholder is 40 characters,__$<34 hex chars>$__, so the pattern matches only the inner 38 characters and leaves one_on each side. On top of that, the replacement is"00".repeat(40)(80 hex chars, 40 bytes) rather than the 20 bytes of an address. Because of the leftover_, hex decoding always fails, sostrip_bytecode_placeholdersreturnsNonefor every unlinked bytecode that contains a placeholder.Fix
__\$[0-9a-fA-F]{34}\$__, the same__$<hash>$__form thatutils::library_hash_placeholderproduces andlinksearches for."00".repeat(20), 40 hex chars), so the decoded bytecode keeps its length and the offsets of the code after it stay the same.Related: foundry-rs/foundry#12656 tried to fix only the replacement length and was closed without merge in 2025-11. With that change alone the leftover
_characters still break decoding, so this PR fixes both the pattern and the replacement.Test
Added
strip_bytecode_placeholders_replaces_library_placeholder. It builds6000+ a real placeholder forsrc/Lib.sol:Lib+6000, and checks thatreplace_placeholders_and_decodereturns 24 bytes with 20 zero bytes in place of the placeholder and thatstrip_bytecode_placeholdersreturnsSomewith the same bytes. Before this change it fails withInvalidHexCharacter { c: '_', index: 4 }.cargo test -p foundry-compilers-artifacts-solc --lib: 63 passed.cargo fmt --all -- --checkandcargo clippy -p foundry-compilers-artifacts-solc --all-targetsare clean.This PR was prepared with AI assistance (Claude Code); I reviewed the change and ran the tests.
🤖 Generated with Claude Code