Skip to content

Commit 7bef9ca

Browse files
authored
Fix: Check empty input bytecode in find_by_deployed_code_exact (#8257)
* fix: find by deployed code extract * chore: add unit test * chore: minor refactor
1 parent 374a645 commit 7bef9ca

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

crates/common/src/contracts.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ impl ContractsByArtifact {
147147
/// Finds a contract which deployed bytecode exactly matches the given code. Accounts for link
148148
/// references and immutables.
149149
pub fn find_by_deployed_code_exact(&self, code: &[u8]) -> Option<ArtifactWithContractRef<'_>> {
150+
// Immediately return None if the code is empty.
151+
if code.is_empty() {
152+
return None;
153+
}
154+
150155
self.iter().find(|(_, contract)| {
151156
let Some(deployed_bytecode) = &contract.deployed_bytecode else {
152157
return false;
@@ -403,4 +408,11 @@ mod tests {
403408
let a_99 = &b"a".repeat(99)[..];
404409
assert!(bytecode_diff_score(a_100, a_99) <= 0.01);
405410
}
411+
412+
#[test]
413+
fn find_by_deployed_code_exact_with_empty_deployed() {
414+
let contracts = ContractsByArtifact::new(vec![]);
415+
416+
assert!(contracts.find_by_deployed_code_exact(&[]).is_none());
417+
}
406418
}

0 commit comments

Comments
 (0)