Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] console.assert() when running from CLI #566

Closed
bendyarm opened this issue Jan 25, 2021 · 2 comments
Closed

[Bug] console.assert() when running from CLI #566

bendyarm opened this issue Jan 25, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@bendyarm
Copy link
Collaborator

🐛 Bug Report

Adding a simple console.assert causes leo run to fail.
Transcript:

batman@batorang:~$ leo new simple-console-1
Initializing Successfully initialized package "simple-console-1"

batman@batorang:~$ cd !$
cd simple-console-1
batman@batorang:~/simple-console-1$ cat src/main.leo
// The 'simple-console-1' main function.
function main(a: u32, b: u32) -> u32 {
    let c: u32 = a + b;
    return c
}

Then I added the console.assert statement

batman@batorang:~/simple-console-1$ cat src/main.leo
// The 'simple-console-1' main function.
function main(a: u32, b: u32) -> u32 {
    let c: u32 = a + b;
    console.assert(c == b + a);
    return c
}
batman@batorang:~/simple-console-1$ leo run
 Compiling Starting...
 Compiling Compiling main program... ("/home/batman/simple-console-1/src/main.leo")
 Compiling Complete
      Done Finished in 7 milliseconds

     Setup Starting...
     Setup     --> "/home/batman/simple-console-1/src/main.leo": 4:5
     |
   4 |      console.assert(c == b + a);
     |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = console.assert() failed to evaluate. This error is caused by empty input file values
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: SynthesisError(Unsatisfiable)', leo/commands/setup.rs:88:94
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
batman@batorang:~/simple-console-1$ export RUST_BACKTRACE=1
batman@batorang:~/simple-console-1$ leo run
 Compiling Starting...
 Compiling Compiling main program... ("/home/batman/simple-console-1/src/main.leo")
 Compiling Complete
      Done Finished in 8 milliseconds

     Setup Starting...
     Setup     --> "/home/batman/simple-console-1/src/main.leo": 4:5
     |
   4 |      console.assert(c == b + a);
     |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = console.assert() failed to evaluate. This error is caused by empty input file values
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: SynthesisError(Unsatisfiable)', leo/commands/setup.rs:88:94
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:483
   1: core::panicking::panic_fmt
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/panicking.rs:85
   2: core::option::expect_none_failed
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/option.rs:1234
   3: <leo_lang::commands::setup::SetupCommand as leo_lang::cli::CLI>::output
   4: <leo_lang::commands::prove::ProveCommand as leo_lang::cli::CLI>::output
   5: <leo_lang::commands::run::RunCommand as leo_lang::cli::CLI>::output
   6: leo_lang::cli::CLI::process
   7: leo::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
