verichains / revela

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

Econia decompilation substitutes erroneous goto statement for break #4

Open alnoki opened 7 months ago

alnoki commented 7 months ago

@wrwg

Steps to reproduce

econia=0xc0deb00c405f84c85dc13442e305df75d1288100cdd82675695f6148c7ece51c
url=https://fullnode.mainnet.aptoslabs.com
aptos move download --account $econia --bytecode --package Econia --url $url
aptos move decompile --package-path Econia/bytecode_modules

Then see avl_queue.mv.move::traverse

Commentary

This produces the following

    fun traverse<T0>(arg0: &AVLqueue<T0>, arg1: u64, arg2: bool) : (u64, u64, u64) {
        let v0 = &arg0.tree_nodes;
        let (v1, v2) = if (arg2 == true) {
            (56, 42)
        } else {
            (42, 56)
        };
        let v3 = 0x1::table_with_length::borrow<u64, TreeNode>(v0, arg1).bits;
        let v4 = v3;
        let v5 = (v3 >> v1 & (16383 as u128)) as u64;
        let v6 = v5;
        if (v5 == (0 as u64)) {
            v6 = arg1;
            loop {
                let v7 = (v4 >> 70 & (16383 as u128)) as u64;
                if (v7 == (0 as u64)) {
                    break
                };
                let v8 = 0x1::table_with_length::borrow<u64, TreeNode>(v0, v7);
                let v9 = v8.bits;
                v4 = v9;
                if (((v9 >> v2 & (16383 as u128)) as u64) == v6) {
                    /* goto 13 */
                } else {
                    v6 = v7;
                };
            };
            return (0 as u64, 0 as u64, 0 as u64)
        };
        let v10;
        loop {
            let v11 = 0x1::table_with_length::borrow<u64, TreeNode>(v0, v6);
            v10 = v11;
            let v12 = (v11.bits >> v2 & (16383 as u128)) as u64;
            v6 = v12;
            if (v12 == (0 as u64)) {
                break
            };
        };
        /* label 13 */
        let v13 = v10.bits;
        ((v13 >> 94 & (4294967295 as u128)) as u64, (v13 >> 28 & (16383 as u128)) as u64, (v13 >> 14 & (16383 as u128)) as u64)
    }

Compare with https://github.com/econia-labs/econia/blob/3c0fb383ec4109e02277138e41ee420b03127bc2/src/move/econia/sources/avl_queue.move#L4564

There is a decompiled goto comment where there should be a break statement