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

[BUG] In Rust WASM imports, the __wbg_height function expects a number but receives a string, causing a crash #515

Open
noomly opened this issue Mar 12, 2024 · 0 comments

Comments

@noomly
Copy link
Contributor

noomly commented Mar 12, 2024

The function __wbg_height in the Rust WASM imports expects that the value returned by rawImports.Block.height() is a number.

When using ArLocal, the value is effectively a number, it is however not the case when using the mainnet, which in this case returns the height in a string. This causes the assertion to fail and crash the Rust contract that would try to get the current height of the tx.

To Reproduce

  • Deploy a Rust contract to mainnet that makes use of Block::height()
  • Publish a transaction that triggers the contract to call Block::height()
  • Notice how Warp now crashes every time we try to evaluate the contract

Here is the log of the crash. The first line is from a debug log I added right before the call to _assertNum:

wasmLogger.error(`ret type: \`${typeof ret}\`; ret value: \`${JSON.stringify(ret)}\``);
2024-03-12T14:49:55.147Z ERROR [WASM:Rust] ret type: `string`; ret value: `"1381371"` []
wasm-bindgen: imported JS function that was not marked as `catch` threw an error: expected a number argument

Stack:
/home/noom/dev/pianity/transaction-sender/node_modules/warp-contracts/lib/cjs/core/modules/impl/wasm/rust-wasm-imports.js:141
            throw new Error('expected a number argument');
                  ^

Error: expected a number argument
    at _assertNum (/home/noom/dev/pianity/transaction-sender/node_modules/warp-contracts/lib/cjs/core/modules/impl/wasm/rust-wasm-imports.js:141:19)
    at <anonymous> (/home/noom/dev/pianity/transaction-sender/node_modules/warp-contracts/lib/cjs/core/modules/impl/wasm/rust-wasm-imports.js:605:17)
    at logError (/home/noom/dev/pianity/transaction-sender/node_modules/warp-contracts/lib/cjs/core/modules/impl/wasm/rust-wasm-imports.js:320:22)
    at __wbg_height (/home/noom/dev/pianity/transaction-sender/node_modules/warp-contracts/lib/cjs/core/modules/impl/wasm/rust-wasm-imports.js:602:20)
    at wasm://wasm/00132f36:wasm-function[65]:0x6335
    at wasm://wasm/00132f36:wasm-function[62]:0x2b1a
    at wasm://wasm/00132f36:wasm-function[73]:0xf7dd
    at wasm://wasm/00132f36:wasm-function[62]:0x2dc6
    at wasm://wasm/00132f36:wasm-function[76]:0x1385f
    at wasm://wasm/00132f36:wasm-function[143]:0x2c490
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^
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

1 participant