batman@batorang:~/simple-console-1$ export RUST_BACKTRACE=full
batman@batorang:~/simple-console-1$ leo run
 Compiling Starting...
 Compiling Compiling main program... ("/home/batman/simple-console-1/src/main.leo")
 Compiling Complete
      Done Finished in 20 milliseconds

     Setup Starting...
     Setup     --> "/home/batman/simple-console-1/src/main.leo": 4:5
     |
   4 |      console.assert(c == b + a);
     |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = console.assert() failed to evaluate. This error is caused by empty input file values
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: SynthesisError(Unsatisfiable)', leo/commands/setup.rs:88:94
stack backtrace:
   0:     0x564c9a85ccf4 - std::backtrace_rs::backtrace::libunwind::trace::h72c2fb8038f1bbee
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/../../backtrace/src/backtrace/libunwind.rs:96
   1:     0x564c9a85ccf4 - std::backtrace_rs::backtrace::trace_unsynchronized::h1e3b084883f1e78c
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/../../backtrace/src/backtrace/mod.rs:66
   2:     0x564c9a85ccf4 - std::sys_common::backtrace::_print_fmt::h3bf6a7ebf7f0394a
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/sys_common/backtrace.rs:79
   3:     0x564c9a85ccf4 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h2e8cb764b7fe02e7
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/sys_common/backtrace.rs:58
   4:     0x564c99db229c - core::fmt::write::h7a1184eaee6a8644
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/fmt/mod.rs:1080
   5:     0x564c9a856372 - std::io::Write::write_fmt::haeeb374d93a67eac
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/io/mod.rs:1516
   6:     0x564c9a8612fa - std::sys_common::backtrace::_print::h1d14a7f6ad632dc8
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/sys_common/backtrace.rs:61
   7:     0x564c9a8612fa - std::sys_common::backtrace::print::h301abac8bb2e3e81
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/sys_common/backtrace.rs:48
   8:     0x564c9a8612fa - std::panicking::default_hook::{{closure}}::hde0cb80358a6920a
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:208
   9:     0x564c9a861ae4 - std::panicking::default_hook::h9b1a691049a0ec8f
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:227
  10:     0x564c9a861ae4 - std::panicking::rust_panic_with_hook::h2bdec87b60580584
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:577
  11:     0x564c9a8614f7 - std::panicking::begin_panic_handler::{{closure}}::h101ca09d9df5db47
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:484
  12:     0x564c9a85f458 - std::sys_common::backtrace::__rust_end_short_backtrace::h3bb85654c20113ca
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/sys_common/backtrace.rs:153
  13:     0x564c9a8614cd - rust_begin_unwind
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:483
  14:     0x564c99db0031 - core::panicking::panic_fmt::h48c31e1e3d550146
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/panicking.rs:85
  15:     0x564c99daff23 - core::option::expect_none_failed::h6154dc750ae47ade
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/option.rs:1234
  16:     0x564c99f9ab1d - <leo_lang::commands::setup::SetupCommand as leo_lang::cli::CLI>::output::h52f2f04031d72167
  17:     0x564c9a59ba4b - <leo_lang::commands::prove::ProveCommand as leo_lang::cli::CLI>::output::ha419025631c348bd
  18:     0x564c9a3a55f8 - <leo_lang::commands::run::RunCommand as leo_lang::cli::CLI>::output::h7b38305321424a7b
  19:     0x564c99d33e5e - leo_lang::cli::CLI::process::h6b2f5956782f72fc
  20:     0x564c99d277c4 - leo::main::ha307e072c6c46910
  21:     0x564c99d283fa - std::sys_common::backtrace::__rust_begin_short_backtrace::h06b926fa8874f9c0
  22:     0x564c99d26578 - std::rt::lang_start::{{closure}}::h1d26920d5306ce7b
  23:     0x564c9a8620d4 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::he179d32a5d10d957
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/ops/function.rs:259
  24:     0x564c9a8620d4 - std::panicking::try::do_call::hcb3d5e7be089b2b4
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:381
  25:     0x564c9a8620d4 - std::panicking::try::h7ac93b0cd56fb701
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:345
  26:     0x564c9a8620d4 - std::panic::catch_unwind::h7b40e396c93a4fcd
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panic.rs:382
  27:     0x564c9a8620d4 - std::rt::lang_start_internal::h142b9cc66267fea1
                               at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/rt.rs:51
  28:     0x564c99d27ad2 - main
  29:     0x7f7f8c24bb97 - __libc_start_main
  30:     0x564c99d25a1a - _start
  31:                0x0 - <unknown>
batman@batorang:~/simple-console-1$ 

Your Environment

leo v1.0.8
rustc 1.48.0 (7eac88abb 2020-11-16)
Linux Mint 19.3 (based on Ubuntu 18.04)

@bendyarm bendyarm added the bug Something isn't working label Jan 25, 2021
@collinc97
Copy link
Collaborator

Thanks for filing this @bendyarm!

The above code should not compile with a console.assert statement in the main function.
console functions should be used for testing only as described in the developer docs

The reasoning for this approach is because console functions do not create constraints in the circuit. Leaving them inside production code is dangerous because they may be interpreted as constraint assertions.

The real bug here is the error message. It should be changed to something more clear to let the programmer know the expected behavior.

@collinc97
Copy link
Collaborator

collinc97 commented Jan 26, 2021

Closing since the new error has been outlined in #580

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants