zksecurity / noname

Noname: a programming language to write zkapps
https://zksecurity.github.io/noname/
193 stars 50 forks source link

Support kimchi and string type in debugger API #219

Open katat opened 2 weeks ago

katat commented 2 weeks ago

The recent addition allows printing out variable values via log(var) builtin function.

However, it only supports the R1CS backend atm. Also, because noname doesn't support the string type variable yet, the log stdlib can't take a string argument to customize the message per logging output.

It would be very nice to have the following enhancements:

  1. Implement the log_var function for the kimchi backend. For reference, please check how the logging is implemented in R1CS backend.

  2. Support parsing strings in native code, so a customized logging message can be passed to the logging function. At this stage, we may just implement a builtin string type (read only) in order to pass to the log function. Later, we can extend this string type to be able to encoded in the circuit.

mimoo commented 2 weeks ago

I think being able to write log("this is a {var} and this is another {var2}"); like in javascript would be cool

a third feature request would be to make it work with any types (array, structs, etc.) not just field types

cwkang1998 commented 2 weeks ago

Would like to try this, although I might need some guidance.

Can I try taking this?

mimoo commented 1 week ago

correct me if I'm wrong @katat but a first PR could just add support for string literals in the lexer/parser logic, so you can write things like let some_string = "some string!";

katat commented 1 week ago

correct me if I'm wrong @katat but a first PR could just add support for string literals in the lexer/parser logic, so you can write things like let some_string = "some string!";

It would also need to encode the string literal, so they can be passed around. I think it can be similar to how the literal boolean and ints are encoded.

https://github.com/zksecurity/noname/blob/34162a764b2eaac14520fd0a2176d570b7a1465f/src/circuit_writer/writer.rs#L680-L697

For both ints and booleans, they are represented by a single field. For string literals, they could be represented by an array of fields, each of which represent an ASCII code (a character of a string).

katat commented 1 week ago

Sounds good! @cwkang1998