iden3 / circom

zkSnark circuit compiler
GNU General Public License v3.0
1.31k stars 253 forks source link

Logging Bug during Compile Step #240

Closed Shadow-Silhouette closed 7 months ago

Shadow-Silhouette commented 7 months ago

Bug Report

Description

When introducing a log statement with a line break to a circuit, the circom compiler panics and does not exit gracefully.
As a user of the circom compiler, I expect the compiler to exit gracefully and provide a meaningful error message.

Example Circuit

bug.circom

pragma circom 2.1.8;

template Example() {
signal input a;
signal input b;
signal input c;
signal output d;
signal output e;

log("abc
def");

d <== (a * b);
e <== ((a * b) + c);
}
component main { public [a, b] } = Example();

Steps to Reproduce

  1. Create a circuit with a log statement containing a line break.
  2. Compile the circuit with the circom compiler:
    circom ./path/to/bug.circom --r1cs --wasm --sym --c -o ./target/compiled/
  3. Execute make:
    make -C ./target/compiled/bug_cpp/

Expected Behavior

Either the compiler should exit gracefully and provide a meaningful error message, or the log statement should be compiled without an error.

Actual Behavior

Error at step 2 (circom compiler):

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { inner: ErrorInner { text: Some(Text { line: 13027, col: 27, snippet: "(data (i32.const 6932) \"abc" }), file: None, span: Span { offset: 184746 }, kind: Lex(InvalidStringElement('\r')) } }', circom/src/compilation_user.rs:111:47
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Error at step 3 (make):

bug.cpp:84:8: warning: missing terminating " character
   84 | printf("abc
      |        ^
bug.cpp:84:8: error: missing terminating " character
   84 | printf("abc
      |        ^~~~
bug.cpp:85:4: warning: missing terminating " character
   85 | def");
      |    ^
bug.cpp:85:4: error: missing terminating " character
   85 | def");
      |    ^~~
bug.cpp: In function ‘void Example_0_run(uint, Circom_CalcWit*)’:
bug.cpp:85:1: error: ‘def’ was not declared in this scope
   85 | def");
      | ^~~
make: *** [Makefile:16: bug.o] Error 1

Environment

clararod9 commented 7 months ago

Hi!

Thank you for reporting this issue, we have solved it in the last commit. Now the compiler returns an error indicating that it received an unexpected token and the position of it:

error[P1012]: InvalidToken { location: 130 }
   ┌─ "prueba.circom":10:5
   │
10 │ log("abc
   │     ^ here

previous errors were found