Chapter 1: Fibonacci and Chiquito Concepts

The best learning is by doing, In this Part, we will walk through the fibonacci.py example.

Chapter 1: Fibonacci and Chiquito Concepts#

The Fibonacci series is an infinite series, starting from “1” and “1”, in which every number in the series is the sum of two numbers preceding it in the series. The first few rounds for the Fibonacci series are:

  • 1 + 1 = 2

  • 1 + 2 = 3

  • 2 + 3 = 5

  • 3 + 5 = 8

Therefore, to express these mathematical equations, we need three variables “a”, “b”, and “c”, which we call “signals” in Chiquito. Because zero knowledge proofs typically express mathematical equations in the matrix form, we construct the following table:

Signals

a

b

c

1

1

2

1

2

3

2

3

5

3

5

8

Besides assigning values to these signals, we also need to define the mathematical relationships among them, which we call “constraints” in Chiquito. For each row:

  • a + b == c

  • b = a in the next row

  • c = b in the next row

Signals

Setups

a

b

c

constraint 1

constraint 2

constraint 3

1

1

2

a + b == c

b == a.next

c == b.next

1

2

3

a + b == c

b == a.next

c == b.next

2

3

5

a + b == c

b == a.next

c == b.next

3

5

8

a + b == c

b == a.next

c == b.next

Chiquito is a step-based language for constructing zero knowledge circuits, which means that instead of expressing all signals and constraints above as one entirety, we separate them into smaller chunks, called “step instances”. In this example, each row, together with its signals and constraints, are collectively called a “step instance”. We add indices for these step instances to the table, starting from 0:

Step Instance Index

Signals

Setups

a

b

c

constraint 1

constraint 2

constraint 3

0

1

1

2

a + b == c

b == a.next

c == b.next

1

1

2

3

a + b == c

b == a.next

c == b.next

2

2

3

5

a + b == c

b == a.next

c == b.next

3

3

5

8

a + b == c

b == a.next

c == b.next

Note that these 4 step instances share the same signals and constraints, although not the same value assignments for signals. They are essentially different instantiations of the same signals and constraints, or different “step instances” of the same “step type”. In Chiquito, we define signals and constraints in “step types” and we generate “witness assignments” for signal values. “Step types” with “witness assignments” become “step instances”. In the example above, we have 4 step instances but only 1 step type, defined as the same 3 signals and 3 constraints. For simplicity, we call this single step type “fibo step”, also added to the table below:

Step Type

Step Instance Index

Signals

Setups

a

b

c

constraint 1

constraint 2

constraint 3

fibo step

0

1

1

2

a + b == c

b == a.next

c == b.next

fibo step

1

1

2

3

a + b == c

b == a.next

c == b.next

fibo step

2

2

3

5

a + b == c

b == a.next

c == b.next

fibo step

3

3

5

8

a + b == c

b == a.next

c == b.next

As a recap, to construct a Fibonacci circuit, we need three signals-“a”, “b”, and “c”. In Chiquito, “circuit” is a set of constraints that signals of the circuit need to satisfy. Each Chiquito circuit is composed of multiple “step instances”, which are instantiations of “step types”. Each “step type” contains a subset of signals and constraints that these signals need to satisfy.