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

Doesn't support stack machine "flat" syntax #15

Open
qpIlIpp opened this issue Oct 5, 2018 · 7 comments
Open

Doesn't support stack machine "flat" syntax #15

qpIlIpp opened this issue Oct 5, 2018 · 7 comments

Comments

@qpIlIpp
Copy link

qpIlIpp commented Oct 5, 2018

Hi!
If u will get wast from EOS system (cleos -u https://mainnet.eoscalgary.io:443 get code eosio.token -c a.txt ) , it cannot be decompiled by your decompile, but wast is ok.

sorce code cpp is here : https://github.com/EOSIO/eosio.contracts/blob/master/eosio.token/include/eosio.token/eosio.token.hpp

wast is attached: a.txt

@wwwg
Copy link
Owner

wwwg commented Oct 8, 2018

Hey, it looks like that binary is in .wat format, which isn't supported by wasmdec. However, you can convert this binary into a .wasm with wat2wasm offered in the wabt repository, then decompile it with wasmdec. I'll leave this issue open and implement .wat parsing.

@wwwg wwwg changed the title [parse exception: expected list (at 191:4)] Doesn't support .wat input Oct 8, 2018
@qpIlIpp
Copy link
Author

qpIlIpp commented Oct 8, 2018

Cleos told me, that it was wast: "saving wast..", but anyway, thank you!

@wwwg
Copy link
Owner

wwwg commented Oct 9, 2018

Then there must be a mistake on Ceos' behalf, because a.txt appears to be a mix between s-expressions and the stack machine format, and .wast, generally speaking, is exclusively s-expressions.

You can see the two syntax's mix on line 178 of a.txt which defines func $75:

(func $75
    (param $0 i32)
    (param $1 i64)
    (param $2 i32)
    (local $3 i32)
    (local $4 i32)
    (local $5 i64)
    (local $6 i64)
    (local $7 i64)
    (local $8 i64)
    (local $9 i32)
    (local $10 i32)
    (local $11 i64)
    get_global $31
    i32.const 128
    i32.sub
    tee_local $3
    set_global $31
    get_local $0
    i64.load
    call $35
    i32.const 0
    set_local $4
    ;; truncated function body
)

In the example on the wasmdec README, you can clearly see the difference

(func $addTwo (param i32 i32) (result i32)
	(return
		(i32.add
                    ;; Notice how the get_local instructions are structured like a tree rather than stack values
                    (get_local 0)
                    (get_local 1)
               )
	)
)

@qpIlIpp
Copy link
Author

qpIlIpp commented Oct 9, 2018

oh, I see. Thank, I'll write to eosio.

@binji
Copy link

binji commented Oct 11, 2018

Sorry, the WebAssembly text format is a bit confusing. .wast is meant to be only for the WebAssembly spec test script format. This can include multiple modules, as well as mechanisms for linking modules together, invoking functions, and calling assertions.

The .wat format only has one module and has none of the scripting functionality.

Both formats allow S-expressions (what we call "folded") and the "flat" syntax. The folded format is syntactic sugar for the flat format. For example, (i32.add (i32.const 1) (i32.const 2)) and i32.const 1 i32.const 2 i32.add generate identical instruction sequences. Partially folded constructs are also supported, like i32.const 1 (i32.add (i32.const 2)).

Some tools like binaryen only parse the folded format, so many of the .wast files in the spec testsuite are written using the folded format (and because it is somewhat easier to read/write).

@wwwg
Copy link
Owner

wwwg commented Oct 16, 2018

Thank you for the clarification, I'll rename the issue accordingly.

@wwwg wwwg changed the title Doesn't support .wat input Doesn't support stack machine "flat" syntax Oct 16, 2018
@jafri
Copy link

jafri commented Oct 23, 2018

I have attached a WASM in txt format from EOS that shows the same issues.

File: chintailease.txt

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

No branches or pull requests

4 participants