Skip to content

Commit

Permalink
feat: version 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PETAce committed Jun 26, 2024
1 parent f79ede7 commit 34ffb78
Show file tree
Hide file tree
Showing 14 changed files with 651 additions and 24 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@
### Features

- Added KKRT oblivious transfer.

## Version 0.3.0

### Features

- Added benchmark for Verse.
33 changes: 24 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if(NOT CMAKE_BUILD_TYPE)
endif()
message(STATUS "Build type (CMAKE_BUILD_TYPE): ${CMAKE_BUILD_TYPE}")

project(VERSE VERSION 0.2.0 LANGUAGES CXX C)
project(VERSE VERSION 0.3.0 LANGUAGES CXX C)

########################
# Global configuration #
Expand Down Expand Up @@ -153,7 +153,12 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND VERSE_ENABLE_GCOV)
endif()

# CMAKE_CXX_LINK_EXECUTABLE
set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -ldl -lrt")
if (LINUX)
set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -ldl -lrt")
else()
set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE}")
endif()


#########################
# External dependencies #
Expand Down Expand Up @@ -193,7 +198,7 @@ if(NOT TARGET Threads::Threads)
endif()

# PETAce-Network::network
find_package(PETAce-Network 0.2 QUIET CONFIG)
find_package(PETAce-Network 0.3 QUIET CONFIG)
if(PETAce-Network_FOUND)
message(STATUS "PETAce-Network: found")
if(PETAce-Network_STATIC_FOUND)
Expand All @@ -217,7 +222,7 @@ else()
endif()

# PETAce-Solo::solo
find_package(PETAce-Solo 0.2 QUIET CONFIG)
find_package(PETAce-Solo 0.3 QUIET CONFIG)
if(PETAce-Solo_FOUND)
message(STATUS "PETAce-Solo: found")
if(PETAce-Solo_STATIC_FOUND)
Expand Down Expand Up @@ -275,12 +280,9 @@ if(NOT VERSE_BUILD_SHARED_LIBS)
target_include_directories(verse PUBLIC
$<BUILD_INTERFACE:$<TARGET_PROPERTY:${network},INTERFACE_INCLUDE_DIRECTORIES>>
$<INSTALL_INTERFACE:${VERSE_INCLUDES_INSTALL_DIR}>)
verse_combine_archives(verse ${network})
set(VERSE_CARRY_NETWORK TRUE)
else()
target_link_libraries(verse PUBLIC ${network})
set(VERSE_CARRY_NETWORK FALSE)
endif()
target_link_libraries(verse PUBLIC ${network})
set(VERSE_CARRY_NETWORK FALSE)

if(VERSE_BUILD_SOLO)
add_dependencies(verse ${solo})
Expand Down Expand Up @@ -407,6 +409,19 @@ if(VERSE_BUILD_EXAMPLE)
add_subdirectory(example)
endif()

##################
# VERSE C++ bench #
##################

# [option] VERSE_BUILD_BENCH
set(VERSE_BUILD_BENCH_OPTION_STR "Build C++ benchmark for VERSE")
option(VERSE_BUILD_BENCH ${VERSE_BUILD_BENCH_OPTION_STR} ON)
message(STATUS "VERSE_BUILD_BENCH: ${VERSE_BUILD_BENCH}")

if(VERSE_BUILD_BENCH)
add_subdirectory(bench)
endif()

