leo icon indicating copy to clipboard operation
leo copied to clipboard

[Bug] Panic on when using `assert_eq` on arrays

Open AleoAlexander opened this issue 2 months ago • 10 comments

🐛 Bug Report

The compiler panics at runtime when calling the code below. The program will build with no errors.

Code:

let x : [u8;3] = [4u8;3];
x[0] = 2u8;
assert_eq(x, [2u8,4u8,4u8]);

Error:

Image

AleoAlexander avatar Nov 11 '25 21:11 AleoAlexander

Are you using leo run here?

mohammadfawaz avatar Nov 13 '25 02:11 mohammadfawaz

Yeah, using leo run

AleoAlexander avatar Nov 13 '25 13:11 AleoAlexander

Yeah this is new.. we used to just error out saying some constraint failed. But now if you try to run anything that has a trivially false assert you'll get the above.

mohammadfawaz avatar Nov 13 '25 17:11 mohammadfawaz

This seems like bad practice. It should return an actual Leo compiler error message rather than just panicking

AleoAlexander avatar Nov 13 '25 18:11 AleoAlexander

Yes absolutely. There are some proposals floating around regarding this exact issue.

mohammadfawaz avatar Nov 13 '25 18:11 mohammadfawaz

I believe that using catch_unwind on the authorize call and/or the evaluate call will fix this.

mohammadfawaz avatar Dec 02 '25 14:12 mohammadfawaz

I just encountered a VM panic! during a call to deploy while working on #29025:

thread `main` panicked at /home/mindtree/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/snarkvm-circuit-environment-4.4.0/src/testnet_circuit.rs:152:29:
assertion `left == right` failed: Constant constraint failed: (0 * 1) =?= 1
  left: 0
 right: 1
stack backtrace:
...

We may need to also wrap this deploy call-site with a catch_unwind for now too.

It looks like something similar has been previously reported here w.r.t. test failures:

  • https://github.com/ProvableHQ/leo/issues/27858

Related issue in snarkvm:

  • https://github.com/ProvableHQ/snarkVM/issues/2941

It looks like this PR attempts to address something similar, but also bandaids around the core issue with use of catch_unwind:

  • https://github.com/ProvableHQ/snarkVM/pull/2927

Without addressing this in snarkVM, we'll end up needing to use catch_unwind everywhere we invoke the VM throughout tooling in order to ensure a cohesive devex. Panic was never intended to be used as an exception like this - we lose all type info about the error and just get a big string and backtrace dump. Ideally we would:

  • Return an error when the embedded snarkVM panics (or some type that can describe the embedded snarkVM failed to execute due to a panic in the aleo program).
  • Aim to provide the guarantee that the VM never panics the host process, and treat any user-facing panic! as a VM bug.

I'd be happy to dig into https://github.com/ProvableHQ/snarkVM/issues/2941 and attempt to address panic! sites that should be errors if there's interest? Maybe best to chat about this in our next sync.

mitchmindtree avatar Dec 05 '25 05:12 mitchmindtree

It looks like we're not actually able to catch_unwind the vm deploy step as the panic! occurs within a non-unwind-safe context.

Here's the full backtrace for context:

thread `main` panicked at /home/mindtree/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/snarkvm-circuit-environment-4.4.0/src/testnet_circuit.rs:152:29:
assertion `left == right` failed: Constant constraint failed: (0 * 1) =?= 1
  left: 0
 right: 1
