Hash Function Example
To illustrate how to use components, we will create two components where the main component calls a hash function component. For simplicity, instead of an actual hash function, the second component will compute from an input . This component will have, in total, three columns: [input, intermediate, output], which will correspond to the values . Our main component, on the other hand, will have two columns, [input, output], which corresponds to the values . We’ll refer to the main component as the scheduling component and the hash function component as the computing component, since the main component is essentially scheduling the hash function component to run its function with a given input and the hash function component computes on the provided input. As can be seen in Figure 1, the input and output of each component are connected by lookups.Figure 1: Scheduling and Computing components
Design
Figure 2: Traces of each component
When we implement this in S-two, the traces of each component will look like Figure 2 above. Each component has its own original and LogUp traces, and the inputs and outputs of each component are connected by lookups. Since the scheduling component sets the LogUp value as a positive multiplicity and the computing component sets the same value as a negative multiplicity, the verifier can simply check that the sum of the two LogUp columns is zero. Note that we combine the input and output randomly as
to form a single lookup. This is because we want to ensure that each input is paired with the correct output. If we add the input and output as separate lookups as
A malicious prover can switch the output with a different row and still come up with a valid proof. For example, the following scheduling component
And the following computing component
would be valid.
Implementation
Let’s move on to the implementation.ComponentsStatement0, ComponentsStatement1, Components, and ComponentsProof, but the main logic is the same.
Let’s take a closer look at how the LogUp columns are generated.