Skip to main content

Writing a simple circuit

This tutorial describes how to create a simple circuit containing one multiplication operation.

tip

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.

[[circuit]]

A simple example of a circuit with one multiplication operator would look as follows.


[[circuit]] int multiplication_example(
int a,
int b) {
auto c = a*b;
return c;
}

Using standard types in 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.

warning

Only one function in a project can be preceded by the [[circuit]]/#[circuit] annotation.