Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Decompilation for the functions that call other contract functions #412

Open
2 tasks
EthanShang8989 opened this issue May 24, 2024 · 1 comment
Open
2 tasks
Assignees
Labels
A-core Area: core C-decompile Command: decompile D-hard Difficulty: hard P-normal Priority: normal T-bug Type: bug

Comments

@EthanShang8989
Copy link

Component

Heimdall (Core)

Have you ensured that you are up to date?

  • Bifrost
  • Heimdall

What version of Heimdall are you on?

v0.8.1

Operating System

Linux

Describe the bug

contract address:https://arbiscan.io/address/0xa8a36cdf8891267c246fd47fe01cf364f02ce57e#code

Actual Decompiled Output

   /// @custom:selector    0x3e86e13b
    /// @custom:signature   startSwap(address arg0, uint256 arg1, address arg2) public payable
    /// @param              arg0 ["address", "uint160", "bytes20", "int160"]
    /// @param              arg1 ["uint256", "bytes32", "int256"]
    /// @param              arg2 ["address", "uint160", "bytes20", "int160"]
    function startSwap(address arg0, uint256 arg1, address arg2) public payable {
        require(arg0 == (address(arg0)));
        if (arg2 == (address(arg2))) {
        }
    }

Expected Decompiled Output

The following content is gpt4-0 according to https://ethervm.io/decompile

function startSwap(address arg0, uint256 arg1, address arg2) public payable {

 require(arg0 != address(0), "Invalid token address");
 require(arg2 != address(0), "Invalid recipient address");

 address sender = msg.sender;

 IERC20 token = IERC20(arg0);

 require(token.transferFrom(sender, address(this), arg1), "Transfer from sender failed");

 require(token.transfer(arg2, arg1), "Transfer to recipient failed");
}

Related Assembly Code

if (var0 == 0x3e86e13b) {
            // Dispatch table entry for startSwap(address,uint256,address)
            var var1 = 0x007a;
            var var2 = 0x0075;
            var var3 = msg.data.length;
            var var4 = 0x04;
            var2, var3, var4 = func_066C(var3, var4);
            var1 =func_0075(var2, var3, var4);
        
        label_007A:
            var temp0 = memory[0x40:0x60];
            memory[temp0:temp0 + 0x20] = !!var1;
            var1 = temp0 + 0x20;
        
        label_0086:
            var temp1 = memory[0x40:0x60];
            return memory[temp1:temp1 + var1 - temp1];

Definitions of func_066C

  ```

function func_066C(var arg0, var arg1) returns (var r0, var arg0, var arg1) {
var var0 = 0x00;
var var1 = var0;
var var2 = 0x00;

    if (arg0 - arg1 i< 0x60) { revert(memory[0x00:0x00]); }

    var var3 = 0x068a;
    var var4 = arg1;
    var3 = [func_0655](https://ethervm.io/decompile#func_func_0655)(var4);
    var0 = var3;
    var temp0 = arg1;
    var1 = msg.data[temp0 + 0x20:temp0 + 0x20 + 0x20];
    var3 = 0x069f;
    var4 = temp0 + 0x40;
    var3 = [func_0655](https://ethervm.io/decompile#func_func_0655)(var4);
    arg1 = var3;
    arg0 = var1;
    r0 = var0;
    return r0, arg0, arg1;
}
func_0075 is quite lengthy to include here directly.
@EthanShang8989 EthanShang8989 added the T-bug Type: bug label May 24, 2024
@Jon-Becker Jon-Becker added A-core Area: core C-decompile Command: decompile D-hard Difficulty: hard P-normal Priority: normal labels May 25, 2024
@Jon-Becker
Copy link
Owner

thank you for opening! i'll try to fix this soon for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: core C-decompile Command: decompile D-hard Difficulty: hard P-normal Priority: normal T-bug Type: bug
Projects
None yet
Development

No branches or pull requests

2 participants