# Inner product argument

## What is an inner product argument?

The inner product argument is the following construction: given the commitments (for now let’s say the hash) of two vectors $a$ and $b$ of size $n$ and with entries in some field $F$, prove that their inner product $⟨a,b⟩$ is equal to $z$.

There exist different variants of this inner product argument. In some versions, none of the values ($a$, $b$ and $z$) are given, only commitments. In some other version, which is interesting to us and that I will explain here, only $a$ is unknown.

## How is that useful?

Inner products arguments are useful for several things, but what we’re using them for in Mina is polynomial commitments. The rest of this post won’t make too much sense if you don’t know what a polynomial commitment is, but briefly: it allows you to commit to a polynomial $f$ and then later prove its evaluation at some point $s$. Check my post on Kate polynomial commitments for more on polynomial commitment schemes.

How does that translate to the inner product argument though? First, let’s see our polynomial $f$ as a vector of coefficients:

$f =(f_{0},⋯,f_{n})such thatf(x)=f_{0}+f_{1}x+f_{2}x_{2}+⋯+f_{n}x_{n}$

Then notice that

$f(s)=⟨f ,(1,s,s_{2},⋯,s_{n})⟩$

And here’s our inner product again.

## The idea behind Bootleproof-type of inner product argument

The inner product argument protocol I’m about to explain was invented by Bootle et al. It was later optimized in the Bulletproof paper (hence why we unofficially call the first paper bootleproof), and then some more in the Halo paper. It’s the later optimization that I’ll explain here.

### A naive approach

So before I get into the weeds, what’s the high-level? Well first, what’s a naive way to prove that we know the pre-image of a hash $h$, the vector $a$, such that $⟨a,b⟩=z$? We could just reveal $a$ and let anyone verify that indeed, hashing it gives out $h$, and that it also verifies the equation $⟨a,b⟩=z$.

$ ⟨a,b⟩=zgivenb,z, and a hash ofa open proof a $

Obliviously, we have to reveal $a$ itself, which is not great. **But we’ll deal with that later, trust me**. What we want to tackle first here is the proof size, which is the size of the vector $a$. Can we do better?

### Reducing the problem to a smaller problem to prove

The inner product argument reduces the opening proof by using an intermediate reduction proof:

$ ⟨a,b⟩=zgivenb,z, and a hash ofa reduction proof ⟨a_{′},b_{′}⟩=z_{′}givenb_{′},z_{′}, and a hash ofa_{′} open proof a_{′} $

Where the size of $a_{′}$ is half the size of $a$, and as such the final opening proof ($a_{′}$) is half the size of our naive approach.

The reduction proof is where most of the magic happens, and this reduction can be applied many times ($log_{2}(n)$ times to be exact) to get a final opening proof of size 1. Of course the entire proof is not just the final opening proof of size 1, but all the elements involved in the reduction proofs. It can still be much smaller than the original proof of size $n$.

So most of the proof size comes from the multiple reduction subproofs that you’ll end up creating on the way. **Our proof is really a collection of miniproofs or subproofs.**

## One last thing before we get started: Pedersen hashing and commitments

To understand the protocol, you need to understand commitments. I’ve used hashing so far, but hashing with a hash function like SHA-3 is not great as it has no convenient mathematical structure. We need algebraic commitments, which will allow us to prove things on the committed value without revealing the value committed. Usually what we want is some homomorphic property that will allow us to either add commitments together or/and multiply them together.

For now, let’s see a simple non-hiding commitment: a Pedersen hash. To commit to a single value $x$ simply compute:

$xG$

where the discrete logarithm of $G$ is unknown. To open the commitment, simply reveal the value $x$.

We can also perform multi-commitments with Pedersen hashing. For a vector of values $(x_{1},⋯,x_{k})$, compute:

$x_{1}G_{1}+⋯+x_{k}G_{k}$

where each $G_{i}$ is distinct and has an unknown discrete logarithm as well. I’ll often shorten the last formula as the inner product $⟨x,G⟩$ for $x=(x_{1},⋯,x_{k})$ and $G=(G_{1},⋯,G_{k})$. To reveal a commitment, simply reveal the values $x_{i}$.

Pedersen hashing allow commitents that are non-hiding, but binding, as you can’t open them to a different value than the originally comitted one. And as you can see, adding the commitment of $x$ and $y$ gives us the commitment of $x+y$:

$xG+yG=(x+y)G$

which will be handy in our inner product argument protocol

## The protocol

### Set up

Here are the settings of our protocol. Known only to the prover, is the secret vector

$a=(a_{1},a_{2},a_{3},a_{4})$

