-
Notifications
You must be signed in to change notification settings - Fork 116
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
Make debugging / logging variables in a circuit less error-prone #489
Comments
I think such a wrapper would also work well: function log(...args: any[]) {
Circuit.asProver(() => {
console.log(...args.map((x) => x.toString()));
});
} calling it like this: snarky.log('field', Field.zero, 'bool', Bool(true), 'uint', new UInt64(2)); should result in
It would allow developers to log values intuitively with the same syntax they are used from Another option would be exposing a dedicated log function on the const myField = Field(5);
myField.log("the value of my field is:");
> the value of my field is: 5 |
I like the simplicity of your I wonder whether the innermost function should not be |
The json representation makes sense, I know people also like logging values like this: console.log({a,b})
> { a: 1, b: 2 } I feel like this would work great with the json parsing |
I'm adding |
|
Todo: Propose something with reasoning |
Is there any other reason to convert a provable value to a string except for logging? |
@gretzke yes, serializing for IO, & in general process it as a normal JS value outside the circuit. It's used all the time, it's just not supposed to be used in circuits |
@bkase I propose to not change this for now, but instead change the error message to something that explains the matter very well, and to revisit this when we work on separating constants and variables. The reasoning is that the constant-variable separation could mean we can keep a nice API, so it feels premature to introduce that ugly / dangerous-sounding API in the meantime |
feedback by @gretzke
Paraphrasing:
field.toString()
/.toJSON()
because they aren't allowed inside circuitsdebug
/log
function which abstracts this awayfield.debug(x => console.log(x))
, wherex
is a stringdebug(log => { log(field); log(bool) })
which logs variables in a nice formatThe text was updated successfully, but these errors were encountered: