🚧#8 Circom: Other Reference Circuits
- EscalarProduct - Decoder - Multiplexer
Last updated
Was this helpful?
- EscalarProduct - Decoder - Multiplexer
Last updated
Was this helpful?
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 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
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 1
success 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.
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.
Multiplex lets us select the element in the place of index = 2, which is 23.
Takes in an input of nested arrays, and lets us return the nested array of index value 'sel'
Example