Package: latticex.rosetta
OverviewRosetta is a privacy-preserving framework based onTensorFlow. It integrates with mainstream privacy-preserving computation technologies, including cryptography, federated learning and trusted execution environment. Rosetta aims to provide privacy-preserving solutions for artificial intelligence without requiring expertise in cryptography, federated learning and trusted execution environment. Rosetta reuses the APIs of TensorFlow and allows to transfer traditional TensorFlow codes into a privacy-preserving manner with minimal changes. E.g., just add the following line.importlatticex.rosettaThe current version integrates the secure multi-party computation protocols for 3 parties. The underlying protocol isSecureNN. It is secure in the semi-honest model with honest majority.InstallationFor now, Rosetta runs on Ubuntu 18.04, and is based on TensorFlow 1.14 with CPUs (Windows OS is not currently supported yet). You can install Rosetta as follows.First, please check that your local system meets our base environment requirement.Then install the native TensorFlow with the following codes. Note that you could also install it from source code.# install tensorflowpip3installtensorflow==1.14.0And then build and install Rosetta with our all-in-one script as follows.# clone rosetta git repositorygitclonehttps://github.com/LatticeX-Foundation/Rosetta.gitcdRosetta# compile, install and run test casesbashcompile_and_test_all.shBefore running your program, you should configure with your network topology so that a distributed network can be established for parties to communicate with each other.You could use an example to check everything runs OK. Please refer to Deployment Guide for the detailed steps of installation, configuration and deployment of Rosetta.UsageThe following is a toy example for matrix multiplication using Rosetta.In this example, we assume that three guys want to get the product of their private matrix, while do not want others to know what they hold. For brevity, we call them P0, P1 and P2.With Rosetta, each of them can run the following script, from which you can see that only a small amount of codes are needed besides the native TensorFlow lines.#!/usr/bin/env python3# Import rosetta packageimportlatticex.rosettaasrttimporttensorflowastf# You can activate a backend protocol, here we use SecureNNrtt.activate("SecureNN")# Get private data from every partymatrix_a=tf.Variable(rtt.private_console_input(0,shape=(3,2)))matrix_b=tf.Variable(rtt.private_console_input(1,shape=(2,1)))matrix_c=tf.Variable(rtt.private_console_input(2,shape=(1,4)))# Just use the native tf.matmul operation.cipher_result=tf.matmul(tf.matmul(matrix_a,matrix_b),matrix_c)# Start executionwithtf.Session()assess:sess.run(tf.global_variables_initializer())# Take a glance at the ciphertextcipher_result=sess.run(cipher_result)print('local ciphertext result:',cipher_result)# Set only party a and c can get plain resulta_and_c_can_get_plain=0b101# Get the result of Rosetta matmulprint('plaintext matmul result:',sess.run(rtt.SecureReveal(cipher_result,a_and_c_can_get_plain)))To run this jointly, after configuring networks, the three guys can run the following command-line respectively:pythonrosetta_demo.py--party_id=0,pythonrosetta_demo.py--party_id=1andpythonrosetta_demo.py--party_id=2Then each party will be prompted to input his private matrix, for example P0 may have:[2020-07-29 20:10:49.070] [info] Rosetta: Protocol [SecureNN] backend initialization succeeded!please input the private data (float or integer, 6 items, separated by space): 2 3 1 7 6 2Note that input from console like this is purely for pedagogical purpose in this toy example. See our Doc for production-ready data APIs.At the end, P0 and P2 will get the plaintext output while P1 dose not, just as required. Specifically, P0 and P2 may have:plaintext matmul result: [[b'8.000000' b'14.000000' b'18.000000' b'4.000000']
[b'4.000000' b'7.000000' b'9.000000' b'2.000000']
[b'24.000000' b'42.000000' b'54.000000' b'12.000000']][2020-07-29 20:11:06.452] [info] Rosetta: Protocol [SecureNN] backend has been released.while P1 has:plaintext matmul result: [[b'0.000000' b'0.000000' b'0.000000' b'0.000000']
[b'0.000000' b'0.000000' b'0.000000' b'0.000000']
[b'0.000000' b'0.000000' b'0.000000' b'0.000000']][2020-07-29 20:11:06.452] [info] Rosetta: Protocol [SecureNN] backend has been released.That's all, you can see Rosetta is so easy to use.For more details, please check Tutorials and Examples.Note: Currently Rosetta already supports 128-bit integer data type, which can be enabled by configuring the environment variableexport ROSETTA_MPC_128=ON.Getting StartedTo help you start with your first workable program with Rosetta easily, our Tutorials will lead you to this fantastic world. In this detailed tutorials, we will assist you learn the basic concepts about Rosetta, then show you how to use the interfaces that we provide by easy-to-understand examples, and finally help you build a workable privacy-preserving machine learning model on real-world datasets.Hopefully, this tutorial, and more other examples in Examples, will whet your appetite to dive in knowing more about this privacy-preserving framework.How Rosetta WorksRosetta works by extending and hacking both Python frontend and the Operation Kernels in backend of TensorFlow. It decouples the development of TensorFlow-related components and privacy technology so that both developers from AI and cryptography can focus on what they are interested.When running your Rosetta program, firstly the native TensorFlow data flow graph will be converted, and during this process the native Operations within the graph will be replaced with SecureOps.And at the second stage, the backend kernels of operations, implemented with specific cryptographic protocol, will be called to carry out underlying secure computation.Contributing to RosettaRosetta is an open source project developed under the LPGLv3 license and maintained byLatticeX Foundation. Contributions from individuals and organizations are all welcome. Before beginning, please take a look at our contributing guidelines. Our project adheres to code of conduct. By participating in our community, you are expected to uphold this code. You could also open an issue by clickinghere.ContactYou could reach us byemail.And you are welcome to join Rosetta community onSlackto ask any questions and discuss on any interesting topics with other developers.LicenseThe Rosetta library is licensed under the GNU Lesser General Public License v3.0.