keep-starknet-strange / raito

Bitcoin ZK client written in Cairo.
https://raito.wtf
MIT License
40 stars 34 forks source link

[feat] Custom Cairo runner #118

Open m-kus opened 2 months ago

m-kus commented 2 months ago

Currently we use Scarb cairo-run extension for running the light client program but it has several downsides:

Another option is cairo1-run (from cairo-vm) but it still does not solve (1).

A proposed solution is a custom Cairo runner that:

It should have a convenient CLI so that we can integrate it into the validation pipeline.

maciejka commented 2 months ago

I would postpone this one until we gain better understanding how the proving pipeline will look like. Saving Sierra to Casm compilation time does not look like a worthwhile goal.

maciejka commented 2 months ago
  • Pre-processes program arguments (converts JSON to T = Felt | Array<T>)
  • Optionally also queries data from RPC

Both should be facilitated by a script that will drive the client, rather in Python than in Rust.

m-kus commented 2 months ago

In general, cairo1-run should suffice, it can work with sierra output and generate all the artifacts necessary for proving. The only problem is that it's not packaged (and you cannot use cargo install either), we'd need to clone, build, and run cairo-vm locally which is not very convenient.

Just to note, custom runner is a very small program, e.g. see https://github.com/HerodotusDev/integrity/blob/main/runner/src/main.rs

maciejka commented 2 months ago

I prefer not to go custom route until it is strictly necessary. What would be simplest way to get cairo1-run available via cargo install? Clone the vm repo and publish it under the custom name?

m-kus commented 2 months ago

Maybe we can ask Lambda to add it to the [bin] section in Cargo.toml (which is probably the easiest option) or build binaries in CI (or ask some OD contributor to do that)

m-kus commented 2 months ago

Actually it worked without [[bin]] (contrary to https://doc.rust-lang.org/cargo/commands/cargo-install.html#description) cargo install --git https://github.com/lambdaclass/cairo-vm cairo1-run

m-kus commented 2 months ago

For some reason cairo1-run fails to compile the Sierra file produced by Scarb (and it also fails to compile the project because it does not support crates). I've upgraded cairo-lang-* dependencies but the problem seems to be somewhere else.

I'm moving on with Scarb runner for now, will investigate later.

m-kus commented 1 month ago

Another thing: we hit "Arguments list too long" in shell when running full client on large blocks (1MB), it seems that the workaround is to read args from file, Scarb does not support that, cairo1-run does.

m-kus commented 1 month ago

Additional considerations: