Jon-Becker / heimdall-rs

Heimdall is an advanced EVM smart contract toolkit specializing in bytecode analysis and extracting information from unverified contracts.
http://heimdall.rs
MIT License
1.2k stars 125 forks source link

bug: cfg graph starts from offset 0x01 instead of 0x00 #499

Open alessandromazza98 opened 2 months ago

alessandromazza98 commented 2 months ago

Component

Heimdall (Core)

Have you ensured that you are up to date?

What version of Heimdall are you on?

heimdall 0.8.4

Operating System

macOS (Apple Silicon)

Describe the bug

I'm generating the cfg of a very simple contract to try heimdall.

everything works fine but I don't understand why heimdall uses offset in the bytecode starting from 0x01 instead of 0x00.

This creates some confusion because, take the example I have in the image, the first block has a jumpi that should point to 0x20. But heimdall shows the jumpdest at offset 0x21 (because of the shifts of the offset). While at offset 0x20 heimdall shows a different opcode (JUMP in this example).

The contract:

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.27;
contract Faucet {
  // Give out ether to anyone who asks
  function withdraw(uint256 _withdrawAmount, address payable _to) public {
    // Limit withdrawal amount
    require(_withdrawAmount <= 1000000000000);
    // Send the amount to the address that requested it
    _to.transfer(_withdrawAmount);
  }
  fallback() external payable {}
}

I took the runtime bytecode through solc and gave it to heimdall cfg

The graph: image

tg discussion here: https://t.me/heimdallsupport/388