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: only early-return if an exact bytecode match is found #7165

Merged
merged 2 commits into from
Feb 19, 2024
Merged
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
22 changes: 12 additions & 10 deletions crates/evm/traces/src/identifier/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ impl<'a> LocalTraceIdentifier<'a> {
self.known_contracts
}

/// Iterates over artifacts with code length less than or equal to the given code and tries to
/// find a match.
///
/// We do not consider artifacts with code length greater than the given code length as it is
/// considered that after compilation code can only be extended by additional parameters
/// (immutables) and cannot be shortened.
/// Tries to the bytecode most similar to the given one.
pub fn identify_code(&self, code: &[u8]) -> Option<(&'a ArtifactId, &'a JsonAbi)> {
let len = code.len();

Expand All @@ -44,8 +39,8 @@ impl<'a> LocalTraceIdentifier<'a> {
let mut check = |id| {
let (abi, known_code) = self.known_contracts.get(id)?;
let score = bytecode_diff_score(known_code, code);
if score <= 0.1 {
trace!(%score, "found close-enough match");
if score == 0.0 {
trace!("found exact match");
return Some((id, abi));
}
if score < min_score {
Expand Down Expand Up @@ -80,8 +75,15 @@ impl<'a> LocalTraceIdentifier<'a> {
}
}

trace!(%min_score, "no close-enough match found");
min_score_id
trace!(%min_score, "no exact match found");

// Note: the diff score can be inaccurate for small contracts so we're using a relatively
// high threshold here to avoid filtering out too many contracts.
if min_score < 0.85 {
min_score_id
} else {
None
}
}

/// Returns the index of the artifact with the given code length, or the index of the first
Expand Down
Loading