Skip to content

Commit

Permalink
Add usage to README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
chmurka1 committed Aug 26, 2024
1 parent 2c0ddf6 commit 8f8a851
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ Here we rewrite a neural network to a form that makes it possible to produce zk-

So imagine there is a neural network that classifies images: looks at an image of a shopping bag and a receipt and verifies if the receipt matches the shopping bag. The neural network is public, the grocery store has shared it with clients and sets the rule: you can leave our store if the neural network allows. What we can now do with this library is to make ourselves a photo and then create a proof certifying that the neural network accepts our photo. We can share the proof with the grocery store, but keep our photo (and with it our shopping list) private.

The above example has an obvious problem (when did i make the photo?), but even more importantly - this solution is not at all enough efficient computationaly to make such usecase possible. Therefore this project should be treated more like a proof of concept - but with computational advancements and generalization to multi-party computations, this presents exciting possibilities.
The above example has an obvious problem (when did i make the photo?), but even more importantly -- this solution is not at all enough efficient computationally to make such use case possible. Therefore this project should be treated more like a proof of concept - but with computational advancements and generalization to multi-party computations, this presents exciting possibilities.

Here, either the weights or the inputs or any combination of the two can be made private/public.

### Demo

To see how it's used and how it works, check out the tests in [lib::test_trained_into_snark](https://github.com/przyjacielpkp/zkml/blob/main/lib/src/lib.rs#L76). Or run them with `cargo test --profile=test`. Tests take about a minute to run on my laptop.
The usage of the app consists of three steps:

These demonstrate the full functionality:
- a trained model is taken, that is a computation graph with the weight assignments (and some more bookeeping, we admit the abstraction is leaky here)
- the snark public key gets calculated
- prover provides the private argument and calculates the proof, together with evaluation of the circuit that is being claimed
- the evaluation when mapped back to float matches the evaluation of the original non-snark computation
- Use `zkml model` subcommand to train the model and save all necessary setup data to files. The exact description of all the arguments of this subcommand is available under `zkml model --help`,
- Use `zkml server` subcommand to run a verifying server. The server must have access to the files generated by `zkml model`.
- Use `zkml client` subcommand to run a prover. The prover must have access to the files generated by `zkml model` and a file with private input.

The client will communicate with the server to perform the proof of knowledge of the secret input it has access to.

### How does it work

Expand All @@ -41,12 +41,11 @@ The native model of computations which are possible to be made into a snark way

This means two things:

- Need to encode floats as prime field elements. This is done by scaling, for details see [[Note: floats as ints]](https://github.com/przyjacielpkp/zkml/blob/c678d410adc3de188ce439b94ad4b9edba7785cf/lib/src/snark/snark.rs#L124).
- Need to rewrite vectorized computations to significantly more scalar computions. This is done and described in [the scalar module](https://github.com/przyjacielpkp/zkml/blob/c678d410adc3de188ce439b94ad4b9edba7785cf/lib/src/scalar.rs#L131).
- Need to encode floats as prime field elements. This is done by scaling, for details see [[Note: floats as ints]](https://github.com/przyjacielpkp/zkml/blob/c678d410adc3de188ce439b94ad4b9edba7785cf/lib/src/snark/snark.rs#L124).
- Need to rewrite vectorized computations to significantly more scalar computions. This is done and described in [the scalar module](https://github.com/przyjacielpkp/zkml/blob/c678d410adc3de188ce439b94ad4b9edba7785cf/lib/src/scalar.rs#L131).

For a description of what we're dealing with initially as the input ml computation, see [[Note: graph representation]](https://github.com/przyjacielpkp/zkml/blob/c678d410adc3de188ce439b94ad4b9edba7785cf/lib/src/scalar.rs#L31). This is a general and simple representation, similar abstraction level to tinygrad, onnx, pytorch or tensorflow models map onto it (provided these're defined statically, see [pytorch docs](https://pytorch.org/tutorials/intermediate/torch_export_tutorial.html#graph-breaks)).


## Building

Build with cargo:
Expand Down Expand Up @@ -79,4 +78,4 @@ which can be installed systemwide, or provided in a developer shell by running `
rustflags = ["-Zlinker-features=-lld"]
```

in `.cargo/config.toml`.
in `.cargo/config.toml`.

0 comments on commit 8f8a851

Please sign in to comment.