-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
yash-atreya
wants to merge
10
commits into
master
Choose a base branch
from
yash/vb-ignore-immutables
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
56c1544
feat(`forge vb`): --ignore-immutables
yash-atreya 72c0cc9
change return type of get_runtime_codes to Bytes
yash-atreya e154318
ignore creation check when --ignore-immutables
yash-atreya b9fd799
test
yash-atreya 9680501
Merge branch 'master' into yash/vb-ignore-immutables
yash-atreya 789e621
Merge branch 'master' into yash/vb-ignore-immutables
yash-atreya 986becc
fmt
yash-atreya eb6513f
resolve conflicts
yash-atreya 651c74e
make it predeploy specific
yash-atreya 3fe3c60
nit
yash-atreya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,17 +10,18 @@ use foundry_block_explorers::{ | |
errors::EtherscanError, | ||
}; | ||
use foundry_common::{abi::encode_args, compile::ProjectCompiler, provider::RetryProvider}; | ||
use foundry_compilers::artifacts::{BytecodeHash, CompactContractBytecode, EvmVersion}; | ||
use foundry_compilers::artifacts::{BytecodeHash, CompactContractBytecode, EvmVersion, Offsets}; | ||
use foundry_config::Config; | ||
use foundry_evm::{constants::DEFAULT_CREATE2_DEPLOYER, executors::TracingExecutor, opts::EvmOpts}; | ||
use reqwest::Url; | ||
use revm_primitives::{ | ||
db::Database, | ||
env::{EnvWithHandlerCfg, HandlerCfg}, | ||
Bytecode, Env, SpecId, | ||
Env, SpecId, | ||
}; | ||
use semver::Version; | ||
use serde::{Deserialize, Serialize}; | ||
use std::collections::BTreeMap; | ||
use yansi::Paint; | ||
|
||
/// Enum to represent the type of bytecode being verified | ||
|
@@ -136,6 +137,56 @@ pub fn build_using_cache( | |
eyre::bail!("couldn't find cached artifact for contract {}", args.contract.name) | ||
} | ||
|
||
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 | ||
} | ||
|
||
pub fn extract_immutables_refs( | ||
immutable_refs: BTreeMap<String, Vec<Offsets>>, | ||
mut bytecode: Bytes, | ||
) -> Bytes { | ||
let mut total_len_extracted_expected = 0; | ||
let init_length = bytecode.len(); | ||
for (_key, offsets) in immutable_refs { | ||
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); | ||
Comment on lines
+160
to
+175
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
} | ||
let end_length = bytecode.len(); | ||
|
||
tracing::info!( | ||
"Total length extracted (Expected): {}, Initial length: {}, Final length: {}", | ||
total_len_extracted_expected, | ||
init_length, | ||
end_length | ||
); | ||
|
||
bytecode | ||
} | ||
|
||
pub fn print_result( | ||
args: &VerifyBytecodeArgs, | ||
res: Option<VerificationType>, | ||
|
@@ -390,7 +441,7 @@ pub async fn get_runtime_codes( | |
address: Address, | ||
fork_address: Address, | ||
block: Option<u64>, | ||
) -> Result<(Bytecode, Bytes)> { | ||
) -> Result<(Bytes, Bytes)> { | ||
let fork_runtime_code = executor | ||
.backend_mut() | ||
.basic(fork_address)? | ||
|
@@ -414,7 +465,7 @@ pub async fn get_runtime_codes( | |
provider.get_code_at(address).await? | ||
}; | ||
|
||
Ok((fork_runtime_code, onchain_runtime_code)) | ||
Ok((fork_runtime_code.original_bytes(), onchain_runtime_code)) | ||
} | ||
|
||
/// Returns `true` if the URL only consists of host. | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
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 inextract_immutable_refs