Skip to content

[Bug] Decompiling code that includes comparisons between a variable and its old value resulted in incorrect logic #6

@alex4506

Description

@alex4506

🐛 Bug

Code block like this

    fun calculate(x: u256, y:u256, z:u256): u256 {
        let y_prev = y;
        if (z > 1000) {
            y = y + 1;
        } else {
            y = y - 1;
        };
        if (y > y_prev) {
            return x
        } else {
            return y
        }
    }

Decompile code

    fun calculate(arg0: u256, arg1: u256, arg2: u256) : u256 {
        if (arg2 > 1000) {
            arg1 = arg1 + 1;
        } else {
            arg1 = arg1 - 1;
        };
        if (arg1 > arg1) {
            return arg0
        };
        arg1
    }

To reproduce

  1. publish the code to testnet with included-artifacts=none
  2. download bytecode from testnet
  3. decompile source from bytecode

Expected Behavior

y should compare with its old value y_prev not itself

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions