Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using binary secret sharing for comparison? #494

Open
Poppy22 opened this issue Nov 5, 2023 · 4 comments
Open

Using binary secret sharing for comparison? #494

Poppy22 opened this issue Nov 5, 2023 · 4 comments

Comments

@Poppy22
Copy link

Poppy22 commented Nov 5, 2023

Hello,

From what I understood, binary secret sharing should be used for logical operations, such as comparisons, as this would be faster.

Given the code below, which simply compares two numbers x and y using both binary secret sharing, I receive an error:

@mpc.run_multiprocess(world_size=3)
def compare_two_numbers(x_input, y_input):
    x = crypten.cryptensor(x_input, ptype=crypten.mpc.binary)
    y = crypten.cryptensor(y_input, ptype=crypten.mpc.binary)

    r = (x < y)
    crypten.print(f"Source {0} [binary] result: {r.get_plain_text()}")

The error is: AttributeError: 'BinarySharedTensor' object has no attribute 'sub'

How should binary secret sharing be used for comparisons? It seems that only arithmetic secret sharing is working. What am I missing?

@kwmaeng91
Copy link

There is no way to do comparison using arithmetic secret sharing from my understanding. It must be already being converted to binary, if it works with arithmetic secret sharing.

@mialuyao
Copy link

There is no way to do comparison using arithmetic secret sharing from my understanding. It must be already being converted to binary, if it works with arithmetic secret sharing.

Hello

In paper crypten crypten, that say:

we can produce [x < y] by computing their difference [z]= [x]-[y] and comparing result to zero: [z <0]. We compute [z <0] by first converting [z] to a binary secret-share , computing its sign bit, and converting the resulting bit to an arithmetic sharing [b].

I observe functions gt, ge, le in MPC/primitives. So, how should we call functions when we need to compare two numbers.

Thank you!

@kwmaeng91
Copy link

If you use a comparison operator for arithmetic secret sharing (e.g., a < b?), it internally subtracts the value and compare it with zero (a - b < 0?), which involves arithmetic operation (a-b), and then comparison. It first does the arithmetic operation and then convert to binary secret sharing, and perform comparison with zero, and convert the result back to arithmetic secret sharing.

So, to answer your question:

  1. You should compare two numbers in an arithmetic secret shared format, not binary. CrypTen internally converts it to binary when needed.

@mialuyao
Copy link

If you use a comparison operator for arithmetic secret sharing (e.g., a < b?), it internally subtracts the value and compare it with zero (a - b < 0?), which involves arithmetic operation (a-b), and then comparison. It first does the arithmetic operation and then convert to binary secret sharing, and perform comparison with zero, and convert the result back to arithmetic secret sharing.

So, to answer your question:

  1. You should compare two numbers in an arithmetic secret shared format, not binary. CrypTen internally converts it to binary when needed.

I got it. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants