Skip to content

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

@noomly

Description

@noomly

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 */);
            ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions