Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(forge vb): --ignore-predeploy-immutables #8850

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

yash-atreya
Copy link
Member

@yash-atreya yash-atreya commented Sep 12, 2024

Motivation

Closes #8849

Solution

  • Get immutable references for local deployed_bytecode and onchain_runtime_code using the offsets provided under immutableReferences in the artifact.
  • Extract these references/slices from the bytecodes before comparing

@yash-atreya yash-atreya added C-forge Command: forge labels Sep 12, 2024
@yash-atreya yash-atreya marked this pull request as ready for review October 7, 2024 13:23
@yash-atreya yash-atreya changed the title feat(forge vb): --ignore-immutables feat(forge vb): --ignore-predeploy-immutables Oct 7, 2024
Comment on lines +160 to +175
for offset in offsets {
let start = offset.start as usize;
let end = (offset.start + offset.length) as usize;

total_len_extracted_expected += offset.length;

// Remove this sections of bytes from the bytecode
let start_section = bytecode.slice(0..start);
let end_section = bytecode.slice(end..bytecode.len());

// Combine the start and end sections
let mut start_section_vec = start_section.to_vec();

start_section_vec.extend_from_slice(&end_section);

bytecode = Bytes::from(start_section_vec);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should account for bytecode being shifted on every iteration, thus requiring next offsets to be shifted too

Comment on lines +140 to +151
pub fn get_immutable_refs(
artifact: &CompactContractBytecode,
) -> Option<BTreeMap<String, Vec<Offsets>>> {
if artifact.deployed_bytecode.as_ref().is_some_and(|b| !b.immutable_references.is_empty()) {
let immutable_refs =
artifact.deployed_bytecode.as_ref().unwrap().immutable_references.clone();

return Some(immutable_refs);
}

None
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we make this just return a Vec of (start, end) tuples so that we can just iterate over offsets in extract_immutable_refs

@yash-atreya yash-atreya self-assigned this Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(verify-bytecode): ignore immutable refs during runtime check
2 participants