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

New AssemblyScript compiler introduced floats #73

Open
MaksymZavershynskyi opened this issue Sep 22, 2019 · 5 comments
Open

New AssemblyScript compiler introduced floats #73

MaksymZavershynskyi opened this issue Sep 22, 2019 · 5 comments
Assignees

Comments

@MaksymZavershynskyi
Copy link

When we compile AssemblyScript that does not use floats it gets compiled into WebAssembly that uses float operations. Float operations are not allowed for smart contracts, since they introduce non-determinism, see relevant: AssemblyScript#732

To reproduce:

  • Start local node (you would need to install rust)
git clone https://github.com/nearprotocol/nearcore/
cd nearcore
git checkout staging
./scripts/start_unittest.py --local
cd wasm-project-it8oemvbn
near create_account studio-it8oemvbn --masterAccount=test.near --homeDir=/Users/zaver/Projects/nearcore/testdir
near deploy --accountId=studio-it8oemvbn --homeDir=/Users/zaver/Projects/nearcore/testdir --wasmFile=./out/main.wasm
cd ../wasm-project-kr22owu3d
near create_account studio-kr22owu3d --masterAccount=test.near --homeDir=/Users/zaver/Projects/nearcore/testdir
near deploy --accountId=studio-kr22owu3d --homeDir=/Users/zaver/Projects/nearcore/testdir --wasmFile=./out/main.wasm

(Fix the path to nearcore)

  • Call the contract:
near call studio-it8oemvbn calculate "{}" --accountId=test.near --homeDir=/Users/zaver/Projects/nearcore/testdir

Observe the error message:

[studio-it8oemvbn]: Runtime error: wasm async call execution failed with error: PrepareError("Gas instrumentation failed.")
Error:  Error: Transaction 5bGQZ6KSiMWft5Wd3CKzaDitye3gBQiZakzuqcfMnE5c failed. Runtime error: wasm async call execution failed with error: PrepareError("Gas instrumentation failed.")
    at Account.signAndSendTransaction (/usr/local/lib/node_modules/near-shell/node_modules/nearlib/lib/account.js:89:23)
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
    at async Object.exports.scheduleFunctionCall (/usr/local/lib/node_modules/near-shell/index.js:110:34)
    at async exitOnError (/usr/local/lib/node_modules/near-shell/bin/near:8:5)

Expected: to get no error message.

To see that it is float-related comment out https://github.com/nearprotocol/nearcore/blob/2cb653181143cfe4a0c8b2eac5a9e7701e88d1ea/runtime/near-vm-runner/src/prepare.rs#L59 and try again, it will succeed this time.

@MaxGraey
Copy link

That's strange. I can't see any f64/f32 in generated code for second example:
https://webassembly.studio/?f=www28iehfj

@MaksymZavershynskyi
Copy link
Author

MaksymZavershynskyi commented Sep 22, 2019

I do not remember exactly which contract out of the two given generated floats.

@willemneal
Copy link

The version of the compiler is currently tied to near-shell, so the dependency"near-shell": "github:nearprotocol/near-shell" is the issue. Unlike the compiler near-shell is versioned and since it uses a lock file to determine which commit of the compiler to use it acts as a proxy for the version of the compiler. Not saying we shouldn't version the compiler, but just perhaps this is the reason for the breakage/instability.

@willemneal
Copy link

Also I can't download the zip file as dropbox says it's too large and I can't open the .ts file in the browser since dropbox thinks it a video file.

@MaksymZavershynskyi
Copy link
Author

@willemneal Did you figure out how to download the dropbox file?

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

3 participants