##################
# VERSE C++ test #
##################
Expand Down
33 changes: 26 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ Currently, PETAce-Verse includes: [Naor-Pinkas OT](https://dl.acm.org/doi/10.555

| Required dependency | Tested version | Use |
|--------------------------------------------------------------------------------|----------------|---------------------------------|
| [PETAce-Solo](https://github.com/tiktok-privacy-innovation/PETAce-Solo) | 0.2.0 | Cryptography primitives |
| [PETAce-Network](https://github.com/tiktok-privacy-innovation/PETAce-Network) | 0.2.0 | Network communication protocols |
| [PETAce-Solo](https://github.com/tiktok-privacy-innovation/PETAce-Solo) | 0.3.0 | Cryptography primitives |
| [PETAce-Network](https://github.com/tiktok-privacy-innovation/PETAce-Network) | 0.3.0 | Network communication protocols |

| Optional dependency | Tested version | Use |
|----------------------------------------------------|----------------|-------------------|
| [GoogleTest](https://github.com/google/googletest) | 1.12.1 | For running tests |
| [GoogleTest](https://github.com/google/googletest) | 1.12.1 | For running tests |
| [Google Logging](https://github.com/google/glog) | 0.4.0 | For running benchmarks |
| [TCLAP](https://github.com/mirror/tclap) | 1.2.2 | For running benchmarks |

## Building PETAce-Verse

Expand All @@ -42,6 +44,7 @@ Output binaries can be found in `build/lib/` and `build/bin/` directories.
| `CMAKE_BUILD_TYPE` | Release/Debug | Release | Debug mode decreases run-time performance. |
| `VERSE_BUILD_SHARED_LIBS` | ON/OFF | OFF | Build a shared library if set to ON. |
| `VERSE_BUILD_EXAMPLE` | ON/OFF | ON | Build C++ example if set to ON. |
| `VERSE_BUILD_BENCH` | ON/OFF | ON | Build C++ benchmark if set to ON. |
| `VERSE_BUILD_TEST` | ON/OFF | ON | Build C++ test if set to ON. |
| `VERSE_BUILD_DEPS` | ON/OFF | ON | Download and build unmet dependencies if set to ON. |

Expand All @@ -59,6 +62,22 @@ To run Party B
./build/bin/verse_example 127.0.0.1 8890 127.0.0.1 8899 1
```

We have also prepared a series of performance test cases for PETAce-Verse.

To run Party A

```shell
./build/bin/verse_bench -p 0 --log_path ./verse0.log
```

To run Party B

```shell
./build/bin/verse_bench -p 1 --log_path ./verse1.log
```

You can also use ./build/bin/verse_bench -h to learn more details.

## Contribution

Please check [Contributing](CONTRIBUTING.md) for more details.
Expand All @@ -75,14 +94,14 @@ This project is licensed under the [Apache-2.0 License](LICENSE).

To cite PETAce in academic papers, please use the following BibTeX entries.

### Version 0.2.0
### Version 0.3.0

```tex
@misc{petace,
title = {PETAce (release 0.2.0)},
title = {PETAce (release 0.3.0)},
howpublished = {\url{https://github.com/tiktok-privacy-innovation/PETAce}},
month = Oct,
year = 2023,
month = Jun,
year = 2024,
note = {TikTok Pte. Ltd.},
key = {PETAce}
}
Expand Down
94 changes: 94 additions & 0 deletions bench/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Copyright 2023 TikTok Pte. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.14)

project(VERSEBench VERSION 0.3.0 LANGUAGES CXX)

# If not called from root CMakeLists.txt
if(NOT DEFINED VERSE_BUILD_BENCH)
set(VERSE_BUILD_BENCH ON)

find_package(PETAce-Verse 0.3.0 EXACT REQUIRED)

add_compile_options(-msse4.2 -Wno-ignored-attributes -mavx)

# Must define these variables and include macros
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(VERSE_THIRDPARTY_DIR ${CMAKE_CURRENT_BINARY_DIR}/thirdparty)
set(THIRDPARTY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/thirdparty)
include(FetchContent)
mark_as_advanced(FETCHCONTENT_BASE_DIR)
mark_as_advanced(FETCHCONTENT_FULLY_DISCONNECTED)
mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED)
mark_as_advanced(FETCHCONTENT_QUIET)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../cmake)
include(VerseCustomMacros)
else()
set(THIRDPARTY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/../thirdparty)
endif()

if(NOT DEFINED VERSE_BUILD_DEPS)
# [option] VERSE_BUILD_DEPS (default: ON)
# Download and build missing dependencies, throw error if disabled.
set(VERSE_BUILD_DEPS_OPTION_STR "Automatically download and build unmet dependencies")
option(VERSE_BUILD_DEPS ${VERSE_BUILD_DEPS_OPTION_STR} ON)
endif()

# if VERSE_BUILD_BENCH is ON, use GoogleBenchmark
if(VERSE_BUILD_BENCH)

if(VERSE_BUILD_DEPS)
# tclap
message(STATUS "Tclap: download ...")
verse_fetch_thirdparty_content(ExternalTclap)
else()
message(FATAL_ERROR "Tclap: not found, please download and install manually")
endif()

# glog::glog
if(NOT TARGET glog::glog)
find_package(glog 0.4.0 QUIET CONFIG)
if(glog_FOUND)
message(STATUS "glog: found")
else()
if(VERSE_BUILD_DEPS)
message(STATUS "glog: download ...")
verse_fetch_thirdparty_content(ExternalGlog)
else()
message(FATAL_ERROR "glog: not found, please download and install manually")
endif()
endif()
endif()

# Add source files to bench
set(VERSE_BENCH_FILES
${CMAKE_CURRENT_LIST_DIR}/bench.cpp
${CMAKE_CURRENT_LIST_DIR}/verse_bench.cpp
)

set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -ldl -lrt")
add_executable(verse_bench ${VERSE_BENCH_FILES})

target_include_directories(verse_bench PRIVATE ${CMAKE_BINARY_DIR}/thirdparty/tclap-src/include)

if(TARGET PETAce-Verse::verse)
target_link_libraries(verse_bench PRIVATE PETAce-Verse::verse glog::glog)
elseif(TARGET PETAce-Verse::verse_shared)
target_link_libraries(verse_bench PRIVATE PETAce-Verse::verse_shared glog::glog)
else()
message(FATAL_ERROR "Cannot find target PETAce::verse or PETAce::verse_shared")
endif()
endif()
71 changes: 71 additions & 0 deletions bench/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# PETAce-Verse Benchmark

We have prepared a series of performance tests for PETAce-Verse.

## How to run the benchmark

The benchmark codes of all test cases are available in `verse_bench.cpp`.
You should set the option `VERSE_BUILD_BENCH` to be on when building Verse, and the binary file `verse_bench` will be found in `/build/bin`.
To run the benchmark cases, open two terminal sessions and run the following command in the first terminal:

```bash
./build/bin/verse_bench -p 0 --log_path ./verse0.log
```
This terminal will act as party 0 and execute the benchmark program.
Similarly, run the following command in the second terminal.

```bash
./build/bin/verse_bench -p 1 --log_path ./verse1.log
```

Then, you can find logs files in the `/build` directory, named `verse0.log` and `verse1.log`, which represent the performance metrics of Party 0 and Party 1, respectively.

## Logging Format
Logging information follows a specific format as follows:

```bash
case <case name> begin <timestamp> <test_iteration> <parameter>
case <case name> end <timestamp> <cost time> <bytes_send> <bytes_received>
```
```bash
case <case name> begin <timestamp> <test_iteration> <parameter>
stage <stage name> begin <timestamp>
stage <stage name> end <timestamp> <cost time> <bytes_send> <bytes_received>
case <case name> end <timestamp> <cost time> <bytes_send> <bytes_received>
```
`case * begin` and `case * end` indicates the start and end of the test case, respectively. A test case may include multiple stages. For example, when calculating the dot product, one must first compute the element-wise multiplication of two vectors, followed by the summation of these products. We denote the start and end of a stage with the labels `stage begin` and `stage end`.
The meanings of other fields are as follows:
- `case name`: the name of the test case
- `timestamp`: the timestamp of the start or end of the test case or stage
- `test_iteration`: the number of the test case executions
- `parameter`: the parameters of the test case
- `stage name`: the name of the stage
- `cost time`: the time cost of the test case or stage
- `bytes_send`: the number of bytes sent
- `bytes_received`: the number of bytes received
## Benchmark with Various Network Conditions
For MPC (Multi-Party Computation), network overhead is a critical metric. We offer a straightforward method to simulate various network conditions.
The following command can be used to simulate a network with a given latency and bandwidth.
```bash
tc qdisc add dev lo root netem delay {latency}ms rate {bandwidth}mbit
```
For example, to simulate a network with 10ms latency and 100Mbps bandwidth, run the following command.
```bash
tc qdisc add dev lo root netem delay 10ms rate 100mbit
```
To remove this limitation, you can use the following command:
```bash
tc qdisc del dev lo root
```
Loading

0 comments on commit 34ffb78

Please sign in to comment.