From e0b1a8f739b38fd406da13224d0e1d9946bbdc0d Mon Sep 17 00:00:00 2001 From: Chester Leung Date: Wed, 16 Dec 2020 00:56:03 +0000 Subject: [PATCH 1/9] Take out last for loop and push into other for loop --- server/enclave/CMakeLists.txt | 1 + server/enclave/ecalls.cpp | 2 +- server/tests/host_test.cpp | 43 ++++++++++++++++++++++++++--------- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/server/enclave/CMakeLists.txt b/server/enclave/CMakeLists.txt index 25faabb..3cd00ef 100644 --- a/server/enclave/CMakeLists.txt +++ b/server/enclave/CMakeLists.txt @@ -18,6 +18,7 @@ target_compile_options(enclave -fno-strict-aliasing -D_GLIBCXX_USE_CXX11_ABI=0 -ftls-model=local-exec + -march=native ) set_target_properties(enclave PROPERTIES diff --git a/server/enclave/ecalls.cpp b/server/enclave/ecalls.cpp index 01d5ee8..583ec8b 100644 --- a/server/enclave/ecalls.cpp +++ b/server/enclave/ecalls.cpp @@ -141,7 +141,7 @@ void enclave_modelaggregator(int tid) { float n_iter = acc_params["_contribution"][0]; iters_sum += n_iter; - // Multiply the weights by local iterations. + // Multiple the weights by local iterations. vector& weights = acc_params[v_name]; if (updated_params_at_var.size() != weights.size()) { std::cout << "Error! Unequal sizes" << std::endl; diff --git a/server/tests/host_test.cpp b/server/tests/host_test.cpp index 07cf2a1..bc31df1 100644 --- a/server/tests/host_test.cpp +++ b/server/tests/host_test.cpp @@ -10,20 +10,29 @@ #include "encryption/serialization.h" #include "utils.h" #include "flatbuffers/model_generated.h" +#include using namespace std; int main(int argc, char* argv[]) { - size_t accumulator_length = 3; + const size_t accumulator_length = 3; + size_t num_weights = 6000; + size_t weights_length = 100; + uint8_t*** encrypted_accumulator = new uint8_t**[accumulator_length * sizeof(uint8_t**)]; size_t* accumulator_lengths = new size_t[accumulator_length * sizeof(size_t)]; for (int i = 0; i < accumulator_length; i++) { - map> accumulator = {{"w1", {i, i + 1, i + 2, i + 3}}, - {"w2", {i + 1, i + 2, i + 3, i + 4}}, - {"w3", {i + 2, i + 3, i + 4, i + 5}}, - {"_contribution", {1}}}; + map> accumulator = {{"_contribution", {1}}}; + for (int j = 0; j < num_weights; j++) { + vector weights; + for (int k = 0; k < weights_length; k++) { + weights.push_back(i + j + k); + } + accumulator.insert(make_pair("w" + to_string(j), weights)); + } + int serialized_buffer_size = 0; uint8_t* serialized_params = serialize(accumulator, &serialized_buffer_size); @@ -36,9 +45,14 @@ int main(int argc, char* argv[]) accumulator_lengths[i] = serialized_buffer_size; } - map> old_params = {{"w1", {-3, -6, -9, -12}}, - {"w2", {-6, -9, -12, -15}}, - {"w3", {-9, -12, -15, -18}}}; + map> old_params; + for (int j = 0; j < num_weights; j++) { + vector weights; + for (int k = 0; k < weights_length; k++) { + weights.push_back(-(1 + j + k) * (int) accumulator_length); + } + old_params.insert(make_pair("w" + to_string(j), weights)); + } int serialized_old_params_buffer_size = 0; uint8_t* serialized_old_params = serialize(old_params, &serialized_old_params_buffer_size); @@ -62,6 +76,7 @@ int main(int argc, char* argv[]) } size_t* new_params_length = new size_t; + const clock_t begin_time = clock(); int error = host_modelaggregator(encrypted_accumulator, accumulator_lengths, accumulator_length, @@ -69,7 +84,9 @@ int main(int argc, char* argv[]) serialized_old_params_buffer_size, encrypted_new_params_ptr, new_params_length); + cout << "Time for host_modelaggregator to run: " << double(clock() - begin_time) / CLOCKS_PER_SEC << "s" << endl; + /* // Free memory for (int i = 0; i < accumulator_length; i++) { delete encrypted_accumulator[i][0]; @@ -85,6 +102,7 @@ int main(int argc, char* argv[]) if (error > 0) { return error; } + */ uint8_t** encrypted_new_params = *encrypted_new_params_ptr; uint8_t* serialized_new_params = new uint8_t[*new_params_length * sizeof(uint8_t)]; @@ -94,6 +112,7 @@ int main(int argc, char* argv[]) *new_params_length, &serialized_new_params); + /* // Free memory for (int i = 0; i < accumulator_length; i++) { delete encrypted_new_params_ptr[i][0]; @@ -101,11 +120,12 @@ int main(int argc, char* argv[]) delete encrypted_new_params_ptr[i][2]; delete encrypted_new_params_ptr[i]; } + */ - map> new_params = deserialize(serialized_new_params); + map> new_params = deserialize(serialized_new_params); for (const auto& pair : new_params) { - if (pair.second.size() != 4) { + if (pair.second.size() != weights_length) { return 1; } for (float x : pair.second) { @@ -115,5 +135,6 @@ int main(int argc, char* argv[]) } } - return 0; + cout << "Before failing on purpose" << endl; + return 1; } From 0d33d549ef77b35026a20e971a106f0f1719011b Mon Sep 17 00:00:00 2001 From: Chester Leung Date: Wed, 16 Dec 2020 21:11:36 +0000 Subject: [PATCH 2/9] Significant speedup --- server/enclave/ecalls.cpp | 2 +- server/tests/host_test.cpp | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/server/enclave/ecalls.cpp b/server/enclave/ecalls.cpp index 583ec8b..01d5ee8 100644 --- a/server/enclave/ecalls.cpp +++ b/server/enclave/ecalls.cpp @@ -141,7 +141,7 @@ void enclave_modelaggregator(int tid) { float n_iter = acc_params["_contribution"][0]; iters_sum += n_iter; - // Multiple the weights by local iterations. + // Multiply the weights by local iterations. vector& weights = acc_params[v_name]; if (updated_params_at_var.size() != weights.size()) { std::cout << "Error! Unequal sizes" << std::endl; diff --git a/server/tests/host_test.cpp b/server/tests/host_test.cpp index bc31df1..d5a56cb 100644 --- a/server/tests/host_test.cpp +++ b/server/tests/host_test.cpp @@ -76,7 +76,7 @@ int main(int argc, char* argv[]) } size_t* new_params_length = new size_t; - const clock_t begin_time = clock(); + // const clock_t begin_time = clock(); int error = host_modelaggregator(encrypted_accumulator, accumulator_lengths, accumulator_length, @@ -84,7 +84,7 @@ int main(int argc, char* argv[]) serialized_old_params_buffer_size, encrypted_new_params_ptr, new_params_length); - cout << "Time for host_modelaggregator to run: " << double(clock() - begin_time) / CLOCKS_PER_SEC << "s" << endl; + // cout << "Time for host_modelaggregator to run: " << double(clock() - begin_time) / CLOCKS_PER_SEC << "s" << endl; /* // Free memory @@ -112,6 +112,8 @@ int main(int argc, char* argv[]) *new_params_length, &serialized_new_params); + cout << "Decrypted bytes" << endl; + /* // Free memory for (int i = 0; i < accumulator_length; i++) { @@ -123,13 +125,17 @@ int main(int argc, char* argv[]) */ map> new_params = deserialize(serialized_new_params); + cout << "Deserialized bytes" << endl; for (const auto& pair : new_params) { if (pair.second.size() != weights_length) { + cout << "weights length note equal " << endl; return 1; } for (float x : pair.second) { if (x != 0) { + cout << "x is " << x << endl; + cout << "x != 0" << endl; return 1; } } From fe1e62c80ba53bc78d6376f9eee709b8dc2c81b2 Mon Sep 17 00:00:00 2001 From: Chester Leung Date: Wed, 16 Dec 2020 21:30:26 +0000 Subject: [PATCH 3/9] Revert unchanged files --- server/enclave/CMakeLists.txt | 1 - server/host/host.cpp | 2 +- server/tests/host_test.cpp | 50 +++++++++-------------------------- 3 files changed, 14 insertions(+), 39 deletions(-) diff --git a/server/enclave/CMakeLists.txt b/server/enclave/CMakeLists.txt index 3cd00ef..25faabb 100644 --- a/server/enclave/CMakeLists.txt +++ b/server/enclave/CMakeLists.txt @@ -18,7 +18,6 @@ target_compile_options(enclave -fno-strict-aliasing -D_GLIBCXX_USE_CXX11_ABI=0 -ftls-model=local-exec - -march=native ) set_target_properties(enclave PROPERTIES diff --git a/server/host/host.cpp b/server/host/host.cpp index e76495d..e68ff4b 100644 --- a/server/host/host.cpp +++ b/server/host/host.cpp @@ -17,7 +17,7 @@ char* g_path = "./enclave/enclave.signed"; uint32_t g_flags = 0; // Cannot be larger than NumTCS in modelaggregator.conf -static const int NUM_THREADS = 1; +static const int NUM_THREADS = 3; // This is the function that the Python code will call into. // Returns 0 on success. diff --git a/server/tests/host_test.cpp b/server/tests/host_test.cpp index d5a56cb..0992dae 100644 --- a/server/tests/host_test.cpp +++ b/server/tests/host_test.cpp @@ -10,29 +10,20 @@ #include "encryption/serialization.h" #include "utils.h" #include "flatbuffers/model_generated.h" -#include using namespace std; int main(int argc, char* argv[]) { - const size_t accumulator_length = 3; - size_t num_weights = 6000; - size_t weights_length = 100; - + size_t accumulator_length = 3; uint8_t*** encrypted_accumulator = new uint8_t**[accumulator_length * sizeof(uint8_t**)]; size_t* accumulator_lengths = new size_t[accumulator_length * sizeof(size_t)]; for (int i = 0; i < accumulator_length; i++) { - map> accumulator = {{"_contribution", {1}}}; - for (int j = 0; j < num_weights; j++) { - vector weights; - for (int k = 0; k < weights_length; k++) { - weights.push_back(i + j + k); - } - accumulator.insert(make_pair("w" + to_string(j), weights)); - } - + map> accumulator = {{"w1", {i, i + 1, i + 2, i + 3}}, + {"w2", {i + 1, i + 2, i + 3, i + 4}}, + {"w3", {i + 2, i + 3, i + 4, i + 5}}, + {"_contribution", {1}}}; int serialized_buffer_size = 0; uint8_t* serialized_params = serialize(accumulator, &serialized_buffer_size); @@ -45,14 +36,9 @@ int main(int argc, char* argv[]) accumulator_lengths[i] = serialized_buffer_size; } - map> old_params; - for (int j = 0; j < num_weights; j++) { - vector weights; - for (int k = 0; k < weights_length; k++) { - weights.push_back(-(1 + j + k) * (int) accumulator_length); - } - old_params.insert(make_pair("w" + to_string(j), weights)); - } + map> old_params = {{"w1", {-3, -6, -9, -12}}, + {"w2", {-6, -9, -12, -15}}, + {"w3", {-9, -12, -15, -18}}}; int serialized_old_params_buffer_size = 0; uint8_t* serialized_old_params = serialize(old_params, &serialized_old_params_buffer_size); @@ -76,7 +62,6 @@ int main(int argc, char* argv[]) } size_t* new_params_length = new size_t; - // const clock_t begin_time = clock(); int error = host_modelaggregator(encrypted_accumulator, accumulator_lengths, accumulator_length, @@ -84,9 +69,7 @@ int main(int argc, char* argv[]) serialized_old_params_buffer_size, encrypted_new_params_ptr, new_params_length); - // cout << "Time for host_modelaggregator to run: " << double(clock() - begin_time) / CLOCKS_PER_SEC << "s" << endl; - /* // Free memory for (int i = 0; i < accumulator_length; i++) { delete encrypted_accumulator[i][0]; @@ -102,7 +85,6 @@ int main(int argc, char* argv[]) if (error > 0) { return error; } - */ uint8_t** encrypted_new_params = *encrypted_new_params_ptr; uint8_t* serialized_new_params = new uint8_t[*new_params_length * sizeof(uint8_t)]; @@ -112,9 +94,6 @@ int main(int argc, char* argv[]) *new_params_length, &serialized_new_params); - cout << "Decrypted bytes" << endl; - - /* // Free memory for (int i = 0; i < accumulator_length; i++) { delete encrypted_new_params_ptr[i][0]; @@ -122,25 +101,22 @@ int main(int argc, char* argv[]) delete encrypted_new_params_ptr[i][2]; delete encrypted_new_params_ptr[i]; } - */ - map> new_params = deserialize(serialized_new_params); - cout << "Deserialized bytes" << endl; + map> new_params = deserialize(serialized_new_params); for (const auto& pair : new_params) { - if (pair.second.size() != weights_length) { - cout << "weights length note equal " << endl; + if (pair.second.size() != 4) { return 1; } for (float x : pair.second) { if (x != 0) { - cout << "x is " << x << endl; - cout << "x != 0" << endl; return 1; } } } + std::cout << "Right before returning error on purpose" << std::endl; - cout << "Before failing on purpose" << endl; return 1; + + // return 0; } From 36c77531ef06af0fb12ba3736716462fc6842940 Mon Sep 17 00:00:00 2001 From: Chester Leung Date: Wed, 16 Dec 2020 21:31:07 +0000 Subject: [PATCH 4/9] Revert host test --- server/tests/host_test.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/server/tests/host_test.cpp b/server/tests/host_test.cpp index 0992dae..07cf2a1 100644 --- a/server/tests/host_test.cpp +++ b/server/tests/host_test.cpp @@ -114,9 +114,6 @@ int main(int argc, char* argv[]) } } } - std::cout << "Right before returning error on purpose" << std::endl; - return 1; - - // return 0; + return 0; } From f4c59715f73111b5b9b511741cbed0c531fce6d9 Mon Sep 17 00:00:00 2001 From: Octavian Sima Date: Fri, 18 Dec 2020 12:42:38 -0800 Subject: [PATCH 5/9] converted doubles to floats in host_test.cpp --- server/CMakeLists.txt | 2 +- server/host/host.cpp | 4 ++-- server/tests/host_test.cpp | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 3cb9603..1ed01a6 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -3,7 +3,7 @@ project(modelaggregator LANGUAGES CXX C VERSION 1.00) include(CTest) -include_directories(../common /snap/flatbuffers/current/include) +include_directories(../common /snap/flatbuffers/include) if (LVI_MITIGATION MATCHES ControlFlow) # Configure the cmake to use customized compilation toolchain. diff --git a/server/host/host.cpp b/server/host/host.cpp index e68ff4b..7a9b1ff 100644 --- a/server/host/host.cpp +++ b/server/host/host.cpp @@ -13,8 +13,8 @@ using namespace std; char* g_path = "./enclave/enclave.signed"; // Comment in the below if you want to run in debug / simulation mode -// uint32_t g_flags = OE_ENCLAVE_FLAG_DEBUG | OE_ENCLAVE_FLAG_SIMULATE; -uint32_t g_flags = 0; +uint32_t g_flags = OE_ENCLAVE_FLAG_DEBUG | OE_ENCLAVE_FLAG_SIMULATE; +// uint32_t g_flags = 0; // Cannot be larger than NumTCS in modelaggregator.conf static const int NUM_THREADS = 3; diff --git a/server/tests/host_test.cpp b/server/tests/host_test.cpp index 07cf2a1..bb333f3 100644 --- a/server/tests/host_test.cpp +++ b/server/tests/host_test.cpp @@ -20,7 +20,7 @@ int main(int argc, char* argv[]) size_t* accumulator_lengths = new size_t[accumulator_length * sizeof(size_t)]; for (int i = 0; i < accumulator_length; i++) { - map> accumulator = {{"w1", {i, i + 1, i + 2, i + 3}}, + map> accumulator = {{"w1", {i, i + 1, i + 2, i + 3}}, {"w2", {i + 1, i + 2, i + 3, i + 4}}, {"w3", {i + 2, i + 3, i + 4, i + 5}}, {"_contribution", {1}}}; @@ -36,7 +36,7 @@ int main(int argc, char* argv[]) accumulator_lengths[i] = serialized_buffer_size; } - map> old_params = {{"w1", {-3, -6, -9, -12}}, + map> old_params = {{"w1", {-3, -6, -9, -12}}, {"w2", {-6, -9, -12, -15}}, {"w3", {-9, -12, -15, -18}}}; int serialized_old_params_buffer_size = 0; @@ -102,7 +102,7 @@ int main(int argc, char* argv[]) delete encrypted_new_params_ptr[i]; } - map> new_params = deserialize(serialized_new_params); + map> new_params = deserialize(serialized_new_params); for (const auto& pair : new_params) { if (pair.second.size() != 4) { From b7ace08b87d2d915b27aaed41102d12cbd880599 Mon Sep 17 00:00:00 2001 From: Octavian Sima Date: Fri, 18 Dec 2020 13:20:17 -0800 Subject: [PATCH 6/9] consolidated simulation and debugging flags --- server/README.md | 8 ++++++-- server/enclave/CMakeLists.txt | 3 --- server/host/CMakeLists.txt | 7 +++++++ server/host/host.cpp | 13 +++++++++---- server/tests/host_test.cpp | 4 ++-- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/server/README.md b/server/README.md index fa58132..0db1beb 100644 --- a/server/README.md +++ b/server/README.md @@ -3,6 +3,12 @@ ## About This folder contains all the necessary files to build and run a simple model aggregator in an enclave environment. The aggregator takes the element-wise sum of the variables received from multiple clients, weighs them by local iterations, then adds them to the existing model. All sensitive computation is done in an enclave environment, with encryption/decryption being performed inside. + +## Additional Flags +If you would like to build in debugging mode (extra logs of enclave behavior available), set the `OE_DEBUG` environment variable: `export OE_DEBUG=1`. + +If building on a machine with hardware that does not support Intel SGX, you can still emulate the behavior of an enclave by building in simulation mode. To do this, run `export OE_SIMULATION=1` from the command-line. + ## Building 1. Use CMake to build the makefiles in a corresponding `./build` folder. * `mkdir build && cd build` @@ -13,5 +19,3 @@ This folder contains all the necessary files to build and run a simple model agg * `make check` 4. Or build and sign the enclave separately: * `make sign` - -If building in simulate mode, set the environment variable `OE_SIMULATION=1` before step 1. diff --git a/server/enclave/CMakeLists.txt b/server/enclave/CMakeLists.txt index 25faabb..23c762a 100644 --- a/server/enclave/CMakeLists.txt +++ b/server/enclave/CMakeLists.txt @@ -28,9 +28,6 @@ set_target_properties(enclave PROPERTIES target_compile_definitions(enclave PRIVATE OE_API_VERSION=2) -if($ENV{OE_SIMULATION}) - target_compile_definitions(enclave PUBLIC -D__ENCLAVE_SIMULATION__) -endif() if (LVI_MITIGATION MATCHES ControlFlow) # Helper to enable compiler options for LVI mitigation. diff --git a/server/host/CMakeLists.txt b/server/host/CMakeLists.txt index 0a6d44d..0653d5c 100644 --- a/server/host/CMakeLists.txt +++ b/server/host/CMakeLists.txt @@ -15,4 +15,11 @@ target_include_directories(modelaggregator_host PRIVATE # Needed for the generated file modelaggregator_u.h ${CMAKE_CURRENT_BINARY_DIR}) +if($ENV{OE_SIMULATION}) + target_compile_definitions(modelaggregator_host PUBLIC -D__ENCLAVE_SIMULATION__) +endif() +if($ENV{OE_DEBUG}) + target_compile_definitions(modelaggregator_host PUBLIC -D__ENCLAVE_DEBUG__) +endif() + target_link_libraries(modelaggregator_host mbedcrypto mbedtls openenclave::oehostapp OpenMP::OpenMP_CXX) diff --git a/server/host/host.cpp b/server/host/host.cpp index 7a9b1ff..af5d35f 100644 --- a/server/host/host.cpp +++ b/server/host/host.cpp @@ -10,11 +10,9 @@ using namespace std; -char* g_path = "./enclave/enclave.signed"; +static char* g_path = "./enclave/enclave.signed"; -// Comment in the below if you want to run in debug / simulation mode -uint32_t g_flags = OE_ENCLAVE_FLAG_DEBUG | OE_ENCLAVE_FLAG_SIMULATE; -// uint32_t g_flags = 0; +static uint32_t g_flags = 0; // Cannot be larger than NumTCS in modelaggregator.conf static const int NUM_THREADS = 3; @@ -31,6 +29,13 @@ int host_modelaggregator(uint8_t*** encrypted_accumulator, { oe_result_t error; +#ifdef __ENCLAVE_SIMULATION__ + g_flags |= OE_ENCLAVE_FLAG_SIMULATE; +#endif +#ifdef __ENCLAVE_DEBUG__ + g_flags |= OE_ENCLAVE_FLAG_DEBUG; +#endif + // Create the enclave Enclave enclave(g_path, g_flags); error = enclave.getEnclaveRet(); diff --git a/server/tests/host_test.cpp b/server/tests/host_test.cpp index bb333f3..b794c31 100644 --- a/server/tests/host_test.cpp +++ b/server/tests/host_test.cpp @@ -20,7 +20,7 @@ int main(int argc, char* argv[]) size_t* accumulator_lengths = new size_t[accumulator_length * sizeof(size_t)]; for (int i = 0; i < accumulator_length; i++) { - map> accumulator = {{"w1", {i, i + 1, i + 2, i + 3}}, + map> accumulator = {{"w1", {i, i + 1, i + 2, i + 3}}, {"w2", {i + 1, i + 2, i + 3, i + 4}}, {"w3", {i + 2, i + 3, i + 4, i + 5}}, {"_contribution", {1}}}; @@ -36,7 +36,7 @@ int main(int argc, char* argv[]) accumulator_lengths[i] = serialized_buffer_size; } - map> old_params = {{"w1", {-3, -6, -9, -12}}, + map> old_params = {{"w1", {-3, -6, -9, -12}}, {"w2", {-6, -9, -12, -15}}, {"w3", {-9, -12, -15, -18}}}; int serialized_old_params_buffer_size = 0; From 981ea1d9c8bfedd72758386defc967cfa30cda7e Mon Sep 17 00:00:00 2001 From: Octavian Sima Date: Fri, 18 Dec 2020 13:34:19 -0800 Subject: [PATCH 7/9] updated README.md --- server/README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/server/README.md b/server/README.md index 0db1beb..7852eb2 100644 --- a/server/README.md +++ b/server/README.md @@ -3,11 +3,22 @@ ## About This folder contains all the necessary files to build and run a simple model aggregator in an enclave environment. The aggregator takes the element-wise sum of the variables received from multiple clients, weighs them by local iterations, then adds them to the existing model. All sensitive computation is done in an enclave environment, with encryption/decryption being performed inside. +## Dependencies +Building the server code requires the following dependencies: FlatBuffers, Mbed TLS, Open Enclave, and OpenMP. These can be installed on Ubuntu as follows: +1. FlatBuffers: + * `sudo apt-get install snapd` + * `sudo snap install flatbuffers` +2. Mbed TLS: + * `sudo apt-get install libmbedtls-dev` +3. Open Enclave: + * Follow the instructions [here](https://github.com/openenclave/openenclave/blob/master/docs/GettingStartedDocs/install_oe_sdk-Ubuntu_18.04.md) +4. OpenMP: + * `sudo apt-get install libomp-dev` ## Additional Flags If you would like to build in debugging mode (extra logs of enclave behavior available), set the `OE_DEBUG` environment variable: `export OE_DEBUG=1`. -If building on a machine with hardware that does not support Intel SGX, you can still emulate the behavior of an enclave by building in simulation mode. To do this, run `export OE_SIMULATION=1` from the command-line. +If building on a machine with hardware that does not support Intel SGX or any other enclave technology, you can still emulate the behavior of an enclave by building in simulation mode. To do this, run `export OE_SIMULATION=1` from the command-line. ## Building 1. Use CMake to build the makefiles in a corresponding `./build` folder. From 442cbdfa03df1cdefc078226e5d6818931059cf2 Mon Sep 17 00:00:00 2001 From: Octavian Sima Date: Fri, 18 Dec 2020 14:02:38 -0800 Subject: [PATCH 8/9] update dependencies --- server/CMakeLists.txt | 2 +- server/README.md | 16 ++++++++++------ server/host/host.cpp | 1 - 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 1ed01a6..3cb9603 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -3,7 +3,7 @@ project(modelaggregator LANGUAGES CXX C VERSION 1.00) include(CTest) -include_directories(../common /snap/flatbuffers/include) +include_directories(../common /snap/flatbuffers/current/include) if (LVI_MITIGATION MATCHES ControlFlow) # Configure the cmake to use customized compilation toolchain. diff --git a/server/README.md b/server/README.md index 7852eb2..8af3276 100644 --- a/server/README.md +++ b/server/README.md @@ -4,24 +4,28 @@ This folder contains all the necessary files to build and run a simple model aggregator in an enclave environment. The aggregator takes the element-wise sum of the variables received from multiple clients, weighs them by local iterations, then adds them to the existing model. All sensitive computation is done in an enclave environment, with encryption/decryption being performed inside. ## Dependencies -Building the server code requires the following dependencies: FlatBuffers, Mbed TLS, Open Enclave, and OpenMP. These can be installed on Ubuntu as follows: +Building the server code requires the following dependencies that can be installed on Ubuntu as follows: +1. Pip3: + * `sudo apt install python3-pip` +2. CMake: + * `pip3 install cmake` 1. FlatBuffers: - * `sudo apt-get install snapd` + * `sudo apt install snapd` * `sudo snap install flatbuffers` 2. Mbed TLS: - * `sudo apt-get install libmbedtls-dev` + * `sudo apt install libmbedtls-dev` 3. Open Enclave: * Follow the instructions [here](https://github.com/openenclave/openenclave/blob/master/docs/GettingStartedDocs/install_oe_sdk-Ubuntu_18.04.md) 4. OpenMP: - * `sudo apt-get install libomp-dev` + * `sudo apt install libomp-dev` ## Additional Flags If you would like to build in debugging mode (extra logs of enclave behavior available), set the `OE_DEBUG` environment variable: `export OE_DEBUG=1`. -If building on a machine with hardware that does not support Intel SGX or any other enclave technology, you can still emulate the behavior of an enclave by building in simulation mode. To do this, run `export OE_SIMULATION=1` from the command-line. +If building on a machine with hardware that does not support Intel SGX, you can still emulate the behavior of an enclave by building in simulation mode. To do this, set the `OE_SIMULATION` environment variable: `export OE_SIMULATION=1`. ## Building -1. Use CMake to build the makefiles in a corresponding `./build` folder. +1. Use CMake to build the makefiles in a corresponding `./build` folder: * `mkdir build && cd build` * `cmake ..` 2. Build all targets: diff --git a/server/host/host.cpp b/server/host/host.cpp index af5d35f..dde553a 100644 --- a/server/host/host.cpp +++ b/server/host/host.cpp @@ -11,7 +11,6 @@ using namespace std; static char* g_path = "./enclave/enclave.signed"; - static uint32_t g_flags = 0; // Cannot be larger than NumTCS in modelaggregator.conf From d10c9ebb54741ffe80d7f18b4b096fbf6b6f39f8 Mon Sep 17 00:00:00 2001 From: Octavian Sima Date: Tue, 22 Dec 2020 12:38:15 -0500 Subject: [PATCH 9/9] update README.md --- server/README.md | 10 ++++++---- server/host/host.cpp | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/server/README.md b/server/README.md index 8af3276..92e1af4 100644 --- a/server/README.md +++ b/server/README.md @@ -9,14 +9,16 @@ Building the server code requires the following dependencies that can be install * `sudo apt install python3-pip` 2. CMake: * `pip3 install cmake` -1. FlatBuffers: +3. FlatBuffers: * `sudo apt install snapd` * `sudo snap install flatbuffers` -2. Mbed TLS: + * Note: If you're working in a Docker container, Snap's FlatBuffers installation may not work. In that case, install FlatBuffers using snap outside the container, and mount the FlatBuffers installation to the same location inside the container when starting the container, i.e. add the following flag to your `docker exec` command: + * `-v /snap/flatbuffers/current/include:/snap/flatbuffers/current/include` +4. Mbed TLS: * `sudo apt install libmbedtls-dev` -3. Open Enclave: +5. Open Enclave: * Follow the instructions [here](https://github.com/openenclave/openenclave/blob/master/docs/GettingStartedDocs/install_oe_sdk-Ubuntu_18.04.md) -4. OpenMP: +6. OpenMP: * `sudo apt install libomp-dev` ## Additional Flags diff --git a/server/host/host.cpp b/server/host/host.cpp index dde553a..4c21015 100644 --- a/server/host/host.cpp +++ b/server/host/host.cpp @@ -14,7 +14,7 @@ static char* g_path = "./enclave/enclave.signed"; static uint32_t g_flags = 0; // Cannot be larger than NumTCS in modelaggregator.conf -static const int NUM_THREADS = 3; +static const int NUM_THREADS = 1; // This is the function that the Python code will call into. // Returns 0 on success.