stacks-network / clarity-wasm

`clar2wasm` is a compiler for generating WebAssembly from Clarity.
GNU General Public License v3.0
14 stars 16 forks source link

unwrap-panic error on wasm testnet #545

Closed csgui closed 3 weeks ago

csgui commented 4 weeks ago

The following code caused an error in the testnet instance.

(define-map names-map { name: (string-ascii 12) } { id: int })
(map-set names-map { name: "blockstack" } { id: 1337 })
(unwrap-panic (map-get? names-map { name: "blockstack" }))
(unwrap-panic (map-get? names-map { name: "non-existant" }))

Stack-trace:

Interpreter(Wasm(Runtime(error while executing at wasm backtrace:
    0: 0x35ea - <unknown>!stdlib.runtime-error
    1: 0x1b91 - <unknown>!<wasm function 67>

Caused by:
    wasm trap: wasm `unreachable` instruction executed

Stack backtrace:
   0: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from
             at ./usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/anyhow-1.0.91/src/backtrace.rs:27:14
   1: <T as core::convert::Into<U>>::into
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/convert/mod.rs:759:9
   2: wasmtime::trap::from_runtime_box
             at ./usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-15.0.1/src/trap.rs:117:39
   3: wasmtime::func::invoke_wasm_and_catch_traps::{{closure}}
             at ./usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-15.0.1/src/func.rs:1380:28
   4: core::result::Result<T,E>::map_err
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/result.rs:854:27
   5: wasmtime::func::invoke_wasm_and_catch_traps
             at ./usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-15.0.1/src/func.rs:1380:16
   6: wasmtime::func::Func::call_unchecked_raw
             at ./usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-15.0.1/src/func.rs:913:9
   7: wasmtime::func::Func::call_unchecked
             at ./usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-15.0.1/src/func.rs:899:9
   8: wasmtime::func::Func::call_impl
             at ./usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-15.0.1/src/func.rs:1068:13
   9: wasmtime::func::Func::call
             at ./usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-15.0.1/src/func.rs:852:9
  10: clarity::vm::clarity_wasm::initialize_contract
             at ./build/clarity/./src/vm/clarity_wasm.rs:440:5
  11: clarity::vm::contracts::Contract::initialize_from_ast::{{closure}}
             at ./build/clarity/./src/vm/contracts.rs:56:17
  12: clarity::vm::contexts::GlobalContext::execute
             at ./build/clarity/./src/vm/contexts.rs:1723:22
  13: clarity::vm::contracts::Contract::initialize_from_ast
             at ./build/clarity/./src/vm/contracts.rs:55:13
  14: clarity::vm::contexts::Environment::initialize_contract_from_ast::{{closure}}
             at ./build/clarity/./src/vm/contexts.rs:1403:26
  15: clarity::vm::contexts::Environment::initialize_contract_from_ast
             at ./build/clarity/./src/vm/contexts.rs:1377:22
  16: clarity::vm::contexts::OwnedEnvironment::initialize_contract_from_ast::{{closure}}
             at ./build/clarity/./src/vm/contexts.rs:705:17
  17: clarity::vm::contexts::OwnedEnvironment::execute_in_env
             at ./build/clarity/./src/vm/contexts.rs:631:13
  18: clarity::vm::contexts::OwnedEnvironment::initialize_contract_from_ast
             at ./build/clarity/./src/vm/contexts.rs:697:9
  19: clarity::vm::clarity::TransactionConnection::initialize_smart_contract::{{closure}}
             at ./build/clarity/./src/vm/clarity.rs:351:17
  20: <blockstack_lib::clarity_vm::clarity::ClarityTransactionConnection as clarity::vm::clarity::TransactionConnection>::with_abort_callback::{{closure}}::{{closure}}
             at ./build/stackslib/src/clarity_vm/clarity.rs:1695:30
  21: <blockstack_lib::clarity_vm::clarity::ClarityTransactionConnection as clarity::vm::clarity::TransactionConnection>::with_abort_callback::{{closure}}
             at ./build/stackslib/src/clarity_vm/clarity.rs:172:32
  22: <blockstack_lib::clarity_vm::clarity::ClarityTransactionConnection as clarity::vm::clarity::TransactionConnection>::with_abort_callback
             at ./build/stackslib/src/clarity_vm/clarity.rs:172:32
  23: clarity::vm::clarity::TransactionConnection::initialize_smart_contract
             at ./build/clarity/./src/vm/clarity.rs:349:47
  24: blockstack_lib::chainstate::stacks::db::transactions::<impl blockstack_lib::chainstate::stacks::db::StacksChainState>::process_transaction_payload
             at ./build/stackslib/src/chainstate/stacks/db/transactions.rs:1280:39
  25: blockstack_lib::chainstate::stacks::db::transactions::<impl blockstack_lib::chainstate::stacks::db::StacksChainState>::process_transaction
             at ./build/stackslib/src/chainstate/stacks/db/transactions.rs:1525:30
  26: <blockstack_lib::chainstate::nakamoto::miner::NakamotoBlockBuilder as blockstack_lib::chainstate::stacks::miner::BlockBuilder>::try_mine_tx_with_len
             at ./build/stackslib/src/chainstate/nakamoto/miner.rs:656:40
  27: blockstack_lib::chainstate::stacks::miner::<impl blockstack_lib::chainstate::stacks::StacksBlockBuilder>::select_and_apply_transactions::{{closure}}
             at ./build/stackslib/src/chainstate/stacks/miner.rs:2359:41
  28: blockstack_lib::core::mempool::MemPoolDB::iterate_candidates
             at ./build/stackslib/src/core/mempool.rs:1863:19
  29: blockstack_lib::chainstate::stacks::miner::<impl blockstack_lib::chainstate::stacks::StacksBlockBuilder>::select_and_apply_transactions
             at ./build/stackslib/src/chainstate/stacks/miner.rs:2269:43
  30: blockstack_lib::chainstate::nakamoto::miner::NakamotoBlockBuilder::build_nakamoto_block
             at ./build/stackslib/src/chainstate/nakamoto/miner.rs:533:42
  31: stacks_node::nakamoto_node::miner::BlockMinerThread::mine_block
             at ./build/testnet/stacks-node/src/nakamoto_node/miner.rs:1050:54
  32: stacks_node::nakamoto_node::miner::BlockMinerThread::run_miner
             at ./build/testnet/stacks-node/src/nakamoto_node/miner.rs:329:23
  33: stacks_node::nakamoto_node::relayer::RelayerThread::start_new_tenure::{{closure}}
             at ./build/testnet/stacks-node/src/nakamoto_node/relayer.rs:821:33
  34: std::sys::backtrace::__rust_begin_short_backtrace
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/backtrace.rs:154:18
  35: std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}}
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/thread/mod.rs:522:17
  36: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/panic/unwind_safe.rs:272:9
  37: std::panicking::try::do_call
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:554:40
  38: std::panicking::try
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:518:19
  39: std::panic::catch_unwind
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panic.rs:345:14
  40: std::thread::Builder::spawn_unchecked_::{{closure}}
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/thread/mod.rs:521:30
  41: core::ops::function::FnOnce::call_once{{vtable.shim}}
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/ops/function.rs:250:5
  42: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/alloc/src/boxed.rs:2231:9
  43: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/alloc/src/boxed.rs:2231:9
  44: std::sys::pal::unix::thread::Thread::new::thread_start
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/pal/unix/thread.rs:105:17
  45: <unknown>
  46: <unknown>)))
csgui commented 3 weeks ago

Fixed by https://github.com/stacks-network/stacks-core/pull/5401