This tutorial explains the steps necessary to run the program on OlaVM, generate ZK(zero-knowledge) proof and verify.
There are some resources about OlaVM. The developers should learn the concepts and demonstrates to grasp the designs of OlaVM.
- Hello, OlaVM!
- Ola - A ZKVM-based, High-performance, and Privacy-focused Layer2 platform
- Unveiling OlaVM Proof of Concept: The Next-Generation Full-Featured zkVM
- Edit the program: Ola supports writing on vscode, we have developed an extension to vscode to support ola syntax highlighting, and we will continue to improve the plugin in the future. The extension can be found on the Visual Studio Marketplace.
- Compile the program: Ola lang is a ZK compiler. It can compile the program to assembly, refer to ola-lang.md.
- Run the program: Ola client is a OlaVM implementation. It can encode the assembly file to executive file and run. then generate trace file for constructing ZK proof. refer to olavm-execute.md.
- Generate ZK proof: OlaVM execution results and all intermediate processes are recorded during execution and saved as json, including CPU execution trace table, Memory trace table, Range Check trace table, Bitwise trace table and comparison trace table. You can open these json files directly for a simple view, or you can convert it to an excel file for further analysis with the tools we provide. Generating proof can take some time, depending on the size of the trace you are generating.
- Verify ZK proof: Congratulations you have successfully generated the proof, now you only need to execute one command to verify it.
Beginner Workshop: implement the Fibonacci algorithm with loop and recursive two versions.
Advanced Workshop: implement the sqrt algorithm with Newton's method and prophet two versions.
Helpful Resources:
- tool chain: contains tool chain of Ola lang and Ola client.
- source code: contains the source code of above two workshops.
- Ola lang: the github repository of Ola lang.
- OlaVM: the github repository of OlaVM, now is the PoC(Proof of concept) version.
In the paragraph, we guide the developer through the implementation of the loop Fibonacci algorithm.
At first, the developer should use an editor(recommend Visual Studio Marketplace) to develop the Fibonacci algorithm code(refer to below) and save to file fibo_loop.ola.
contract Fibonacci {
fn main() {
fib_loop(10);
}
fn fib_loop(u32 n) -> (u32) {
if (n == 0) {
return 0;
}
u32 first = 0;
u32 second = 1;
u32 third = 1;
for (u32 i = 2; i <= n; i++) {
third = first + second;
first = second;
second = third;
}
return third;
}
}
In this step, the developer should compile the code to the JSON format executable file. Using below tool:
compile code to assembly file fibo_loop.asm:
./olac compile fibo_loop_asm.ola --gen asm
The developer uses ola client command asm to encode code to executable file fibo_loop_exe.json:
./ola asm -i fibo_loop.asm -o fibo_loop_exe.json
The developer uses ola client command run to run executable file fibo_loop_exe.json and generate trace file fibo_loop_trace.json.
./ola run -i fibo_loop_exe.json -o fibo_loop_trace.json
The developer uses ola client command prove to generate ZK proof.
./ola prove -i fibo_loop_trace.json -o fibo_loop_proof
Finally,The developer uses ola client command verify to verify ZK proof. If verification is passed, the client should print "Verify succeed!".
./ola verify -i fibo_loop_proof
Algorithm | Machine core | Machine Memory | OS type | Execution time | Proving time | Trace size |
---|---|---|---|---|---|---|
1000 times sqrt(prophet) | Apple M1 Pro (10 threads) | 32 GB | macosx | 58 ms | 11.8 s | 18 MB |
1000 times sqrt(Newton's method) | Apple M1 Pro (10 threads) | 32 GB | macosx | 4441 ms | 163 s | 681 MB |
Twitter: https://twitter.com/Sin7y_Labs
Discord: http://discord.gg/vDFy7YEG6j
Email: contact@sin7y.org