### 19 breaking releases

new 0.20.0 | Jul 18, 2024 |
---|---|

0.18.0 | May 10, 2024 |

0.17.0 | Mar 4, 2024 |

0.16.0 | Oct 10, 2023 |

0.5.0 | Nov 5, 2021 |

#**626** in Cryptography

**247** downloads per month

Used in **11** crates
(10 directly)

**Apache-2.0**

205KB

4.5K
SLoC

# Schnorr's proof of knowledge

Schnorr protocol to prove knowledge of 1 or more discrete logs in zero knowledge. Refer this for more details of Schnorr protocol.

Also implements the proof of knowledge of discrete log in pairing groups, i.e. given prover and verifier
both know (

, `A1`

), and prover additionally knows `Y1`

, prove that `B1`

. Similarly,
proving `e``(``A1``,` `B1``)` `=` `Y1`

when only prover knows `e``(``A2``,` `B2``)` `=` `Y2`

but both know (`A2`

, `B2`

). See `Y2`

.`discrete_log_pairing`

Also implements the proof of **inequality of discrete log** (a value committed in a Pedersen commitment),
either with a public value or with another discrete log in

. eg. Given a message `Inequality`

,
its commitment `m`

and a public value `C = g * m + h * r`

`v`

, proving that `m`

≠ `v`

. Or given 2 messages
`m1`

and `m2`

and their commitments `C1` `=` g `*` m1 `+` h `*` r1

and `C2` `=` g `*` m2 `+` h `*` r2

, proving `m1`

≠ `m2`

Also implements the proof of **inequality of discrete log** when only one of the discrete log is known to
the prover. i.e. given

and `y = g * x`

`z ``=` h `*` k

, prover and verifier know `g`

, `h`

, `y`

and `z`

and
prover additionally knows `x`

but not `k`

.Also impelements partial Schnorr proof where response for some witnesses is not generated. This is useful when several Schnorr protocols are executed together and they share some witnesses. The response for those witnesses will be generated in one Schnorr proof while the other protocols will generate partial Schnorr proofs where responses for those witnesses will be missing.

We outline the steps of Schnorr protocol.
Prover wants to prove knowledge of

in `x`

(`y = g * x`

`y`

and `g`

are public knowledge)
**Step 1**: Prover generates randomness

`r`

, and sends `t ``=` g `*` r

to Verifier.
**Step 2**: Verifier generates random challenge

`c`

and send to Prover.
**Step 3**: Prover produces

`s ``=` r `+` x`*`c

, and sends s to Verifier.
**Step 4**: Verifier checks that

`g ``*` s `=` `(`y `*` c`)` `+` t

.For proving knowledge of multiple messages like

and `x_1`

in `x_2`

:
`y = g_1*x_1 + g_2*x_2`

**Step 1**: Prover generates randomness

`r_1`

and `r_2`

, and sends `t ``=` g_1`*`r_1 `+` g_2`*`r_2

to Verifier
**Step 2**: Verifier generates random challenge

`c`

and send to Prover
**Step 3**: Prover produces

`s_1 ``=` r_1 `+` x_1`*`c

and `s_2 ``=` r_2 `+` x_2`*`c

, and sends `s_1`

and `s_2`

to Verifier
**Step 4**: Verifier checks that

`g_1``*`s_1 `+` g_2`*`s_2 `=` y`*`c `+` t

Above can be generalized to more than 2

s`x`

There is another variant of Schnorr which gives shorter proof but is not implemented:

- Prover creates

and then`r`

.`T``=`r`*`G - Prover computes challenge as

.`c``=`Hash`(`G`||`Y`||`T`)` - Prover creates response

and sends`s``=`r`+`c`*`x

and`c`

to the Verifier as proof.`s` - Verifier creates

as`T``'`

and computes`T``'``=`s`*`G`-`c`*`Y

as`c``'``c``'``=`Hash`(`G`||`Y`||`T`'``)` - Proof if valid if
`c``==`c`'`

The problem with this variant is that it leads to poorer failure reporting as in case of failure, it can't be
pointed out which relation failed to verify. Eg. say there are 2 relations being proven which leads to 2

s `T`

and `T1`

and 2 responses `T2`

and `s1`

. If only the responses and challenge are sent then
in case of failure, the verifier will only know that its computed challenge `s2`

doesn't match prover's given
challenge `c '`

`c`

but won't know which response `s1`

or `s2`

or both were incorrect. This is not the case
with the implemented variant as verifier checks 2 equations `s1 ``=` r1 `+` x1`*`c

and `s2 ``=` r2 `+` x2`*`c

#### Dependencies

~7–18MB

~207K SLoC