Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-Becker committed Dec 7, 2024
1 parent 26b3fe6 commit bf84317
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions crates/decompile/src/core/postprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ impl PostprocessOrchestrator {
// Note: this can't be done with a postprocessor because it needs all lines
if !function.payable && (function.pure || function.view) && function.arguments.is_empty() {
// check for RLP encoding. very naive check, but it works for now
if function.logic.iter().any(|line| line.contains("0x0100 *")) &&
function.logic.iter().any(|line| line.contains("0x01) &"))
if function.logic.iter().any(|line| line.contains("0x0100 *"))
&& function.logic.iter().any(|line| line.contains("0x01) &"))
{
// find any storage accesses
let joined = function.logic.join(" ");
Expand Down
23 changes: 20 additions & 3 deletions crates/decompile/src/utils/heuristics/extcall.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use std::fmt::format;

use alloy::primitives::U256;
use futures::future::BoxFuture;
use heimdall_common::utils::hex::ToLowerHex;
use heimdall_common::utils::{hex::ToLowerHex, strings::encode_hex_reduced};
use heimdall_vm::{
core::{opcodes::opcode_name, vm::State},
w_gas, w_push0,
Expand Down Expand Up @@ -162,17 +165,31 @@ pub fn extcall_heuristic<'a>(
) {
function.logic.push(precompile_logic);
} else if let Some(decoded) = decoded {
let start_slot = instruction.inputs[2] + U256::from(4);

function.logic.push(format!(
"(bool success, bytes memory ret0) = address({}).{}{}({}); // {}",
address,
modifier,
decoded.decoded.name,
decoded.decoded.inputs.join(", "),
decoded
.decoded
.inputs
.iter()
.enumerate()
.map(|(i, _)| {
format!(
"memory[{}]",
encode_hex_reduced(start_slot + U256::from(i * 32))
)
})
.collect::<Vec<String>>()
.join(", "),
opcode_name(instruction.opcode).to_lowercase(),
));
} else {
function.logic.push(format!(
"(bool success, bytes memory ret0) = address({}).Unresolved_{}{}(msg.data[{}:{}]); // {}",
"(bool success, bytes memory ret0) = address({}).Unresolved_{}{}(memory[{}:{}]); // {}",
address,
extcalldata.get(2..10).unwrap_or(""),
modifier,
Expand Down

0 comments on commit bf84317

Please sign in to comment.