verichains / revela

Decompiler for Move smart contracts
https://revela.verichains.io
Other
43 stars 10 forks source link

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

Open alex4506 opened 4 months ago

alex4506 commented 4 months ago

🐛 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

alex4506 commented 4 months ago

Any update?