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

Args value is mangled when host function is called #1409

Closed
MaksymZavershynskyi opened this issue Apr 27, 2020 · 1 comment · Fixed by #1412
Closed

Args value is mangled when host function is called #1409

MaksymZavershynskyi opened this issue Apr 27, 2020 · 1 comment · Fixed by #1412
Labels
bug Something isn't working

Comments

@MaksymZavershynskyi
Copy link

MaksymZavershynskyi commented Apr 27, 2020

When host function is called by Wasm program some arguments receive a different value than the one passed by the Wasm program.

This bug reproduces with the following Wasmer Rust crates:

wasmer-runtime = { version = "0.16.2", features = ["default-backend-singlepass"], default-features = false }
wasmer-runtime-core = { version = "0.16.2" }

and it does not reproduce with the following crates:

wasmer-runtime = { version = "0.13.1", features = ["default-backend-singlepass"], default-features = false }
wasmer-runtime-core = { version = "0.13.1" }

Steps to reproduce

Version 0.16.2

In Terminal 1:
a) This needs to be run once:

git clone https://github.com/nearprotocol/nearcore/
cd nearcore
git checkout master_storage_write_log
cargo build --package neard --bin near

b) This can be run multiple times

rm -rf /tmp/testdir
./target/debug/near --home=/tmp/testdir init --chain-id= --test-seed=alice.near --account-id=test.near --fast
./target/debug/near --home=/tmp/testdir run

In Terminal 2:

git clone https://github.com/nearprotocol/near-evm/
cd near-evm
git checkout storage_write_log
./build.sh
cargo test --package near-evm --test cryptozombies_rpc test_all_in_one

Observe the console output in Terminal 1:

LOG storage_write 33 67119368 8 1047344 18446744073709551614
CALLED storage_write 33 67119368 8 18446744073709551614 18446744073709551614

The fist line is printed by the Wasm program using log_utf8 host function before calling storage_write host function, see: https://github.com/near/near-sdk-rs/blob/storage_write_log/near-sdk/src/environment/env.rs#L641
The second line is printed by the storage_write host function right after it was called, see: https://github.com/nearprotocol/nearcore/blob/master_storage_write_log/runtime/near-vm-logic/src/logic.rs#L1879

The arguments do not match.

Version 0.13.1

Now, in Terminal 1, instead of git checkout master_storage_write_log do git checkout beta_storage_write_log
and run the rest of the commands.

Observe:

LOG storage_write 33 67119368 8 1047344 18446744073709551614
CALLED storage_write 33 67119368 8 1047344 18446744073709551614

What changed? -- We are now using Wasmer 0.13.1 instead of 0.16.2

Expected behavior

Host receives exactly the same arguments that were passed by the guest program.

Actual behavior

Host receives different arguments than those passed by the guest program.

Versions

rustup 1.21.1 (7832b2ebe 2019-12-20)
cargo 1.44.0-nightly (7019b3ed3 2020-03-17)
rustc 1.44.0-nightly (f509b26a7 2020-03-18)
@MaksymZavershynskyi MaksymZavershynskyi added the bug Something isn't working label Apr 27, 2020
@MaksymZavershynskyi
Copy link
Author

MaksymZavershynskyi commented Apr 27, 2020

0.15 seems to also have the bug.. and so does 0.14.

nearprotocol-bulldozer bot pushed a commit to near/nearcore that referenced this issue Apr 28, 2020
Due to wasmerio/wasmer#1409 we need to rollback Wasmer to older version. I am replacing some of Wasmer generated error with Unknown to avoid undoing too much code from this PR: #2505

After the following PR lands wasmerio/wasmer#1401 we would need to revisit error handling from Wasmer anyway. CC @fckt  

### Testing

Ran near-evm test. CI passes.
losfair added a commit that referenced this issue Apr 29, 2020
@bors bors bot closed this as completed in 0cba64b Apr 29, 2020
@bors bors bot closed this as completed in #1412 Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant