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

Fix usage of Wasmer Module when recompiling Wasm (regression bug 1.3.x -> 1.4.0) #1907

Merged
merged 9 commits into from
Oct 7, 2023

Conversation

webmaster128
Copy link
Member

@webmaster128 webmaster128 commented Oct 5, 2023

The upgrade CosmWasm 1.3 -> 1.4.0 contains a big upgrade of Wasmer from 2.3 to version 4. This led to large refactorings in our usage of the Wasmer API. To a large degree this improved the integration. E.g. cached modules in memory are now much smaller because we don't need to cache a Store anymore. However, we made one mistake in some code paths when using Wasmer: When we recompile a module from the Wasm file to the node's architecture we use an engine with a singlepass compiler attached. But for running modules we use a different engine that does not have a compiler. This is nice as the engine running contracts is lightweight and reusable. Now the regression was introduced by creating a Wasmer Module instance with one engine but run it with a different engine. The type system and Wasmer API allows you to do that, but it seems to be an invalid usage of Wasmer due to how Modules, Artifacts and Engines work internally. The resulting error message we get is:

Wasmer runtime error: RuntimeError: out of bounds memory access

This PR fixes the issue by ensuring the compiling engine and the Module instance are not used to instantiate and execute the Module. Instead the Module is serialized to the file system cache and read from there.

We also increase our test coverage for the affected cases. Before we just checked the instance was created. Now we also test that the created instances can be executed.

packages/vm/src/cache.rs Outdated Show resolved Hide resolved
@webmaster128 webmaster128 force-pushed the fix-module-usage branch 2 times, most recently from f651771 to ed6f9d4 Compare October 5, 2023 14:31
@webmaster128 webmaster128 changed the title Fix module usage Fix usage of Wasmer Module when recompiling Wasm (regression bug 1.3.x -> 1.4.0) Oct 6, 2023
Copy link
Contributor

@maurolacy maurolacy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@maurolacy maurolacy marked this pull request as ready for review October 6, 2023 08:38
Copy link
Contributor

@maurolacy maurolacy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

packages/vm/src/cache.rs Show resolved Hide resolved
@webmaster128 webmaster128 merged commit 7309960 into release/1.4 Oct 7, 2023
3 checks passed
@webmaster128 webmaster128 deleted the fix-module-usage branch October 7, 2023 11:17
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 this pull request may close these issues.

3 participants