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

Deserialization error on contract call after rust update #1035

Closed
alexvelicu opened this issue Jun 28, 2023 · 2 comments
Closed

Deserialization error on contract call after rust update #1035

alexvelicu opened this issue Jun 28, 2023 · 2 comments

Comments

@alexvelicu
Copy link

We have integrated a near contract in our development.

When we compile / build / test / deploy the contract with
cargo 1.66.1 (ad779e08b 2023-01-10)
rustup 1.25.1 (bb60b1e89 2022-07-12)
We can call the contract, execute view, no errors.

After updating to rustup 1.26.0 (5af9b9484 2023-04-05)
Contract call returns Querying [object Object] failed: wasm execution failed with error: CompilationError(PrepareError(Deserialization))
Also on call to set values we get a receipt with

"status": {
            "Failure": {
              "ActionError": {
                "index": 0,
                "kind": {
                  "FunctionCallError": {
                    "CompilationError": {
                      "PrepareError": "Deserialization"
                    }
                  }
                }
              }
            }
          }

This can be reproduced on
https://github.com/near-examples/hello-near-rust/tree/main/contract
Any suggestions?

@agostbiro
Copy link
Contributor

Hi @alexvelicu, thanks for reporting this!

The error is an unfortunate consequence of nearcore not yet supporting Rust 1.70. You can work around this limitation by using Rust 1.69. If you're using rustup, you can accomplish this automatically by placing a file called rust-toolchain.toml next to your Cargo.toml (or workspace root) with the following content:

[toolchain]
channel = "1.69"

I'll submit a PR in hello-near-rust to add this file.

agostbiro added a commit to agostbiro/hello-near-rust that referenced this issue Jun 28, 2023
The latest release `nearcore` currently doesn't support Rust 1.70.
This commit fixes that for users who use `rustup` by pinning the
Rust version to 1.69.

Motivated by near/near-sdk-rs#1035
@agostbiro
Copy link
Contributor

Closing this as fixed as PR was merged to hello-near-rust near-examples/hello-near-examples#6

evgenykuzyakov pushed a commit to NearSocial/social-db that referenced this issue Aug 3, 2023
Hi,

This PR adds an option to the `set` method to refund part of the deposit that covers unused storage to the caller (fixes #6).

### Invariants

I think there are three invariants to maintain with this feature:

1. No refunds for storage that is in use.
1. No double spending: same deposit cannot be withdrawn multiple times.
1. A caller cannot withdraw more than they deposited in the call.

I ensured the first two invariants by reusing the existing `storage_withdraw` implementation.

I ensured the third invariant by checking that we don't refund more than what was in the attached balance:

4e0581d#diff-bc8da1acc242fddbedebb84935fc8bb893ed6bb4044090dbed4b2e53fc817b02R153

### Integration tests

I added an integration test suite to convince myself that the implementation is correct. If you want to keep the integration tests, I'm happy to add CI for them in a follow up PR.

### Rust 1.69

I added a `rust-toolchain.toml` file to pin Rust 1.69 as `nearcore` doesn't support Rust 1.70 yet (more info: near/near-sdk-rs#1035)

### Reviewing

I implemented this feature to gain more experience with NEAR smart contract development. As a result, in spite of my best efforts, it's possible that I overlooked something important, so please review carefully.
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

2 participants