🚧#8 Circom: Other Reference Circuits
- EscalarProduct - Decoder - Multiplexer
EscalarProduct
Verifies the inner/scalar product of two provided arrays

Like in1[w] . in2[w] === out
.

aux[n]
collects the pairwise multiplication of elements in both input arrays.lc
is a collector var, which basically returns the sum of elements in aux array.
out
is constrained and assigned to lc
, therefore, the circuit verifies that the sum of pairwise multiplication - inner product - of 2 arrays is correct.
Decoder
Decoder creates a mask based on the supplied index and size of array. Creates a mask of some array of defined size, by zero-ing out all other elements except the index we specified as inp
value

Decoder(3)
input: inp = 1
output: [0,1,0]
Creates a mask [0,1,0] that can be overlaid on an array of 3 elements to extract the 2nd element. Decoder returns array out:[0,1,0] and success: 1.
Returns a bitmask where the 1 is in the position of inp, if inp is less than w.
if inp == i, assign 1 into out[i]; else assign 0.
constraint out[i] to be either 0 or
inp == i
.
lc sums all the elements of
out
. sum should be either 0 or 1success is constrained to be either 0 or 1.
Therefore, lc should have a max value of 1.
This means out
is essentially the binary representation of some figure [0,0,1,0], where there can only be a single 1.
If success/lc is 0, the implication is that inp is larger than the array, since i never takes its value.
decoder() returns a bitmask where the 1 is at the inp; if inp is less than w.
If the index we were looking for was 4, in the same array:
Consider the array [1,2,3]
Decoder(3)
input: inp = 4
output: [0,0,0] and success = 0
since the input array only goes to index 2.
Multiplexer
Let's reduce this to 1 dimension first
Multiplexer allows us to retrieve the value/element of a specified array.
Given an array inp[], return the element in said array for a specified selector.
If we input [13,19,23,29] and set sel = 2, we will obtain out as 23.
This is the element at index = 2.

input: inp = [13,19,23,29] and sel = 2
mask: [0,0,1,0]
dot product: [0,0,1,0] . [13,19,23,29] = 23
output: out = 23, success = 1
Multiplex lets us select the element in the place of index = 2, which is 23.
2-D Multiplex

Takes in an input of nested arrays, and lets us return the nested array of index value 'sel'
Example
// nested arrays
[
[1,2,3,1],
[3,4,5,2],
[6,7,8,3]
]
Multiplex(3, 4):
sel = 2
out returns us [6,7,8,3]
Last updated
Was this helpful?