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

Contract compiled with Rust 1.70.0 not working #2009

Closed
think-in-universe opened this issue Jun 5, 2023 · 5 comments · Fixed by #2013
Closed

Contract compiled with Rust 1.70.0 not working #2009

think-in-universe opened this issue Jun 5, 2023 · 5 comments · Fixed by #2013

Comments

@think-in-universe
Copy link
Member

think-in-universe commented Jun 5, 2023

Problem

After creating a new Rust contract with create-near-app with latest Rust version 1.70.0, and following the steps to deploy contract, developer failed to view function with near view <dev-account> get_greeting.

This issue is reported by developers in community who are learning how to build on NEAR today.

How to Reproduce

(1) Install the latest Rust version 1.70.0. For example,

stable-x86_64-unknown-linux-gnu (default)
rustc 1.70.0 (90c541806 2023-05-31)

(2) Create a new project with create-near-app command

npx create-near-app my-project --contract rust --frontend none --tests rust

(3) Deploy contract to testnet

cd ./my-project
npm i
npm run deploy

(4) View call function get_greeting

near view <dev-account> get_greeting

View call failed and you'll encounter the error as below.

$ near view dev-1685967486834-62115280035912 get_greeting
View call: dev-1685967486834-62115280035912.get_greeting()
An error occured
Error: Querying [object Object] failed: wasm execution failed with error: CompilationError(PrepareError(Deserialization)).
{
  "block_hash": "5cdGPvRvN8JGKs7AfEPjVJaoVZjhhS35H1WgxrvxmNXR",
  "block_height": 128323323,
  "error": "wasm execution failed with error: CompilationError(PrepareError(Deserialization))",
  "logs": []
}
    at JsonRpcProvider.query (/usr/local/share/nvm/versions/node/v19.9.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/providers/json-rpc-provider.js:123:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Account.viewFunction (/usr/local/share/nvm/versions/node/v19.9.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/account.js:366:24)
    at async exports.callViewFunction (/usr/local/share/nvm/versions/node/v19.9.0/lib/node_modules/near-cli/index.js:103:48)
    at async Object.handler (/usr/local/share/nvm/versions/node/v19.9.0/lib/node_modules/near-cli/utils/exit-on-error.js:52:9)
TypedError: Querying [object Object] failed: wasm execution failed with error: CompilationError(PrepareError(Deserialization)).
{
  "block_hash": "5cdGPvRvN8JGKs7AfEPjVJaoVZjhhS35H1WgxrvxmNXR",
  "block_height": 128323323,
  "error": "wasm execution failed with error: CompilationError(PrepareError(Deserialization))",
  "logs": []
}
    at JsonRpcProvider.query (/usr/local/share/nvm/versions/node/v19.9.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/providers/json-rpc-provider.js:123:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Account.viewFunction (/usr/local/share/nvm/versions/node/v19.9.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/account.js:366:24)
    at async exports.callViewFunction (/usr/local/share/nvm/versions/node/v19.9.0/lib/node_modules/near-cli/index.js:103:48)
    at async Object.handler (/usr/local/share/nvm/versions/node/v19.9.0/lib/node_modules/near-cli/utils/exit-on-error.js:52:9) {
  type: 'UntypedError',
  context: undefined
}

Notes

This is probably a compatibility issue of Rust SDK 4.0.0 with Rust 1.70.0.

@frol
Copy link
Collaborator

frol commented Jun 5, 2023

CompilationError(PrepareError

This usually indicates that the contract defined that it requires host functions that are not going to be provided or has illegal/unsupported operation. We will need to involve nearcore team to help to diagnose it.

P.S. Here are some relevant issues: near/nearcore#7223, near/nearcore#8502

@frol
Copy link
Collaborator

frol commented Jun 5, 2023

@jakmeier
Copy link

jakmeier commented Jun 5, 2023

Unfortunately, without a protocol upgrade, the best workaround is to use rustc <=1.69.

See near/nearcore#9143

@agostbiro
Copy link
Contributor

Hey, I've just ran into this.

I'm wondering if we should add a rust-toolchain.toml with the following content to the template to force using Rust 1.69:

[toolchain]
channel = "1.69"

Happy to provide a PR.

near-bulldozer bot pushed a commit to near/nearcore that referenced this issue Jun 19, 2023
With 1.70 toolchain, the contracts are by default compiled in a way
which requires updates to wasmer 2.4.1 as well.

I looked also into replacing usage of once_cell crate but sadly
std::sync::OnceLock doesn’t implement wait method.

Co-authored-by: Jakob Meier <mail@jakobmeier.ch>
Co-authored-by: Simonas Kazlauskas <git@kazlauskas.me>
Issue: near/create-near-app#2009
Issue: #9143
@frol
Copy link
Collaborator

frol commented Jun 20, 2023

@agostbiro let’s do what you suggested as a quick temporary fix

agostbiro added a commit to agostbiro/create-near-app that referenced this issue Jun 20, 2023
As contracts compiled with Rust 1.70 are not working currently this
commit ensures that users who use rustup aren't experiencing errors.

Resolves near#2009
agostbiro added a commit to agostbiro/cross-contract-hello-rust that referenced this issue Jun 21, 2023
As contracts compiled with Rust 1.70 are not working currently, this commit
ensures that users who use rustup aren't experiencing errors.

Related: near/create-near-app#2009
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

Successfully merging a pull request may close this issue.

4 participants