stack backtrace:
   0: leo::set_panic_hook::{closure#0}
             at /home/mindtree/repo/provable/leo/leo/cli/main.rs:26:50
   1: <alloc::boxed::Box<dyn for<'a, 'b> core::ops::function::Fn<(&'a std::panic::PanicHookInfo<'b>,), Output = ()> + core::marker::Send + core::marker::Sync> as core::ops::function::Fn<(&std::panic::Pan
cHookInfo,)>>::call
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/alloc/src/boxed.rs:2220:9
      std::panicking::panic_with_hook
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/panicking.rs:833:13
   2: std::panicking::panic_handler::{closure#0}
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/panicking.rs:698:13
   3: std::sys::backtrace::__rust_end_short_backtrace::<std::panicking::panic_handler::{closure#0}, !>
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/sys/backtrace.rs:176:18
   4: __rustc::rust_begin_unwind
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/panicking.rs:689:5
   5: core::panicking::panic_fmt
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/core/src/panicking.rs:80:14
   6: core::panicking::assert_failed_inner
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/core/src/panicking.rs:434:23
   7: core::panicking::assert_failed::<snarkvm_fields::fp_256::Fp256<snarkvm_curves::bls12_377::fr::FrParameters>, snarkvm_fields::fp_256::Fp256<snarkvm_curves::bls12_377::fr::FrParameters>>
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/core/src/panicking.rs:394:5
   8: <snarkvm_circuit_environment::testnet_circuit::TestnetCircuit as snarkvm_circuit_environment::environment::Environment>::enforce::<<snarkvm_circuit_network::testnet_v0::AleoTestnetV0 as snarkvm_cir
uit_environment::environment::Environment>::assert<snarkvm_circuit_types_boolean::Boolean<snarkvm_circuit_network::testnet_v0::AleoTestnetV0>>::{closure#0}, snarkvm_circuit_types_boolean::Boolean<snarkvm
circuit_network::testnet_v0::AleoTestnetV0>, snarkvm_circuit_environment::helpers::linear_combination::LinearCombination<snarkvm_fields::fp_256::Fp256<snarkvm_curves::bls12_377::fr::FrParameters>>, snark
m_circuit_environment::helpers::linear_combination::LinearCombination<snarkvm_fields::fp_256::Fp256<snarkvm_curves::bls12_377::fr::FrParameters>>>::{closure#0}::{closure#0}
             at /home/mindtree/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/snarkvm-circuit-environment-4.4.0/src/testnet_circuit.rs:152:29
      <std::thread::local::LocalKey<core::cell::RefCell<snarkvm_circuit_environment::helpers::r1cs::R1CS<snarkvm_fields::fp_256::Fp256<snarkvm_curves::bls12_377::fr::FrParameters>>>>>::try_with::<<snarkv
_circuit_environment::testnet_circuit::TestnetCircuit as snarkvm_circuit_environment::environment::Environment>::enforce<<snarkvm_circuit_network::testnet_v0::AleoTestnetV0 as snarkvm_circuit_environment
:environment::Environment>::assert<snarkvm_circuit_types_boolean::Boolean<snarkvm_circuit_network::testnet_v0::AleoTestnetV0>>::{closure#0}, snarkvm_circuit_types_boolean::Boolean<snarkvm_circuit_network
:testnet_v0::AleoTestnetV0>, snarkvm_circuit_environment::helpers::linear_combination::LinearCombination<snarkvm_fields::fp_256::Fp256<snarkvm_curves::bls12_377::fr::FrParameters>>, snarkvm_circuit_envir
nment::helpers::linear_combination::LinearCombination<snarkvm_fields::fp_256::Fp256<snarkvm_curves::bls12_377::fr::FrParameters>>>::{closure#0}::{closure#0}, ()>
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/thread/local.rs:513:12
      <std::thread::local::LocalKey<core::cell::RefCell<snarkvm_circuit_environment::helpers::r1cs::R1CS<snarkvm_fields::fp_256::Fp256<snarkvm_curves::bls12_377::fr::FrParameters>>>>>::with::<<snarkvm_ci
cuit_environment::testnet_circuit::TestnetCircuit as snarkvm_circuit_environment::environment::Environment>::enforce<<snarkvm_circuit_network::testnet_v0::AleoTestnetV0 as snarkvm_circuit_environment::en
ironment::Environment>::assert<snarkvm_circuit_types_boolean::Boolean<snarkvm_circuit_network::testnet_v0::AleoTestnetV0>>::{closure#0}, snarkvm_circuit_types_boolean::Boolean<snarkvm_circuit_network::te
tnet_v0::AleoTestnetV0>, snarkvm_circuit_environment::helpers::linear_combination::LinearCombination<snarkvm_fields::fp_256::Fp256<snarkvm_curves::bls12_377::fr::FrParameters>>, snarkvm_circuit_environme
t::helpers::linear_combination::LinearCombination<snarkvm_fields::fp_256::Fp256<snarkvm_curves::bls12_377::fr::FrParameters>>>::{closure#0}::{closure#0}, ()>
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/thread/local.rs:477:20
      <snarkvm_circuit_environment::testnet_circuit::TestnetCircuit as snarkvm_circuit_environment::environment::Environment>::enforce::<<snarkvm_circuit_network::testnet_v0::AleoTestnetV0 as snarkvm_cir
uit_environment::environment::Environment>::assert<snarkvm_circuit_types_boolean::Boolean<snarkvm_circuit_network::testnet_v0::AleoTestnetV0>>::{closure#0}, snarkvm_circuit_types_boolean::Boolean<snarkvm
circuit_network::testnet_v0::AleoTestnetV0>, snarkvm_circuit_environment::helpers::linear_combination::LinearCombination<snarkvm_fields::fp_256::Fp256<snarkvm_curves::bls12_377::fr::FrParameters>>, snark
m_circuit_environment::helpers::linear_combination::LinearCombination<snarkvm_fields::fp_256::Fp256<snarkvm_curves::bls12_377::fr::FrParameters>>>::{closure#0}
             at /home/mindtree/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/snarkvm-circuit-environment-4.4.0/src/testnet_circuit.rs:135:33
      <std::thread::local::LocalKey<core::cell::Cell<bool>>>::try_with::<<snarkvm_circuit_environment::testnet_circuit::TestnetCircuit as snarkvm_circuit_environment::environment::Environment>::enforce<<
narkvm_circuit_network::testnet_v0::AleoTestnetV0 as snarkvm_circuit_environment::environment::Environment>::assert<snarkvm_circuit_types_boolean::Boolean<snarkvm_circuit_network::testnet_v0::AleoTestnet
0>>::{closure#0}, snarkvm_circuit_types_boolean::Boolean<snarkvm_circuit_network::testnet_v0::AleoTestnetV0>, snarkvm_circuit_environment::helpers::linear_combination::LinearCombination<snarkvm_fields::f
_256::Fp256<snarkvm_curves::bls12_377::fr::FrParameters>>, snarkvm_circuit_environment::helpers::linear_combination::LinearCombination<snarkvm_fields::fp_256::Fp256<snarkvm_curves::bls12_377::fr::FrParam
ters>>>::{closure#0}, ()>
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/thread/local.rs:513:12
      <std::thread::local::LocalKey<core::cell::Cell<bool>>>::with::<<snarkvm_circuit_environment::testnet_circuit::TestnetCircuit as snarkvm_circuit_environment::environment::Environment>::enforce<<snar
vm_circuit_network::testnet_v0::AleoTestnetV0 as snarkvm_circuit_environment::environment::Environment>::assert<snarkvm_circuit_types_boolean::Boolean<snarkvm_circuit_network::testnet_v0::AleoTestnetV0>>
:{closure#0}, snarkvm_circuit_types_boolean::Boolean<snarkvm_circuit_network::testnet_v0::AleoTestnetV0>, snarkvm_circuit_environment::helpers::linear_combination::LinearCombination<snarkvm_fields::fp_25
::Fp256<snarkvm_curves::bls12_377::fr::FrParameters>>, snarkvm_circuit_environment::helpers::linear_combination::LinearCombination<snarkvm_fields::fp_256::Fp256<snarkvm_curves::bls12_377::fr::FrParameter
>>>::{closure#0}, ()>
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/thread/local.rs:477:20
   9: <snarkvm_circuit_environment::testnet_circuit::TestnetCircuit as snarkvm_circuit_environment::environment::Environment>::enforce::<<snarkvm_circuit_network::testnet_v0::AleoTestnetV0 as snarkvm_cir
uit_environment::environment::Environment>::assert<snarkvm_circuit_types_boolean::Boolean<snarkvm_circuit_network::testnet_v0::AleoTestnetV0>>::{closure#0}, snarkvm_circuit_types_boolean::Boolean<snarkvm
circuit_network::testnet_v0::AleoTestnetV0>, snarkvm_circuit_environment::helpers::linear_combination::LinearCombination<snarkvm_fields::fp_256::Fp256<snarkvm_curves::bls12_377::fr::FrParameters>>, snark
m_circuit_environment::helpers::linear_combination::LinearCombination<snarkvm_fields::fp_256::Fp256<snarkvm_curves::bls12_377::fr::FrParameters>>>
             at /home/mindtree/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/snarkvm-circuit-environment-4.4.0/src/testnet_circuit.rs:132:20
      <snarkvm_circuit_network::testnet_v0::AleoTestnetV0 as snarkvm_circuit_environment::environment::Environment>::enforce::<<snarkvm_circuit_network::testnet_v0::AleoTestnetV0 as snarkvm_circuit_environment::environment::Environment>::assert<snarkvm_circuit_types_boolean::Boolean<snarkvm_circuit_network::testnet_v0::AleoTestnetV0>>::{closure#0}, snarkvm_circuit_types_boolean::Boolean<snarkvm_circuit_network::testnet_v0::AleoTestnetV0>, snarkvm_circuit_environment::helpers::linear_combination::LinearCombination<snarkvm_fields::fp_256::Fp256<snarkvm_curves::bls12_377::fr::FrParameters>>, snarkvm_circuit_environment::helpers::linear_combination::LinearCombination<snarkvm_fields::fp_256::Fp256<snarkvm_curves::bls12_377::fr::FrParameters>>>
             at /home/mindtree/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/snarkvm-circuit-network-4.4.0/src/testnet_v0.rs:433:9
      <snarkvm_circuit_network::testnet_v0::AleoTestnetV0 as snarkvm_circuit_environment::environment::Environment>::assert::<snarkvm_circuit_types_boolean::Boolean<snarkvm_circuit_network::testnet_v0::AleoTestnetV0>>
             at /home/mindtree/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/snarkvm-circuit-environment-4.4.0/src/environment.rs:74:9
  10: <snarkvm_synthesizer_program::logic::instruction::operation::assert::AssertInstruction<snarkvm_console_network::testnet_v0::TestnetV0, 0>>::execute::<snarkvm_circuit_network::testnet_v0::AleoTestnetV0, snarkvm_synthesizer_process::stack::Stack<snarkvm_console_network::testnet_v0::TestnetV0>, snarkvm_synthesizer_process::stack::registers::Registers<snarkvm_console_network::testnet_v0::TestnetV0, snarkvm_circuit_network::testnet_v0::AleoTestnetV0>>
             at /home/mindtree/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/snarkvm-synthesizer-program-4.4.0/src/logic/instruction/operation/assert.rs:121:18
  11: <snarkvm_synthesizer_process::stack::Stack<snarkvm_console_network::testnet_v0::TestnetV0>>::execute_function::<snarkvm_circuit_network::testnet_v0::AleoTestnetV0, rand_chacha::chacha::ChaCha20Rng>
             at /home/mindtree/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/snarkvm-synthesizer-process-4.4.0/src/stack/execute.rs:325:34
  12: <snarkvm_synthesizer_process::stack::Stack<snarkvm_console_network::testnet_v0::TestnetV0>>::synthesize_key::<snarkvm_circuit_network::testnet_v0::AleoTestnetV0, rand_chacha::chacha::ChaCha20Rng>
             at /home/mindtree/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/snarkvm-synthesizer-process-4.4.0/src/stack/helpers/synthesize.rs:82:30
      <snarkvm_synthesizer_process::stack::Stack<snarkvm_console_network::testnet_v0::TestnetV0>>::deploy::<snarkvm_circuit_network::testnet_v0::AleoTestnetV0, rand_chacha::chacha::ChaCha20Rng>
             at /home/mindtree/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/snarkvm-synthesizer-process-4.4.0/src/stack/deploy.rs:34:18
      <snarkvm_synthesizer_process::Process<snarkvm_console_network::testnet_v0::TestnetV0>>::deploy::<snarkvm_circuit_network::testnet_v0::AleoTestnetV0, rand_chacha::chacha::ChaCha20Rng>
             at /home/mindtree/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/snarkvm-synthesizer-process-4.4.0/src/deploy.rs:33:32
      <snarkvm_synthesizer::vm::VM<snarkvm_console_network::testnet_v0::TestnetV0, snarkvm_ledger_store::helpers::memory::consensus::ConsensusMemory<snarkvm_console_network::testnet_v0::TestnetV0>>>::deploy_raw::<rand_chacha::chacha::ChaCha20Rng>
             at /home/mindtree/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/snarkvm-synthesizer-4.4.0/src/vm/deploy.rs:94:43
      <snarkvm_synthesizer::vm::VM<snarkvm_console_network::testnet_v0::TestnetV0, snarkvm_ledger_store::helpers::memory::consensus::ConsensusMemory<snarkvm_console_network::testnet_v0::TestnetV0>>>::deploy::<rand_chacha::chacha::ChaCha20Rng>
             at /home/mindtree/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/snarkvm-synthesizer-4.4.0/src/vm/deploy.rs:35:35
  13: leo_compiler::run::run_with_ledger::{closure#3}::{closure#0}
             at /home/mindtree/repo/provable/leo/compiler/compiler/src/run.rs:323:29
      <leo_compiler::run::run_with_ledger::{closure#3}::{closure#0} as core::ops::function::FnOnce<()>>::call_once
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/core/src/ops/function.rs:250:5
      <core::panic::unwind_safe::AssertUnwindSafe<leo_compiler::run::run_with_ledger::{closure#3}::{closure#0}> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/core/src/panic/unwind_safe.rs:274:9
      std::panicking::catch_unwind::do_call::<core::panic::unwind_safe::AssertUnwindSafe<leo_compiler::run::run_with_ledger::{closure#3}::{closure#0}>, core::result::Result<snarkvm_ledger_block::transaction::Transaction<snarkvm_console_network::testnet_v0::TestnetV0>, anyhow::Error>>
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/panicking.rs:581:40
      std::panicking::catch_unwind::<core::result::Result<snarkvm_ledger_block::transaction::Transaction<snarkvm_console_network::testnet_v0::TestnetV0>, anyhow::Error>, core::panic::unwind_safe::AssertUnwindSafe<leo_compiler::run::run_with_ledger::{closure#3}::{closure#0}>>
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/panicking.rs:544:19
      std::panic::catch_unwind::<core::panic::unwind_safe::AssertUnwindSafe<leo_compiler::run::run_with_ledger::{closure#3}::{closure#0}>, core::result::Result<snarkvm_ledger_block::transaction::Transaction<snarkvm_console_network::testnet_v0::TestnetV0>, anyhow::Error>>
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/panic.rs:359:14
      leo_compiler::run::run_with_ledger::{closure#3}
             at /home/mindtree/repo/provable/leo/compiler/compiler/src/run.rs:322:36
on<snarkvm_console_network::testnet_v0::TestnetV0>, anyhow::Error>>
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/panic.rs:359:14
      leo_compiler::run::run_with_ledger::{closure#3}
             at /home/mindtree/repo/provable/leo/compiler/compiler/src/run.rs:322:36
  14: leo_compiler::run::run_with_ledger
             at /home/mindtree/repo/provable/leo/compiler/compiler/src/run.rs:355:9
  15: leo_lang::cli::commands::test::handle_test
             at /home/mindtree/repo/provable/leo/leo/cli/commands/test.rs:128:20
      <leo_lang::cli::commands::test::LeoTest as leo_lang::cli::commands::Command>::apply
             at /home/mindtree/repo/provable/leo/leo/cli/commands/test.rs:60:9
  16: <leo_lang::cli::commands::test::LeoTest as leo_lang::cli::commands::Command>::execute
             at /home/mindtree/repo/provable/leo/leo/cli/commands/mod.rs:129:24
      <leo_lang::cli::commands::test::LeoTest as leo_lang::cli::commands::Command>::try_execute
             at /home/mindtree/repo/provable/leo/leo/cli/commands/mod.rs:143:14
  17: leo_lang::cli::cli::run_with_args
             at /home/mindtree/repo/provable/leo/leo/cli/cli.rs:179:47
  18: leo::main::{closure#0}
             at /home/mindtree/repo/provable/leo/leo/cli/main.rs:47:53
      <scoped_tls::ScopedKey<leo_span::symbol::SessionGlobals>>::with::<leo::main::{closure#0}, ()>
             at /home/mindtree/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/scoped-tls-1.0.1/src/lib.rs:171:13
  19: leo_span::symbol::create_session_if_not_set_then::<(), leo::main::{closure#0}>::{closure#0}
             at /home/mindtree/repo/provable/leo/compiler/span/src/symbol.rs:450:53
      <scoped_tls::ScopedKey<leo_span::symbol::SessionGlobals>>::set::<leo_span::symbol::create_session_if_not_set_then<(), leo::main::{closure#0}>::{closure#0}, ()>
             at /home/mindtree/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/scoped-tls-1.0.1/src/lib.rs:137:9
  20: leo_span::symbol::create_session_if_not_set_then::<(), leo::main::{closure#0}>
             at /home/mindtree/repo/provable/leo/compiler/span/src/symbol.rs:450:25
      leo::main
             at /home/mindtree/repo/provable/leo/leo/cli/main.rs:47:5
  21: <fn() as core::ops::function::FnOnce<()>>::call_once
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/core/src/ops/function.rs:250:5
      std::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/sys/backtrace.rs:160:18
  22: std::rt::lang_start::<()>::{closure#0}
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/rt.rs:206:18
  23: <&dyn core::ops::function::Fn<(), Output = i32> + core::panic::unwind_safe::RefUnwindSafe + core::marker::Sync as core::ops::function::FnOnce<()>>::call_once
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/core/src/ops/function.rs:287:21
      std::panicking::catch_unwind::do_call::<&dyn core::ops::function::Fn<(), Output = i32> + core::panic::unwind_safe::RefUnwindSafe + core::marker::Sync, i32>
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/panicking.rs:581:40
      std::panicking::catch_unwind::<i32, &dyn core::ops::function::Fn<(), Output = i32> + core::panic::unwind_safe::RefUnwindSafe + core::marker::Sync>
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/panicking.rs:544:19
      std::panic::catch_unwind::<&dyn core::ops::function::Fn<(), Output = i32> + core::panic::unwind_safe::RefUnwindSafe + core::marker::Sync, i32>
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/panic.rs:359:14
      std::rt::lang_start_internal::{closure#0}
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/rt.rs:175:24
      std::panicking::catch_unwind::do_call::<std::rt::lang_start_internal::{closure#0}, isize>
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/panicking.rs:581:40
      std::panicking::catch_unwind::<isize, std::rt::lang_start_internal::{closure#0}>
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/panicking.rs:544:19
      std::panic::catch_unwind::<std::rt::lang_start_internal::{closure#0}, isize>
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/panic.rs:359:14
      std::rt::lang_start_internal
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/rt.rs:171:5
  24: std::rt::lang_start::<()>
             at /rustc/1d60f9e070c1039b263e0f035c0f03dfcc610d0f/library/std/src/rt.rs:205:5
  25: __libc_start_call_main
  26: __libc_start_main_alias_1
  27: _start

Looking at frames 8-9 of the stack trace, the panic occurs deep inside thread-local storage (TLS) access:

  <std::thread::local::LocalKey<core::cell::RefCell<...>>>::try_with
  <std::thread::local::LocalKey<core::cell::RefCell<...>>>::with

So we're likely unable to catch_unwind because we're panic!ing while the threadlocal RefCell containing circuit state is borrowed, leading to a kind of RefCell "poisoning". This is another good reason to prefer using a type (like an error) to represent VM panics intead of panicking the whole host process.

mitchmindtree avatar Dec 05 '25 06:12 mitchmindtree

@mitchmindtree very happy to see you found all the related issues and PRs!

I'd be happy to dig into https://github.com/ProvableHQ/snarkVM/issues/2941 and attempt to address panic! sites that should be errors if there's interest? Maybe best to chat about this in our next sync.

That would be great, though please do not try to comprehensively replace all panicking code. Just focus on resolving this specific Leo issue.

Morover, just saying "Constraint failed 0 != 1" is not very helpful. We should be reporting:

  • the aleo instructions line number (can you make a new snarkVM issue?)
  • the associated leo program line number and variable values (can you make a new leo issue if you agree?)

vicsn avatar Dec 05 '25 09:12 vicsn

Opened:

  • https://github.com/ProvableHQ/snarkVM/issues/3055
  • https://github.com/ProvableHQ/leo/issues/29035

That would be great, though please do not try to comprehensively replace all panicking code. Just focus on resolving this specific Leo issue.

For sure! I've been doing some digging into this, I'll track progress under https://github.com/ProvableHQ/snarkVM/issues/2941.

mitchmindtree avatar Dec 09 '25 00:12 mitchmindtree