#Unable to guard failed execution with conditional

5 messages · Page 1 of 1 (latest)

proud crater
#
        Circuit.if(
          UInt64.from(a).lessThan(UInt64.from(b)),
          UInt64.from(b).sub(UInt64.from(a)),
          UInt64.from(a).sub(UInt64.from(b))
        )

The compiler does not let this past even though the failed execution is guarded.

proud crater
#

Ok, fixed by pulling Field methods out of UInt64 then creating new UInt64 for return value

floral sequoia
#

Awesome that you were able to make this work!

Just a note on this:

The compiler does not let this past even though the failed execution is guarded.

It's important to get your mental model right about this. The JS you write as your circuit isn't compiled/transpiled. It's normal JS that is executed and creates the circuit by calling library functions like Circuit.if.
Since Circuit.if is a normal JS function, it can't be short-circuiting like a native if statement. All arguments are evaluated before calling the function (that's how function calls work)

proud crater
#

This may be a silly question, I guess it's not quite clear to me what the circuit is. Where does the proof system get involved and how does snarkjs talk to the proof system?

glad cosmos
#

snarkyjs essentially builds up an AST, turns it into R1CS, then puts that into Kimchi.
If you want to know what it "actually" looks like under the hood, look into PLONK and PLONKish arithmetisation systems.