Replies: 3 comments 4 replies
-
Nice! Here's my take on ASM-like language vs JSON format:
It sounds to me like this ASM format is very simple to parse and integrate as well. Also, I'm sure the ASM format can be easily mapped to JSON and back. So it's like an optional readability / writability layer, and there's no strong reason against using this layer wherever it can be integrated. So, is there a good reason in favor of using the ASM-like language? I think yes! Snark circuits are a case where improved readability can make a huge difference. It can mean the difference between a broken protocol and a secure one. That's why I would advocate for using the ASM format in places that are meant for the human eye, to get a second view into a circuit, as a check on the DSL that's used to write the circuit. The snarky tests seem like a reasonable example of that. |
Beta Was this translation helpful? Give feedback.
-
Looks interesting for debugging. A JSON encoding would be interesting if we need to exchange data but at this point I don't see much value in it. On a more shallow point, regarding the syntax, since it's aimed at human consumption, I would remove the As of now, the |
Beta Was this translation helpful? Give feedback.
-
I think we should go this route, especially for the snarky tests. The tests that we'll use to check consistency between the rust and OCaml backends are not the place to smuggle in a new assembly language. On the proposal in particular, I don't like the syntax, but also would prefer that we don't spend time bikeshedding it. If there's a canonical, easy-to-manipulate representation, like JSON, it's easy for anyone -- internal or external -- to write a visualiser or equivalent language. I propose closing this discussion and backing out PR #831. |
Beta Was this translation helpful? Give feedback.
-
This RFC proposes a syntax that can be used to debug kimchi circuits
Not an intermediate representation (IR)
Currently we think about the snarky-kimchi stack as either:
at no point do we use an intermediate representation (IR). An IR would be interesting because:
I think there's some interesting developments with both VampIR (Anoma) and ACIR (Aztec Network) that we should investigate.
Anyway, this RFC is not about an IR! This RFC is about an assembly-like language (ASM) for Kimchi. In other words, for a human-readable encoding of kimchi gates.
Is it actually useful?
Low-level programmers need a way to reach out for the actual output produced by the circuits they write using a higher-level abstraction (like snarky), this is what ASM languages are for.
More generally, it seems like this could also be useful to users of snarkyjs to understand how code you write translates to kimchi gates, and how costly some of your lines of code can be. (Starknet has a cool product that allow users to submit gadgets and observe the computational efficiency of their solutions, it could be cool if we had something similar that would show you how some code translate to some kimchi gates.)
I've been successfully using such an ASM language for kimchi for my side project noname. In the repo, the folder examples/ contains circuits (in
.no
format) as well as their associated asm encoding of the compiled circuit (in.asm
format).Tests will compile every
.no
files, and check that they match their associated.asm
file. Not only did I caught a number of bugs by being able to read through the ASM-encoded circuit, but bugs can also be caught in PRs as you can clearly see how changes impact the compilation of existing circuits we have. For example zksecurity/noname@fd60e81The proposal
The ASM-language I use in noname looks like this:
It basically has 4 sections:
@ noname.0.7.0
)ci =
) that are too large to be displayed inlineGateName<coefficients>
)(row, col) -> (other_row, other_col)
)The encoding has been optimized essentially to what I found useful at the time when I was debugging.
I've iterated on this process and proposed something a bit different for kimchi in #831
The differences:
pub
keyword to the public rows, this is actually needed to differentiate different circuits with different public input size (and I need to fix this in noname)row0.
)row2.Generic<-1,0,0,1,0><-1,0,0,1,0>
)l1, r1, o1
, orl2, r2, o2
These changes were made so that I could read the tests I was writing for snarky more quickly (see MinaProtocol/mina#12125 and MinaProtocol/mina#12128)
Here's an example using the generic gate more heavily:
I don't necessarily think this is the prettiest language, again I did what was useful to me when I needed to look at the compiled version of my circuits to ensure that there were no bugs in the compilation.
Writing gadgets using the ASM-language
This proposal, so far, assumes that the ASM language won't be used directly to write gadgets or circuits. But is this something that we would potentially want to support? If so we'd have to think about specifying what are the input and output of the gadget. I don't think this would be too useful personally, but perhaps someone has a strong argument in favor of supporting this use case.
Support for custom gates
More problematic: how do we make the language work when users can add their own custom gates? Do we need to support a unique namespace for adding custom gates?
Downsides and alternatives
A criticism of this feature is that it will add some overhead to our work: as we extend kimchi we will need to continuously support this ASM language.
Another criticism is that people who want to make use of it in other languages will have to write their own encoder or parser (in the case we would want to support use cases for parsing these).
An alternative is to simply encode a circuit using a standard encoding like JSON.
More examples
For snarky examples, you can see https://github.com/MinaProtocol/mina/pull/12128/files which I took the following circuit from:
which translates to:
you can also check how I use it in noname: https://github.com/mimoo/noname/tree/main/examples
Beta Was this translation helpful? Give feedback.
All reactions