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

fix(invariant): lookup fuzz interface abi by name or identifier #9744

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/common/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ impl ContractsByArtifact {
Ok(contracts.first().cloned())
}

/// Finds abi for contract which has the same contract name or identifier as `id`.
pub fn find_abi_by_name_or_identifier(&self, id: &str) -> Option<JsonAbi> {
self.iter()
.find(|(artifact, _)| {
artifact.name.split(".").next().unwrap() == id || artifact.identifier() == id
})
.map(|(_, contract)| contract.abi.clone())
}

/// Flattens the contracts into functions, events and errors.
pub fn flatten(&self) -> (BTreeMap<Selector, Function>, BTreeMap<B256, Event>, JsonAbi) {
let mut funcs = BTreeMap::new();
Expand Down
9 changes: 3 additions & 6 deletions crates/evm/evm/src/executors/invariant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,21 +767,18 @@ impl<'a> InvariantExecutor<'a> {
// Identifiers are specified as an array, so we loop through them.
for identifier in artifacts {
// Try to find the contract by name or identifier in the project's contracts.
if let Some((_, contract)) =
self.project_contracts.find_by_name_or_identifier(identifier)?
if let Some(abi) = self.project_contracts.find_abi_by_name_or_identifier(identifier)
{
combined
// Check if there's an entry for the given key in the 'combined' map.
.entry(*addr)
// If the entry exists, extends its ABI with the function list.
.and_modify(|entry| {
// Extend the ABI's function list with the new functions.
entry.abi.functions.extend(contract.abi.functions.clone());
entry.abi.functions.extend(abi.functions.clone());
})
// Otherwise insert it into the map.
.or_insert_with(|| {
TargetedContract::new(identifier.to_string(), contract.abi.clone())
});
.or_insert_with(|| TargetedContract::new(identifier.to_string(), abi));
}
}
}
Expand Down
Loading