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

Unnecessary condSelect in CompareAndSwap (for booleans) #334

Open
basitkhurram opened this issue Feb 12, 2019 · 0 comments
Open

Unnecessary condSelect in CompareAndSwap (for booleans) #334

basitkhurram opened this issue Feb 12, 2019 · 0 comments
Labels
Good beginner issue Type: Enhancement New functionality related issues.

Comments

@basitkhurram
Copy link
Contributor

Looks like CompareAndSwap requires three AND gates per bit of an input bitstring (i.e., if two bitstrings with m bits each are being compared and swapped, we would use 3m AND gates in total).

It should be possible to perform a "compare and swap" operation with only two AND gates per bit.

Looking at the following code, I think that there may be an unnecessary condSelect used here:

List<DRes<SBool>> first = left.stream()
.map(e -> {return par.advancedBinary().condSelect(data, e, right.get(left.indexOf(e)));})
.collect(Collectors.toList());
List<DRes<SBool>> second = right.stream()
.map(e -> {return par.advancedBinary().condSelect(data, e, left.get(right.indexOf(e)));})
.collect(Collectors.toList());

Instead, we could XOR the bits in right with the bits in left and then XOR this result with the bits from first:

List<DRes<SBool>> second = right.stream()
              .map(e -> {return par.binary().xor(e, par.binary().xor(left.get(right.indexOf(e)), first.get(right.indexOf(e))));})
              .collect(Collectors.toList());

However, this approach requires second to be computed after first has been computed, so we lose some parallelism.

A better solution would be to implement a condSwap gate and use such a gate in place of the condSelect gates.

A conditional swap gate takes in a selection bit and two other bits and then sets the order of these two bits depending on the value of the selection bit. A condSwap gate would be parallelizable. (See page 10 from "Improved Garbled Circuit: Free XOR Gates and Applications").

@jot2re jot2re added Type: Enhancement New functionality related issues. Good beginner issue labels Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good beginner issue Type: Enhancement New functionality related issues.
Projects
None yet
Development

No branches or pull requests

2 participants