Skip to content

Commit

Permalink
🔀 merge: 🔧 fix: use 32 byte hash for events to reduce collisions
Browse files Browse the repository at this point in the history
fix(decompile): use 32 byte hash for events to reduce collisions
  • Loading branch information
Jon-Becker authored Dec 9, 2022
2 parents e3bf939 + 667a107 commit 1018f61
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions common/src/ether/signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,18 @@ pub fn resolve_error_signature(signature: &String) -> Option<Vec<ResolvedError>>
pub fn resolve_event_signature(signature: &String) -> Option<Vec<ResolvedLog>> {

// get function possibilities from 4byte
let signatures = match get_json_from_url(format!("https://sig.eth.samczsun.com/api/v1/signatures?all=true&function=0x{}", &signature)) {
let signatures = match get_json_from_url(format!("https://sig.eth.samczsun.com/api/v1/signatures?all=true&event=0x{}", &signature)) {
Some(signatures) => signatures,
None => return None
};

// convert the serde value into a vec of possible functions
// AAAHAHHHHHH IM MATCHING
let results = match signatures.get("result") {
Some(result) => match result.get("function") {
Some(function) => match function.get(format!("0x{signature}")) {
Some(functions) => match functions.as_array() {
Some(functions) => functions.to_vec(),
Some(result) => match result.get("event") {
Some(event) => match event.get(format!("0x{signature}")) {
Some(events) => match events.as_array() {
Some(events) => events.to_vec(),
None => return None
},
None => return None
Expand Down
8 changes: 4 additions & 4 deletions heimdall/src/decompile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ pub fn decompile(args: DecompilerArgs) {
}

if !args.skip_resolving {

let resolved_functions = match resolved_selectors.get(&selector) {
Some(func) => func.clone(),
None => {
Expand Down Expand Up @@ -481,7 +481,7 @@ pub fn decompile(args: DecompilerArgs) {
resolved_counter = 0;
for (event_selector, (_, raw_event)) in analyzed_function.events.clone() {
decompilation_progress.set_message(format!("resolving event 0x{}", &event_selector.get(0..8).unwrap().to_string()));
let resolved_event_selectors = resolve_event_signature(&event_selector.get(0..8).unwrap().to_string());
let resolved_event_selectors = resolve_event_signature(&event_selector.get(0..64).unwrap().to_string());

// only continue if we have matches
match resolved_event_selectors {
Expand All @@ -507,7 +507,7 @@ pub fn decompile(args: DecompilerArgs) {
std::process::exit(1)
}
};

resolved_counter += 1;
analyzed_function.events.insert(event_selector, (Some(selected_match.clone()), raw_event));
},
Expand Down Expand Up @@ -545,4 +545,4 @@ pub fn decompile(args: DecompilerArgs) {

trace.display();
logger.debug(&format!("decompilation completed in {:?}.", now.elapsed()).to_string());
}
}

0 comments on commit 1018f61

Please sign in to comment.