Writing a simple circuit
This tutorial describes how to create a simple circuit containing one multiplication operation.
The C++ examples in this tutorial and across the rest of the documentation use types and algorithms from the crypto3
library.
The Rust examples use types from the arkworks-rs
project.
Multiplication example
Any circuit is a series of polynomials that, in the case of high-level programming languages, can be expressed as a function.
For zkLLVM to correctly recognize a function as a circuit, it needs to be preceded by the following directive.
- C++
- Rust
[[circuit]]
#[circuit]
A simple example of a circuit with one multiplication operator would look as follows.
- C++
- Rust
[[circuit]] int multiplication_example(
int a,
int b) {
auto c = a*b;
return c;
}
#[circuit]
pub fn multiplication_example(a: i32, b: i32) -> i32 {
let c = a * b;
c
}
Note that clang
presently does not support std::string
and several other types from std
.
The function takes two variables, multiplies them, and returns the result. With no additional code needed, it is a fully-fledged circuit.
Only one function in a project can be preceded by the [[circuit]]
/#[circuit]
annotation.