The rest is known to both:

- $G=(G_{1},G_{2},G_{3},G_{4})$, a basis for Pedersen hashing
- $A=⟨a,G⟩$, the commitment of $a$
- $b=(b_{1},b_{2},b_{3},b_{4})$, the powers of some value $s$ such that $b=(1,s,s_{2},s_{3})$
- the result of the inner product $z=⟨a,b⟩$

For the sake of simplicity, let’s pretend that this is our problem, and we just want to halve the size of our secret vector $a$ before revealing it. As such, we will only perform a single round of reduction. But you can also think of this step as being already the reduction of another problem twice as large.

We can picture the protocol as follows:

- The prover first sends a commitment to the polynomial $f$.
- The verifier sends a point $s$, asking for the value $f(s)$. To help the prover perform a proof of correct evaluation, they also send a random challenge $x$. (NOTE: The verifier sends the random challenge $x$ ONLY AFTER they receive the $z=f(s)$)
- The prover sends the result of the evaluation, $z$, as well as a proof.

Does that make sense? Of course what’s interesting to us is the proof, and how the prover uses that random $x$.

### Reduced problem

First, the prover cuts everything in half. Then they use $x$ to construct linear combinations of these cuts:

- $a_{′}=x_{−1}(a_{1}a_{2} )+x(a_{3}a_{4} )$
- $b_{′}=x(b_{1}b_{2} )+x_{−1}(b_{3}b_{4} )$
- $G_{′}=x(G_{1}G_{2} )+x_{−1}(G_{3}G_{4} )$

This is how the problem is reduced to $⟨a_{′},b_{′}⟩=z_{′}$.

At this point, the prover can send $a_{′}$, $b_{′}$, and $z_{′}$ and the verifier can check if indeed $⟨a_{′},b_{′}⟩=z_{′}$. But that wouldn’t make much sense would it? Here we also want:

- a proof that proving that statement is the same as proving the previous statement ($⟨a,b⟩=z$)
- a way for the verifier to compute $z_{′}$ and $b_{′}$ and $A_{′}$ (the new commitment) by themselves.

### The actual proof

The verifier can compute $b_{′}$ as they have everything they need to do so.

What about $A_{′}$, the commitment of $a_{′}$ which uses the new $G_{′}$ basis. It should be the following value:

$A_{′}==== ⟨a_{′},G_{′}⟩(x_{−1}a_{1}+xa_{3})(xG_{1}+x_{−1}G_{3})+(x_{−1}a_{2}+xa_{4})(xG_{2}+x_{−1}G_{4})A+x_{−2}(a_{1}G_{3}+a_{2}G_{4})+x_{2}(a_{3}G_{1}+a_{4}G_{2})A+x_{−2}L_{a}+x_{2}R_{a} $

So to compute this new commitment, the verifier needs:

- the previous commitment $A$, which they already have
- some powers of $x$, which they can compute
- two curve points $L_{a}$ and $R_{a}$, which the prover will have to provide to them

What about $z_{′}$? Recall:

- $a_{′}=(x_{−1}a_{1}+xa_{3}x_{−1}a_{2}+xa_{4} )$
- $b_{′}=(xb_{1}+x_{−1}b_{3}xb_{2}+x_{−1}b_{4} )$

So the new inner product should be:

$z_{′}==== ⟨a_{′},b_{′}⟩⟨(x_{−1}a_{1}+xa_{3}x_{−1}a_{2}+xa_{4} ),(xb_{1}+x_{−1}b_{3}xb_{2}+x_{−1}b_{4} )⟩(a_{1}b_{1}+a_{2}b_{2}+a_{3}b_{3}+a_{4}b_{4})+x_{−2}(a_{1}b_{3}+a_{2}b_{4})+x_{2}(a_{3}b_{1}+a_{4}b_{2})z+x_{−2}(L_{z})+x_{2}(R_{z}) $

Similarly to $A_{′}$, the verifier can recompute $z_{′}$ from the previous value $z$ and two scalar values $L_{z}$ and $R_{z}$ which the prover needs to provide.

So in the end, the proof has become:

- the vector $a_{′}$ which is half the size of $a$
- the $L_{a},R_{a}$ curve points (around two field elements, if compressed)
- the $L_{z},R_{z}$ scalar values

We can update our previous diagram:

In our example, the naive proof was to reveal $a$ which was 4 field elements. We are now revealing instead 2 + 2 + 2 = 6 field elements. This is not great, but if $a$ was much larger (let’s say 128), the reduction in half would still be of 64 + 2 + 2 = 68 field elements. Not bad no? We can do better though…

### The HALO optimization

