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

Add a protocol kwarg to encrypt() method to select between MPC and Paillier HE #3234

Merged
merged 14 commits into from
Mar 30, 2020

Conversation

Syzygianinfern0
Copy link
Member

@Syzygianinfern0 Syzygianinfern0 commented Mar 21, 2020

Fixes #3212

Modify .encrypt() to add a kwarg and be used not only for Paillier encryption but only MPC (default should be MPC, and it should call for mpc .fix_prec(...).share(...) under the hood)

@codecov
Copy link

codecov bot commented Mar 22, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@6357bb6). Click here to learn what that means.
The diff coverage is 97.82%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #3234   +/-   ##
=========================================
  Coverage          ?   94.54%           
=========================================
  Files             ?      146           
  Lines             ?    15920           
  Branches          ?        0           
=========================================
  Hits              ?    15052           
  Misses            ?      868           
  Partials          ?        0
Impacted Files Coverage Δ
test/torch/tensors/test_paillier.py 100% <100%> (ø)
test/torch/tensors/test_native.py 100% <100%> (ø)
...ft/frameworks/torch/tensors/interpreters/native.py 91.06% <93.75%> (ø)

@imskr
Copy link
Member

imskr commented Mar 22, 2020

Please always use other than your master branch for creating PR

Copy link
Contributor

@LaRiffle LaRiffle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean and thorough PR, congrats!
I've added some comments below :)

syft/frameworks/torch/tensors/interpreters/native.py Outdated Show resolved Hide resolved
syft/frameworks/torch/tensors/interpreters/native.py Outdated Show resolved Hide resolved
syft/frameworks/torch/tensors/interpreters/native.py Outdated Show resolved Hide resolved
syft/frameworks/torch/tensors/interpreters/native.py Outdated Show resolved Hide resolved
syft/frameworks/torch/tensors/interpreters/native.py Outdated Show resolved Hide resolved
test/torch/tensors/test_native.py Outdated Show resolved Hide resolved

x = torch.randint(10, (1, 5), dtype=torch.float32)
x_encrypted = x.encrypt(workers=[bob, alice], crypto_provider=james, args_fix_prec={"base": 10})
assert torch.all(torch.eq(x_encrypted.get().float_prec(), x))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh we've forgotten to add a generic decrypt method!!
Would you be willing to do also this one? :)
for MPC .decrypt() would call .get().float_prec()
and for paillier, it would'nt change

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Do I submit it in another PR?
I've incorporated the suggestions mentioned.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this PR would be more coherent if you can do it !

@karlhigley karlhigley changed the title Enhance encryption API Add a protocol kwarg to encrypt() method to select between MPC and Paillier HE Mar 27, 2020
Copy link
Contributor

@LaRiffle LaRiffle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last question and this is good for me!

"""

if protocol.lower() == "mpc":
x_encrypted = self.copy()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need copy() here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LaRiffle It served a purpose of not making it an inplace operation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see
Ok I got your point, let's keep it your way

@Jasopaum Jasopaum merged commit 8f0a559 into OpenMined:master Mar 30, 2020
@Syzygianinfern0 Syzygianinfern0 deleted the master branch April 1, 2020 05:11
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

Successfully merging this pull request may close these issues.

Enhance encryption API
5 participants