facebookresearch / CrypTen

A framework for Privacy Preserving Machine Learning
MIT License
1.52k stars 274 forks source link

Could you please tell me the difference between MPCTensor and CrypTensor #392

Closed YZY010203 closed 2 years ago

lvdmaaten commented 2 years ago

CrypTensor is a generic tensor class that implements things like automatic differentiation, but it does not implement the actual secure computation protocol. In particular, it contains a set of abstract functions that any subclass of CrypTensor should implement using some (secure) computation protocol.

MPCTensor is a subclass of CrypTensor that implements these abstract functions using a particular secure MPC protocol (as described in the CrypTen paper).

Note that this design allows a user to implement their own secure computation protocol in their own code (without having to make any changes in CrypTen). Specifically, you could implement your own homomorphic encryption tensor as a subclass of CrypTensor. If you register that subclass into CrypTen, you inherit a lot of goodies from CrypTen: in particular, a wide variety of functions (you only implement addition, multiplication, and comparison), automatic differentiation on those function, and the neural network library.

hobbitlzy commented 1 year ago

Hi, I read the source code of Crypten and find it is quite elegant. But I have a question when I look into the details of MPC functions of MPCTensor. I find there is another class ArithmeticSharedTensor actually does things, and MPCTensor simply calls the methods of ArithmeticSharedTensor. The MPCTensor seems like a intermediate class between Crypten and ArithmeticSharedTensor. If I have ArithmeticSharedTensor to do everything about MPC protocols, why the existence of MPCTensor?

lvdmaaten commented 1 year ago

The MPCTensor uses ArithmeticSharedTensor to evaluate all linear functions but comparators are implemented in BinarySharedTensor, which uses a different type of secret sharing (namely, binary secret sharing). The MPCTensor transforms the secret-shared tensor between arithmetic and binary sharing as needed.

hobbitlzy commented 1 year ago

Understand! Thanks for your reply.

mialuyao commented 1 month ago

The MPCTensor uses ArithmeticSharedTensor to evaluate all linear functions but comparators are implemented in BinarySharedTensor, which uses a different type of secret sharing (namely, binary secret sharing). The MPCTensor transforms the secret-shared tensor between arithmetic and binary sharing as needed.

Thanks for your reply. I find when using MPCTensor, the type of share is MPCTensor rather than ArithmeticSharedTensor or BinarySharedTensor. This results in a failure when attempting to conduct XOR/AND on two shares,with the error message unsupported operand type(s) for ^: 'MPCTensor' and 'MPCTensor'. I would like to understand the reason for this issue. Thanks!