Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-Becker committed Dec 23, 2024
1 parent 4767941 commit b2bbfdf
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 74 deletions.
6 changes: 3 additions & 3 deletions crates/cfg/src/core/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn build_cfg(

let assembly = format!(
"{} {} {}",
encode_hex_reduced(U256::from(operation.last_instruction.instruction)),
encode_hex_reduced(U256::from(operation.last_instruction.pc)),
opcode_name,
if opcode_name.contains("PUSH") {
encode_hex_reduced(
Expand Down Expand Up @@ -61,8 +61,8 @@ pub fn build_cfg(
.first()
.ok_or_eyre("failed to get first operation")?
.last_instruction
.opcode ==
JUMPDEST,
.opcode
== JUMPDEST,
)?;
}

Expand Down
12 changes: 6 additions & 6 deletions crates/decompile/src/utils/heuristics/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ pub fn argument_heuristic<'a>(
// calculate the argument index, with the 4byte signature padding removed
// for example, CALLDATALOAD(4) -> (4-4)/32 = 0
// CALLDATALOAD(36) -> (36-4)/32 = 1
let arg_index = (state.last_instruction.inputs[0].saturating_sub(U256::from(4)) /
U256::from(32))
let arg_index = (state.last_instruction.inputs[0].saturating_sub(U256::from(4))
/ U256::from(32))
.try_into()
.unwrap_or(usize::MAX);

Expand Down Expand Up @@ -77,7 +77,7 @@ pub fn argument_heuristic<'a>(
{
debug!(
"instruction {} ({}) indicates argument {} is masked to {} bytes",
state.last_instruction.instruction,
state.last_instruction.pc,
opcode_name(state.last_instruction.opcode),
arg_index,
mask_size_bytes
Expand Down Expand Up @@ -227,7 +227,7 @@ pub fn argument_heuristic<'a>(
{
debug!(
"instruction {} ({}) indicates argument {} may be a numeric type",
state.last_instruction.instruction,
state.last_instruction.pc,
opcode_name(state.last_instruction.opcode),
arg_index
);
Expand All @@ -251,7 +251,7 @@ pub fn argument_heuristic<'a>(
{
debug!(
"instruction {} ({}) indicates argument {} may be a bytes type",
state.last_instruction.instruction,
state.last_instruction.pc,
opcode_name(state.last_instruction.opcode),
arg_index
);
Expand All @@ -278,7 +278,7 @@ pub fn argument_heuristic<'a>(
{
debug!(
"instruction {} ({}) indicates argument {} may be a boolean",
state.last_instruction.instruction,
state.last_instruction.pc,
opcode_name(state.last_instruction.opcode),
arg_index
);
Expand Down
4 changes: 2 additions & 2 deletions crates/decompile/src/utils/heuristics/extcall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn extcall_heuristic<'a>(
if gas_solidified.contains("0x08fc") {
trace!(
"instruction {} ({}) with 2300 gas indicates a value transfer",
instruction.instruction,
instruction.pc,
opcode_name(instruction.opcode)
);
function.logic.push(format!(
Expand All @@ -51,7 +51,7 @@ pub fn extcall_heuristic<'a>(
if extcalldata.is_empty() {
trace!(
"instruction {} ({}) with no calldata indicates a value transfer",
instruction.instruction,
instruction.pc,
opcode_name(instruction.opcode)
);
function.logic.push(format!(
Expand Down
12 changes: 6 additions & 6 deletions crates/decompile/src/utils/heuristics/modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn modifier_heuristic<'a>(
if function.pure && !opcode_info.is_pure() {
debug!(
"instruction {} ({}) indicates a non-pure function",
state.last_instruction.instruction,
state.last_instruction.pc,
opcode_info.name()
);
function.pure = false;
Expand All @@ -32,21 +32,21 @@ pub fn modifier_heuristic<'a>(
if function.view && !opcode_info.is_view() {
debug!(
"instruction {} ({}) indicates a non-view function",
state.last_instruction.instruction,
state.last_instruction.pc,
opcode_info.name()
);
function.view = false;
}

// if the instruction is a JUMPI with non-zero CALLVALUE requirement, the function is
// non-payable exactly: ISZERO(CALLVALUE())
if function.payable &&
state.last_instruction.opcode == JUMPI &&
state.last_instruction.input_operations[1] == w_iszero!(w_callvalue!())
if function.payable
&& state.last_instruction.opcode == JUMPI
&& state.last_instruction.input_operations[1] == w_iszero!(w_callvalue!())
{
debug!(
"conditional at instruction {} indicates a non-payable function",
state.last_instruction.instruction
state.last_instruction.pc
);
function.payable = false;
}
Expand Down
Loading

0 comments on commit b2bbfdf

Please sign in to comment.