The HALO optimization is similar to the bulletproof optimization, but it further reduces the size of our proof, so I’ll explain that directly.

With the HALO optimization, the prover translates the problem into the following:

$C=A+zU=⟨a,G⟩+⟨a,b⟩U$

This is simply a commitment of $a$ and $z$.

A naive proof is to reveal $a$ and let the verifier check that it is a valid opening of the following commitment. Then, that commitment will be reduced recursively to commitments of the same form.

$C_{′}=A_{′}+z_{′}U=⟨a_{′},G_{′}⟩+⟨a_{′},b_{′}⟩U$

The whole point is that the reduction proofs will be smaller than our previous bootleproof-inspired protocol.

How does the reduction proof work? Notice that this is the new commitment:

$C_{′}== ⟨a_{′},G_{′}⟩+⟨a_{′},b_{′}⟩U[A+x_{−2}L_{a}+x_{2}R_{a}]+[z+x_{−2}(L_{z})+x_{2}(R_{z})]U $

This is simply from copy/pasting the equations from the previous section. This can be further reduced to:

$C_{′}=C+x_{−2}(L_{a}+L_{z}U)+x_{2}(R_{a}+R_{z}U)$

And now you see that the verifier now only needs, in addition to $a_{′}$, two curve points (~ 2 field elements):

- $L=L_{a}+L_{z}U$
- $R=R_{a}+R_{z}U$

this is in contrast to the 4 field elements per reduction needed without this optimization. Much better right?

At the end of a round (or the protocol) the verifier can compute the expected commitment $C_{′}$ as such:

$C_{′}=C+x_{−2}L+x_{2}R$

and open it by computing the following and checking it is indeed equal to $C_{′}$:

$⟨a_{′},G_{′}⟩+⟨a_{′},b_{′}⟩U$

For this, the verifier needs to recompute $G_{′}$ and $b_{′}$ by themselves, which they can as they have all the necessary information. We can update our previous diagram:

### What about zero-knowledge?

Didn’t we forget something? Oh right, we’re sending $a_{′}$ in clear, a single element that will leak some information about the original vector $a$ (as it is a linear combination of that original vector).

The simple solution is to alter our pedersen commitment to make it hiding on top of being binding:

$C=A+zU+rH=⟨a,G⟩+⟨a,b⟩U+rH$

where H is another generator we don’t know the discrete logarithm of, and $r$ is a random scalar value generated by the prover to blind the commitment.

But wait, each $L$ and $R$ also leaks some! As they are also made from the original secret vector $a$. Remember, $L=L_{a}+L_{z}U$ No worries, we can perform the same treatment on that curve point and blind it like so:

- $L=L_{a}+L_{z}U+r_{L}H$
- $R=R_{a}+R_{z}U+r_{R}H$

In order to open the final commitment, the verifier first recomputes the expected commitment as before:

$C_{′}=C+x_{−2}L+x_{2}R$

then use $a_{′}$ and the final blinding value $r_{′}$ sent by the prover (and composed of $r$ and all the rounds’ $r_{L}$ and $r_{R}$), as well as reconstructed $G_{′}$ and $b_{′}$ to open the commitment:

$⟨a_{′},G_{′}⟩+⟨a_{′},b_{′}⟩U+r_{′}H$

with $r_{′}$ being equal to something like $r+∑_{i}(r_{Li}+r_{Ri})$

At this point, the protocol requires the sender to send:

- 2 curve points $L$ and $R$ per rounds
- 1 scalar value $a_{′}$ for the final opening
- 1 blinding (scalar) value $r_{′}$ for the final opening

But wait… one last thing. In this protocol the prover is revealing $a_{′}$, and even if they were not, by revealing $r_{′}$ they might allow someone to recompute $a_{′}$… The HALO paper contains a generalized Schnorr protocol to open the commitment without revealing $a_{′}$ nor $r_{′}$.

from Vanishree:

- So in general the more data we send the more randomness we need to ensure the private aspects are hidden, right
- The randomness in a
*commitment*is because we are sending the commitment elements - The random elements
*mixed with the polynomial*(in the new zkpm technique) is because we send evaluations of the polynomial at zeta and zeta omega later - Zk in
*Schnorr opening*is because we reveal the opening values

where can I find a proof? perhaps appendix C of https://eprint.iacr.org/2017/1066.pdf

### The real protocol, and a note on non-interactivity

Finally, we can look at what the real protocol end up looking at with $log_{2}(n)$ rounds of reduction followed by a commitment opening.

So far the protocol was interactive, but you can make it non-interactive by simply using the Fiat-Shamir transformation. That’s all I’ll say about that.