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

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

Open
alex4506 opened this issue May 1, 2024 · 1 comment

Comments

@alex4506
Copy link

alex4506 commented May 1, 2024

🐛 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant