warp-contracts / warp

An implementation of the Arweave SmartWeave smart contracts protocol.
MIT License
159 stars 44 forks source link

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

Open noomly opened 8 months ago

noomly commented 8 months ago

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

https://github.com/warp-contracts/warp/blob/25b2abd35172cb14f4aff384eb3e07961c2a1eb8/src/core/modules/impl/wasm/rust-wasm-imports.ts#L710

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

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