stacks-network / clarity-wasm

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

define-read-only error on wasm testnet #548

Open csgui opened 3 weeks ago

csgui commented 3 weeks ago

The following code caused an error in the testnet instance.

(define-read-only (get-decimals) (ok u0))
(define-read-only (get-name) (ok "Rocket Token"))
(define-read-only (get-symbol) (ok "RKT"))
(define-read-only (get-symbol) (ok "RKT"))
(define-read-only (get-token-uri) (ok none))

Stack-trace:

Interpreter(Wasm(UnableToLoadModule(failed to parse WebAssembly module

Caused by:
    Invalid input WebAssembly code at offset 3808: duplicate export name `get-symbol` already defined

Stack backtrace:
   0: <E as anyhow::context::ext::StdError>::ext_context
             at ./usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/anyhow-1.0.91/src/backtrace.rs:27:14
   1: anyhow::context::<impl anyhow::Context<T,E> for core::result::Result<T,E>>::context
             at ./usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/anyhow-1.0.91/src/context.rs:54:31
   2: wasmtime::module::Module::build_artifacts
             at ./usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-15.0.1/src/module.rs:414:31
   3: wasmtime::module::Module::from_binary::{{closure}}
             at ./usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-15.0.1/src/module.rs:320:44
   4: core::ops::function::FnOnce::call_once
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/ops/function.rs:250:5
   5: wasmtime_cache::ModuleCacheEntry::get_data_raw
             at ./usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-cache-15.0.1/src/lib.rs:83:28
   6: wasmtime::module::Module::from_binary
             at ./usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-15.0.1/src/module.rs:311:46
   7: clarity::vm::clarity_wasm::initialize_contract::{{closure}}
             at ./build/clarity/./src/vm/clarity_wasm.rs:415:13
   8: clarity::vm::contexts::ContractContext::with_wasm_module
             at ./build/clarity/./src/vm/contexts.rs:1917:9
   9: clarity::vm::clarity_wasm::initialize_contract
             at ./build/clarity/./src/vm/clarity_wasm.rs:412:18
  10: clarity::vm::contracts::Contract::initialize_from_ast::{{closure}}
             at ./build/clarity/./src/vm/contracts.rs:56:17
  11: clarity::vm::contexts::GlobalContext::execute
             at ./build/clarity/./src/vm/contexts.rs:1723:22
  12: clarity::vm::contracts::Contract::initialize_from_ast
             at ./build/clarity/./src/vm/contracts.rs:55:13
  13: clarity::vm::contexts::Environment::initialize_contract_from_ast::{{closure}}
             at ./build/clarity/./src/vm/contexts.rs:1403:26
  14: clarity::vm::contexts::Environment::initialize_contract_from_ast
             at ./build/clarity/./src/vm/contexts.rs:1377:22
  15: clarity::vm::contexts::OwnedEnvironment::initialize_contract_from_ast::{{closure}}
             at ./build/clarity/./src/vm/contexts.rs:705:17
  16: clarity::vm::contexts::OwnedEnvironment::execute_in_env
             at ./build/clarity/./src/vm/contexts.rs:631:13
  17: clarity::vm::contexts::OwnedEnvironment::initialize_contract_from_ast
             at ./build/clarity/./src/vm/contexts.rs:697:9
  18: clarity::vm::clarity::TransactionConnection::initialize_smart_contract::{{closure}}
             at ./build/clarity/./src/vm/clarity.rs:351:17
  19: <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
  20: <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
  21: <blockstack_lib::clarity_vm::clarity::ClarityTransactionConnection as clarity::vm::clarity::TransactionConnection>::with_abort_callback
             at ./build/stackslib/src/clarity_vm/clarity.rs:172:32
  22: clarity::vm::clarity::TransactionConnection::initialize_smart_contract
             at ./build/clarity/./src/vm/clarity.rs:349:47
  23: 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
  24: 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
  25: <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
  26: 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
  27: blockstack_lib::core::mempool::MemPoolDB::iterate_candidates
             at ./build/stackslib/src/core/mempool.rs:1863:19
  28: 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
  29: blockstack_lib::chainstate::nakamoto::miner::NakamotoBlockBuilder::build_nakamoto_block
             at ./build/stackslib/src/chainstate/nakamoto/miner.rs:533:42
  30: stacks_node::nakamoto_node::miner::BlockMinerThread::mine_block
             at ./build/testnet/stacks-node/src/nakamoto_node/miner.rs:1050:54
  31: stacks_node::nakamoto_node::miner::BlockMinerThread::run_miner
             at ./build/testnet/stacks-node/src/nakamoto_node/miner.rs:329:23
  32: stacks_node::nakamoto_node::relayer::RelayerThread::start_new_tenure::{{closure}}
             at ./build/testnet/stacks-node/src/nakamoto_node/relayer.rs:821:33
  33: std::sys::backtrace::__rust_begin_short_backtrace
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/backtrace.rs:154:18
  34: std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}}
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/thread/mod.rs:522:17
  35: <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
  36: std::panicking::try::do_call
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:554:40
  37: std::panicking::try
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panicking.rs:518:19
  38: std::panic::catch_unwind
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/panic.rs:345:14
  39: std::thread::Builder::spawn_unchecked_::{{closure}}
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/thread/mod.rs:521:30
  40: core::ops::function::FnOnce::call_once{{vtable.shim}}
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/ops/function.rs:250:5
  41: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/alloc/src/boxed.rs:2231:9
  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: std::sys::pal::unix::thread::Thread::new::thread_start
             at ./rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/std/src/sys/pal/unix/thread.rs:105:17
  44: <unknown>
  45: <unknown>)))
csgui commented 3 weeks ago

Check https://github.com/stacks-network/clarity-wasm/commit/7e964a76aff8a62d2af904fa500a11cf8fd261c9