Skip to content

Commit

Permalink
Enclave flag consolidation and README improvements
Browse files Browse the repository at this point in the history
Co-authored-by: Octavian Sima <[email protected]>
  • Loading branch information
chester-leung and Octavian Sima committed Jan 21, 2021
1 parent dc99ddd commit 90f5ffb
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
27 changes: 24 additions & 3 deletions server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,31 @@
## 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 that can be installed on Ubuntu as follows:
1. Pip3:
* `sudo apt install python3-pip`
2. CMake:
* `pip3 install cmake`
3. FlatBuffers:
* `sudo apt install snapd`
* `sudo snap install flatbuffers`
* 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`
5. Open Enclave:
* Follow the instructions [here](https://github.com/openenclave/openenclave/blob/master/docs/GettingStartedDocs/install_oe_sdk-Ubuntu_18.04.md)
6. OpenMP:
* `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, 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:
Expand All @@ -13,5 +36,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.
3 changes: 0 additions & 3 deletions server/enclave/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions server/host/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
14 changes: 9 additions & 5 deletions server/host/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,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;
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 = 1;
Expand All @@ -31,6 +28,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();
Expand Down
6 changes: 3 additions & 3 deletions server/tests/host_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, vector<double>> accumulator = {{"w1", {i, i + 1, i + 2, i + 3}},
map<string, vector<float>> 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}}};
Expand All @@ -36,7 +36,7 @@ int main(int argc, char* argv[])
accumulator_lengths[i] = serialized_buffer_size;
}

map<string, vector<double>> old_params = {{"w1", {-3, -6, -9, -12}},
map<string, vector<float>> old_params = {{"w1", {-3, -6, -9, -12}},
{"w2", {-6, -9, -12, -15}},
{"w3", {-9, -12, -15, -18}}};
int serialized_old_params_buffer_size = 0;
Expand Down Expand Up @@ -102,7 +102,7 @@ int main(int argc, char* argv[])
delete encrypted_new_params_ptr[i];
}

map<string, vector<double>> new_params = deserialize(serialized_new_params);
map<string, vector<float>> new_params = deserialize(serialized_new_params);

for (const auto& pair : new_params) {
if (pair.second.size() != 4) {
Expand Down

0 comments on commit 90f5ffb

Please sign in to comment.