near / nearcore

Reference client for NEAR Protocol
https://near.org
GNU General Public License v3.0
2.32k stars 623 forks source link

MacOS WasmVM is "broken": Link Error: "function types incompatible: expected func of type `(i64) -> ()`, found func of type `(i32) -> ()` #12062

Closed frol closed 1 month ago

frol commented 1 month ago

Describe the bug

nearcore 2.1.1+ built for macOS cannot deploy/execute any contract:

Error: Action #1: ExecutionError("Link Error: \"function types incompatible: expected func of type `(i64) -> ()`, found func of type `(i32) -> ()`\"")

https://github.com/near/near-workspaces-rs/actions/runs/10741891187/job/29793334139

This issue blocks all the tooling upgrades (near-sandbox-js, near-sandbox-rs, near-workspaces-*, ...).

It was reported before: https://github.com/near/nearcore/pull/11782#issuecomment-2230175103

To Reproduce

Pull this commit: https://github.com/near/near-workspaces-rs/pull/375/commits/9186ff1b88d4c8f46f30f91dfbbe1ff83579e065, and run tests (cargo test)

Expected behavior

Tests should pass.

Version (please complete the following information):

akorchyn commented 1 month ago

The same issue happens on the 2.2.0 release: https://github.com/near/near-workspaces-rs/actions/runs/10813176493/job/29996604197?pr=376

akorchyn commented 1 month ago

I have made some initial investigation and tried to determine the failure point. Using some Github actions and binary search I have located the next commit: https://github.com/near/nearcore/commit/872ac5c6a792e269ae37aba04e409f078de94a1e

I have adjusted to compile the nearcore sandbox (as some versions are not available on s3) and run tests:

This commit fails on the CI https://github.com/near/near-workspaces-rs/actions/runs/10835306324/job/30066537415 - fails The commit before passes on the CI https://github.com/near/near-workspaces-rs/actions/runs/10835654098/job/30067647491

akorchyn commented 1 month ago

The issue is reproducible on any OS using: cargo t -p near-vm-runner --features wasmtime_vm,near_vm

akorchyn commented 1 month ago

Weird, but it's only reproducible if you remove engine from WasmtimeVM and recreate it each time. Otherwise, test passes :( As I did here for example: https://github.com/near/nearcore/compare/master...akorchyn:nearcore:test-fix

akorchyn commented 1 month ago

If the engine is new, it won't work. Potentially the issue is within: precompile and then prepare and run on another engine.

To reproduce the issue just use a new engine before the linker.instantiate() It's a bit weird as the documentation says that if you have the same compatibility hash it should work.

Though, it doesn't

Returns a [std::hash::Hash] that can be used to check precompiled WebAssembly compatibility.

The outputs of [Engine::precompile_module] and [Engine::precompile_component] are compatible with a different [Engine] instance only if the two engines use compatible [Config]s. If this Hash matches between two [Engine]s then binaries from one are guaranteed to deserialize in the other.