# Yao's Millionaires' Problem

(Redirected from Millionaire's Problem)

Yao's Millionaires' problem is a secure multi-party computation problem which was introduced in 1982 by Andrew Yao, a prominent computer scientist and computational theorist. The problem discusses two millionaires, Alice and Bob, who are interested in knowing which of them is richer without revealing their actual wealth.

This problem is analogous to a more general problem where there are two numbers ${\displaystyle a}$ and ${\displaystyle b}$ and the goal is to solve the inequality ${\displaystyle a\geq b}$ without revealing the actual values of ${\displaystyle a}$ and ${\displaystyle b}$.

The Millionaires' Problem is an important problem in cryptography, the solution of which is used in e-commerce and data mining. Commercial applications sometimes have to compare numbers which are confidential and whose security is important.

Many solutions have been introduced for the problem, among which the first solution, presented by Yao himself,[1] was exponential in time and space. This article presents and explains one possible solution.[2]

## Protocol and proof

### The protocol

We will make use of a variant of oblivious transfer, called 1-2 oblivious transfer, in our protocol. In that transfer one bit is transferred in the following way: a sender has two bits ${\displaystyle S_{0}}$ and ${\displaystyle S_{1}}$. The receiver chooses ${\displaystyle i\in \{0,1\}}$ and the sender sends ${\displaystyle S_{i}}$ with the oblivious transfer protocol such that

1. the receiver doesn't get any information about ${\displaystyle S_{(1-i)}}$,
2. the value of ${\displaystyle i}$ is not exposed to the sender.

Now we will begin with the protocol description. We will indicate Alice's number as ${\displaystyle a}$ and Bob's number as ${\displaystyle b}$ and assume that the length of their binary representation is less than ${\displaystyle d}$ for some ${\displaystyle d\in N}$. The steps of the protocol are as follows.

1. Alice creates a matrix ${\displaystyle K}$ of size ${\displaystyle d\times 2}$ of ${\displaystyle k}$-bit numbers, where ${\displaystyle k}$ is the length of the key in the oblivious transfer protocol. In addition, she chooses two random numbers ${\displaystyle u}$ and ${\displaystyle v}$ where ${\displaystyle 0\leq u<2k}$ and ${\displaystyle v\leq k}$.
2. ${\displaystyle K_{ijl}}$ will be the ${\displaystyle l}$-th bit of the number which appears in cell ${\displaystyle K_{ij}}$ (where ${\displaystyle l=0}$ indicates the least significant bit). In addition, we denote ${\displaystyle a_{i}}$ as the ${\displaystyle i}$-th bit of Alice's number ${\displaystyle a}$. For every ${\displaystyle i}$, ${\displaystyle 1\leq i\leq d}$ Alice does the following actions.
1. For every bit ${\displaystyle j\geq v}$ she sets ${\displaystyle K_{i1j}}$ and ${\displaystyle K_{i2j}}$ to random bits.
2. If ${\displaystyle a_{i}=1}$ let ${\displaystyle l=1}$ otherwise let ${\displaystyle l=2}$ and for every ${\displaystyle j,0\leq j\leq 2\cdot i-1}$ set ${\displaystyle K_{ilj}}$ to a random bit.
3. For ${\displaystyle m=2\cdot i}$ set ${\displaystyle K_{il(m+1)}=1}$ and ${\displaystyle K_{ilm}}$ to ${\displaystyle a_{i}}$.
4. For every ${\displaystyle i,1\leq i, ${\displaystyle S_{i}}$ will be a random ${\displaystyle k}$-bit number and ${\displaystyle S_{d}}$ will be another number of ${\displaystyle k}$ bits where all bits except the last two are random and the last two are calculated as ${\displaystyle S_{d(k-1)}=1\oplus \bigoplus _{j=1}^{d-1}S_{j(k-1)}\oplus \bigoplus _{j=1}^{d}K_{j1(k-1)}}$ and ${\displaystyle S_{d(k-2)}=1\oplus \bigoplus _{j=1}^{d-1}S_{j(k-2)}\oplus \bigoplus _{j=1}^{d}K_{j1(k-2)}}$, where ${\displaystyle \bigoplus }$ is the bitwise XOR operation.
5. For ${\displaystyle l=1,2}$ set ${\displaystyle K'_{ij}=rot(K_{il}\oplus S_{i},u)}$. Where ${\displaystyle rot(x,t)}$ indicates the bitwise rotation of ${\displaystyle x}$ to the left by ${\displaystyle t}$ bits.
3. For every ${\displaystyle i}$, ${\displaystyle 0\leq i\leq d}$ Bob transfers ${\displaystyle K'_{il}}$ with the oblivious transfer protocol where ${\displaystyle l=b_{i}+1}$ and ${\displaystyle b_{i}}$ is the ${\displaystyle i}$-th bit of ${\displaystyle b}$.
4. Alice sends to Bob ${\displaystyle N=rot(\bigoplus _{j=1}^{d}S_{j},u)}$.
5. Bob calculates the bitwise XOR of all the numbers he got in step 3 and ${\displaystyle N}$ from step 4. Bob scans the result from left to right until he finds a large sequence of zero bits. Let ${\displaystyle c}$ be the bit to the right of that sequence (${\displaystyle c}$ is non zero). If the bit to the right of ${\displaystyle c}$ equals 1 then ${\displaystyle a\geq b}$. otherwise ${\displaystyle a.

### Proof

#### Correctness

Bob calculates the final result from ${\displaystyle N\oplus \bigoplus _{i=1}^{d}K'_{i(b_{i}+1)}=rol(\bigoplus _{i=1}^{d}K_{i(b_{i}+1)},u)}$ and the result depends on ${\displaystyle c=\bigoplus _{i=1}^{d}K_{i(b_{i}+1)}}$. K and therefore c as well, can be split into 3 parts. The left part doesn't affect the result. The right part has all the important information and in the middle there is a sequence of zeros what separate those two parts. The length of each partition of c is linked to the security scheme.

For every i, only one of ${\displaystyle K_{i1},K_{i2}}$ has non zero right part and it is ${\displaystyle K_{i1}}$ if ${\displaystyle a_{i}=1}$ and ${\displaystyle K_{i2}}$ otherwise. In addition, if ${\displaystyle i>j}$ and ${\displaystyle K_{il}}$ has a non zero right part then ${\displaystyle K_{il}\oplus K_{jl}}$ has also a non zero right part and the two leftmost bits of this right part will be the same as the one of ${\displaystyle A_{il}}$. As a result, the right part of c is a function of the entries Bob transferred correspond to the unique bits in a and b and the only bits in the right part in c which are not random are the two leftmost, Exactly the bits which determines the result of ${\displaystyle a_{i}>b_{i}}$ where i is the highest order bit in which a and b differ. In the end, if ${\displaystyle a_{i}>b_{i}}$ then those two leftmost bits will be 11 and Bob will answer that ${\displaystyle a\geq b}$. If the bits are 10 then ${\displaystyle a_{i} and he will answer a<b. If a=b then there will be no right part in c and in this case the two leftmost bits in c will be 11 and will indicate the result.

#### Security

The information Bob sends to Alice is secure because it is sent through oblivious transfer which is secure.

Bob gets 3 numbers from Alice,

1. ${\displaystyle rol(K_{i(1+b_{i})}\oplus S_{i},u)}$ for every ${\displaystyle i}$ Bob receives one such number and ${\displaystyle S_{i}}$ is random so no secure information is transformed,
2. N, This is an XOR of random numbers and therefore reveals no information. The relevant information is revealed only after calculating c and,
3. c, The same goes for c. The left part of c is random and the right part is random as well except from the two leftmost bits. Deducing any information from those bits requires guessing some other values and the chance of guessing them correct is very low.

### Complexity

The complexity of the protocol is ${\displaystyle O(d^{2})}$. Alice constructs d length number for each bit of a and Bob calculates XOR d times of d length numbers. The complexity of those operations is ${\displaystyle O(d^{2})}$. The communication part takes also ${\displaystyle O(d^{2})}$. Therefore, the complexity of the protocol is ${\displaystyle O(d^{2}).}$