Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

secavf #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions SecureAggregation-master/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__pycache__/
.vscode
keys/
*.h5
21 changes: 21 additions & 0 deletions SecureAggregation-master/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Junbao Chen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
48 changes: 48 additions & 0 deletions SecureAggregation-master/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Secure Aggregation

This is an unofficial implementation of Secure Aggregation Protocol. The details of the protocol can be found in the original paper: [(CCS'17) Practical Secure Aggregation for Privacy-Preserving Machine Learning](https://dl.acm.org/doi/abs/10.1145/3133956.3133982).

## Usage

There are two ways to use the Secure Aggregation Protocol.

### Docker
---

This is the recommended option, as all entities are independent containers. That is, a real federated learning scenario is simulated in this way.

- Pull base image:
```
$ docker pull chenjunbao/secureaggregation
```

- Build docker images for each entity:
```
$ git clone https://github.com/chen-junbao/secureaggregation.git
$ cd secureaggregation/docker
$ ./scripts/build.sh
```

- Simulate 100 users and set the waiting time and iteration to 60 seconds and 20, respectively:
```
$ ./start.sh -u 100 -t 60 -i 20
```

### Single Machine
---

- Install python libraries:

```
$ git clone https://github.com/chen-junbao/secureaggregation.git
$ cd secureaggregation
$ pip install -r requirements.txt
$ pip install git+https://github.com/blockstack/secret-sharing

$ python main.py -h
```

- Simulate 100 users and set the waiting time to 300 seconds:
```
$ python main.py -u 100 -t 300
```
12 changes: 12 additions & 0 deletions SecureAggregation-master/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM tensorflow/tensorflow:latest-gpu

LABEL maintainer="chen.junbao@outlook.com"

ADD ./requirements.txt /sa/requirements.txt
ADD ./secret-sharing /sa/secret-sharing

WORKDIR /sa

RUN ["apt", "install", "-y", "git"]
RUN ["pip", "install", "-r", "requirements.txt"]
RUN ["pip", "install", "git+file:///sa/secret-sharing"]
4 changes: 4 additions & 0 deletions SecureAggregation-master/docker/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
py_diffie_hellman==1.0.1
pycryptodomex==3.12.0
rsa==4.8
tqdm==4.62.3
9 changes: 9 additions & 0 deletions SecureAggregation-master/docker/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#! /bin/bash

. scripts/utils.sh

infoln "Building docker images for each entity"
docker build -t sa/server:1.0 ./server
docker build -t sa/ta:1.0 ./ta
docker build -t sa/user:1.0 ./user
successln "Successfully built server, TA and user images"
49 changes: 49 additions & 0 deletions SecureAggregation-master/docker/scripts/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

C_RESET='\033[0m'
C_RED='\033[0;31m'
C_GREEN='\033[0;32m'
C_BLUE='\033[0;34m'

function printHelp() {
cat <<EOF
Usage: start.sh [OPTIONS] [ARG...]

Secure aggregation protocol for federated learning

Option:
-h, --help Show this help message and exit
-u, --user int Set the number of users
-t, --wait int Set maximum waiting time for each round
-i, --iteration int Set the iteration of federated learning
--model str Set the trained model (MLP or CNN)
--batchsize int Set the training batch size

Examples:
start.sh -u 500 -t 300 -i 20 --model CNN --batchsize 28
EOF
}

# println echos string
function println() {
echo -e "$1"
}

# errorln echos i red color
function errorln() {
println "${C_RED}${1}${C_RESET}"
}

# successln echos in green color
function successln() {
println "${C_GREEN}${1}${C_RESET}"
}

# infoln echos in blue color
function infoln() {
println "${C_BLUE}${1}${C_RESET}"
}

export -f errorln
export -f successln
export -f infoln
1 change: 1 addition & 0 deletions SecureAggregation-master/docker/server/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
model.h5
11 changes: 11 additions & 0 deletions SecureAggregation-master/docker/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM fedncf:latest

LABEL maintainer="chen.junbao@outlook.com"

ADD . /server

WORKDIR /server

EXPOSE 10000 20000-20004

ENTRYPOINT [ "python", "-u", "main.py" ]
Loading