How Does Peggy Prove To Victor The Banker That Her Salary is between $30K and $100K Without…

And the greatness of Python 3.8

Photo by Sahand Hoseini on Unsplash

How Does Peggy Prove To Victor The Banker That Her Salary is between $30K and $100K Without Revealing It?

And the greatness of Python 3.8

Python is wonderful, and it just keeps getting better. One of the new changes in Python 3.8 is the support for:

pow(a,b,p)

and where b can now be a negative number. This is a great advancement for crypto functions, as we often have to use the inverse mod function to perform a divide. With the new function, Python 3.8 does it all automatically, and so: [a/b] can now become [a * pow(b,-1,p)]. Magic! And so in this article, I’ll use this new function, and run the code in Python 3.8

Home on the range

There are many things in life ask if we have something that is in a certain range, such as for our age, our salary or even our weight. But when we answer the question we often have to give away the actual value. So how can we take our value, and show someone that the range is in a certain range? Well for this we can use range proofs.

So let’s say that Victor wants Peggy to prove that her salary is between $30K and $100K. We will now use the Damgard Fukisaki method to prove that Peggy’s salary is in a given range [here]:

First Victor and Peggy agree on two bases for their calculations (g and h) and a prime number (n). Victor then sends Peggy using a random number (r) as a challenge. Every positive value can be represented in the form:

For example:

Peggy now creates four commitments from these four values and takes four random numbers (r0, r1, r2 and r3).

And:

Victor then checks:

And this should be equal to:

Now to prove the range, we take (x-a) and (b-x) and which should be positive values. Next, we compute a commitment of:

and:

To prove the commitments we take:

and:

and they should be equal to:

Coding

You will see that there are divides involve in the method, and an inverse (r^-1). So we will use Python 3.8 and the pow() function to perform these [here]:

A sample run shows that we can prove that x=70 is between 20 and 100, but we cannot prove that it is between 71 and 75:

x= 70
a= 20
b= 100
r= 302939

b-x= 30
x-a= 50

Commit 1: 8192 1536 5184 341773
Commit 2: 16384 1 262145 170605
Prover 1: 441705
Prover 2: 441705
Prover 3: 441705
Peggy has proven that her value is between: 20 and 100

Prover 1: 347636
Prover 2: 342720
Prover 3: 441705
Peggy has NOT proven that her value is between: 71 and 75

In this way, Peggy can prove her value is in a given range.

Conclusion

Well, I’ve covered two things: the fantastic new pow() function in Python 3.8 and a range proof. Anyway, here’s my demo:

Range proofs can be used in a whole lot of applications, include within a cryptocurrency transaction, and where Peggy can prove to Victor that she has enough cryptocurrency to pay for a transaction, without revealing the amount of cryptocurrency she has.