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

ABY VM and Interpreter #47

Merged
merged 32 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
17c19fc
Added support for multiple outputs in test cases
edwjchen Aug 31, 2021
62282de
Added support for multiple outputs in test cases
edwjchen Aug 31, 2021
fb4c08e
added function call tests
edwjchen Aug 31, 2021
e4c49c5
merged
edwjchen Aug 31, 2021
be62a46
merging test file
edwjchen Sep 1, 2021
ea3a6ee
Added EZPC helper file, updated output, added shift tests
edwjchen Sep 2, 2021
95205f7
Merge branch 'lower_to_aby' of https://github.com/circify/circ into l…
edwjchen Sep 2, 2021
561483a
merged
edwjchen Sep 3, 2021
fa547d5
Merge branch 'master' into lower_to_aby
edwjchen Sep 3, 2021
db6e1a0
loops for ABY!
edwjchen Sep 3, 2021
02e4c44
fixing array tests cases
edwjchen Sep 7, 2021
6a61265
merged with master
edwjchen Feb 8, 2022
3a46422
new parser
edwjchen Feb 9, 2022
331b8b0
minor
edwjchen Feb 9, 2022
bd58945
new input parser for testing
edwjchen Feb 9, 2022
2c252b6
updated ABY test setup
edwjchen Feb 10, 2022
aa11569
remove vscode setting
edwjchen Feb 10, 2022
99305e3
remove input parser
edwjchen Feb 10, 2022
1e3aad3
formatting
edwjchen Feb 10, 2022
9a51697
bytecode parser
edwjchen Feb 13, 2022
b68b4a5
format and lint
edwjchen Feb 13, 2022
7fec867
aby interpreter!
edwjchen Feb 15, 2022
2b36c98
updated ABY
edwjchen Feb 17, 2022
fc5621e
tested!
edwjchen Feb 22, 2022
cbff492
lint
edwjchen Feb 22, 2022
6d06441
merge with master
edwjchen Feb 28, 2022
1d0e777
updated build system to use ABY interpreter
edwjchen Feb 28, 2022
6109840
removing feature list
edwjchen Feb 28, 2022
20a4b3f
removed make file
edwjchen Feb 28, 2022
b2322cb
lint
edwjchen Feb 28, 2022
0d4ee96
updating ci
edwjchen Feb 28, 2022
4e1f128
fixing path error
edwjchen Feb 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,5 @@ jobs:
run: cargo fmt -- --check
- name: Lint
run: python3 driver.py --lint
- name: Build
run: python3 driver.py --build
- name: Test
- name: Build, then Test
run: python3 driver.py --test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ __pycache__
/perf.data*
/.gdb_history
.features.txt
scripts/aby_tests/tests
23 changes: 9 additions & 14 deletions driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ def verify_path_empty(path) -> bool:
subprocess.run(["git", "clone", "https://github.com/edwjchen/ABY.git", ABY_SOURCE])
subprocess.run(["./scripts/build_aby.zsh"])

# Get EZPC header file
subprocess.run(["mkdir", "-p", EZPC_SOURCE])
subprocess.run(["wget", "-O", EZPC_SOURCE+"/ezpc.h", "https://raw.githubusercontent.com/circify/circ/master/third_party/EZPC/ezpc.h"])


def check(features):
"""
Run cargo check
Expand All @@ -43,7 +38,7 @@ def check(features):
cargo_features = filter_cargo_features(features)
if cargo_features:
cmd = cmd + ["--features"] + cargo_features
subprocess.run(cmd)
subprocess.run(cmd, check=True)

def build(features):
"""
Expand All @@ -70,14 +65,14 @@ def build(features):
cargo_features = filter_cargo_features(features)
if cargo_features:
cmd = cmd + ["--features"] + cargo_features
subprocess.run(cmd)
subprocess.run(cmd, check=True)

if "aby" in features:
if "c" in features:
subprocess.run(["./scripts/build_mpc_c_test.zsh"])
subprocess.run(["./scripts/build_mpc_c_test.zsh"], check=True)
if "smt" in features and "zok" in features:
subprocess.run(["./scripts/build_mpc_zokrates_test.zsh"])
subprocess.run(["./scripts/build_aby.zsh"])
subprocess.run(["./scripts/build_mpc_zokrates_test.zsh"], check=True)
subprocess.run(["./scripts/build_aby.zsh"], check=True)

def test(features):
"""
Expand All @@ -97,10 +92,6 @@ def test(features):
test_cmd = test_cmd + ["--features"] + cargo_features
subprocess.run(test_cmd, check=True)

if "c" in features:
if "a" in features:
subprocess.run(["python3", "./scripts/aby_tests/c_test_aby.py"], check=True)

if "r1cs" in features and "smt" in features:
subprocess.run(["./scripts/test_datalog.zsh"], check=True)

Expand All @@ -114,6 +105,10 @@ def test(features):
if "lp" in features and "r1cs" in features:
subprocess.run(["./scripts/test_zok_to_ilp_pf.zsh"], check=True)

if "c" in features:
if "aby" in features:
subprocess.run(["python3", "./scripts/aby_tests/c_test_aby.py"], check=True)

def format():
print("formatting!")
subprocess.run(["cargo", "fmt", "--all"], check=True)
Expand Down
2 changes: 1 addition & 1 deletion examples/C/mpc/benchmarks/2pc_biomatch.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
int mpc_main(
int main(
__attribute__((private(0))) int db[1024],
__attribute__((private(1))) int sample[4])
{
Expand Down
4 changes: 0 additions & 4 deletions examples/ZoKrates/mpc/unit_tests/2pc_conv.zok

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def main(private<1> u32 a, private<2> u32 b, public bool sel) -> u32:
return if sel then a else b fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def main(private<1> u32 a, private<2> u32 b) -> u32:
for u32 i in 0..4 do
a = a + b
endfor
return a

2 changes: 0 additions & 2 deletions examples/circ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use circ::ir::{
opt::{opt, Opt},
term::extras::Letified,
};
use circ::target::aby::output::write_aby_exec;
use circ::target::aby::trans::to_aby;
#[cfg(feature = "lp")]
use circ::target::ilp::trans::to_ilp;
Expand Down Expand Up @@ -327,7 +326,6 @@ fn main() {
};
println!("Cost model: {}", cost_model);
to_aby(cs, &path_buf, &lang_str, &cost_model);
write_aby_exec(&path_buf, &lang_str);
}
#[cfg(feature = "lp")]
Backend::Ilp { .. } => {
Expand Down
10 changes: 6 additions & 4 deletions scripts/aby_tests/c_test_aby.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
const_arith_tests + \
const_bool_tests + \
ite_tests + \
c_array_tests + \
div_tests + \
function_tests + \
array_tests
array_tests + \
c_array_tests + \
misc_tests + \
biomatch_tests + \
kmeans_tests
# shift_tests

# TODO: add support for return value - int promotion
# unsigned_arithmetic_tests + \

Expand Down
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/add.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 1

// client
b 2

// result
3
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/add_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 1

// client
b 2

// result
6
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/and_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 0

// client
b 0

// result
0
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/and_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 1

// client
b 0

// result
0
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/and_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 0

// client
b 1

// result
0
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/and_4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 1

// client
b 1

// result
1
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/array.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 2

// client
b 2

// result
2
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/array_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 10

// client
b 3

// result
17
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/array_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 10

// client
b 3

// result
17
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/array_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 2

// client
b 3

// result
18
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/array_4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 1 2 3 4 5

// client
b 1 2 3 4 5

// result
30
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/biomatch_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
db 0 1 2 3 1 2 3 4 2 3 4 5 3 4 5 6 4 5 6 7 5 6 7 8 6 7 8 9 7 8 9 10 8 9 10 11 9 10 11 12 10 11 12 13 11 12 13 14 12 13 14 15 13 14 15 16 14 15 16 17 15 16 17 18 16 17 18 19 17 18 19 20 18 19 20 21 19 20 21 22 20 21 22 23 21 22 23 24 22 23 24 25 23 24 25 26 24 25 26 27 25 26 27 28 26 27 28 29 27 28 29 30 28 29 30 31 29 30 31 32 30 31 32 33 31 32 33 34 32 33 34 35 33 34 35 36 34 35 36 37 35 36 37 38 36 37 38 39 37 38 39 40 38 39 40 41 39 40 41 42 40 41 42 43 41 42 43 44 42 43 44 45 43 44 45 46 44 45 46 47 45 46 47 48 46 47 48 49 47 48 49 50 48 49 50 51 49 50 51 52 50 51 52 53 51 52 53 54 52 53 54 55 53 54 55 56 54 55 56 57 55 56 57 58 56 57 58 59 57 58 59 60 58 59 60 61 59 60 61 62 60 61 62 63 61 62 63 64 62 63 64 65 63 64 65 66 64 65 66 67 65 66 67 68 66 67 68 69 67 68 69 70 68 69 70 71 69 70 71 72 70 71 72 73 71 72 73 74 72 73 74 75 73 74 75 76 74 75 76 77 75 76 77 78 76 77 78 79 77 78 79 80 78 79 80 81 79 80 81 82 80 81 82 83 81 82 83 84 82 83 84 85 83 84 85 86 84 85 86 87 85 86 87 88 86 87 88 89 87 88 89 90 88 89 90 91 89 90 91 92 90 91 92 93 91 92 93 94 92 93 94 95 93 94 95 96 94 95 96 97 95 96 97 98 96 97 98 99 97 98 99 100 98 99 100 101 99 100 101 102 100 101 102 103 101 102 103 104 102 103 104 105 103 104 105 106 104 105 106 107 105 106 107 108 106 107 108 109 107 108 109 110 108 109 110 111 109 110 111 112 110 111 112 113 111 112 113 114 112 113 114 115 113 114 115 116 114 115 116 117 115 116 117 118 116 117 118 119 117 118 119 120 118 119 120 121 119 120 121 122 120 121 122 123 121 122 123 124 122 123 124 125 123 124 125 126 124 125 126 127 125 126 127 128 126 127 128 129 127 128 129 130 128 129 130 131 129 130 131 132 130 131 132 133 131 132 133 134 132 133 134 135 133 134 135 136 134 135 136 137 135 136 137 138 136 137 138 139 137 138 139 140 138 139 140 141 139 140 141 142 140 141 142 143 141 142 143 144 142 143 144 145 143 144 145 146 144 145 146 147 145 146 147 148 146 147 148 149 147 148 149 150 148 149 150 151 149 150 151 152 150 151 152 153 151 152 153 154 152 153 154 155 153 154 155 156 154 155 156 157 155 156 157 158 156 157 158 159 157 158 159 160 158 159 160 161 159 160 161 162 160 161 162 163 161 162 163 164 162 163 164 165 163 164 165 166 164 165 166 167 165 166 167 168 166 167 168 169 167 168 169 170 168 169 170 171 169 170 171 172 170 171 172 173 171 172 173 174 172 173 174 175 173 174 175 176 174 175 176 177 175 176 177 178 176 177 178 179 177 178 179 180 178 179 180 181 179 180 181 182 180 181 182 183 181 182 183 184 182 183 184 185 183 184 185 186 184 185 186 187 185 186 187 188 186 187 188 189 187 188 189 190 188 189 190 191 189 190 191 192 190 191 192 193 191 192 193 194 192 193 194 195 193 194 195 196 194 195 196 197 195 196 197 198 196 197 198 199 197 198 199 200 198 199 200 201 199 200 201 202 200 201 202 203 201 202 203 204 202 203 204 205 203 204 205 206 204 205 206 207 205 206 207 208 206 207 208 209 207 208 209 210 208 209 210 211 209 210 211 212 210 211 212 213 211 212 213 214 212 213 214 215 213 214 215 216 214 215 216 217 215 216 217 218 216 217 218 219 217 218 219 220 218 219 220 221 219 220 221 222 220 221 222 223 221 222 223 224 222 223 224 225 223 224 225 226 224 225 226 227 225 226 227 228 226 227 228 229 227 228 229 230 228 229 230 231 229 230 231 232 230 231 232 233 231 232 233 234 232 233 234 235 233 234 235 236 234 235 236 237 235 236 237 238 236 237 238 239 237 238 239 240 238 239 240 241 239 240 241 242 240 241 242 243 241 242 243 244 242 243 244 245 243 244 245 246 244 245 246 247 245 246 247 248 246 247 248 249 247 248 249 250 248 249 250 251 249 250 251 252 250 251 252 253 251 252 253 254 252 253 254 255 253 254 255 256 254 255 256 257 255 256 257 258

// client
sample 0 0 0 0

// result
14
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/biomatch_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
db 0 1 2 3 1 2 3 4 2 3 4 5 3 4 5 6 4 5 6 7 5 6 7 8 6 7 8 9 7 8 9 10 8 9 10 11 9 10 11 12 10 11 12 13 11 12 13 14 12 13 14 15 13 14 15 16 14 15 16 17 15 16 17 18 16 17 18 19 17 18 19 20 18 19 20 21 19 20 21 22 20 21 22 23 21 22 23 24 22 23 24 25 23 24 25 26 24 25 26 27 25 26 27 28 26 27 28 29 27 28 29 30 28 29 30 31 29 30 31 32 30 31 32 33 31 32 33 34 32 33 34 35 33 34 35 36 34 35 36 37 35 36 37 38 36 37 38 39 37 38 39 40 38 39 40 41 39 40 41 42 40 41 42 43 41 42 43 44 42 43 44 45 43 44 45 46 44 45 46 47 45 46 47 48 46 47 48 49 47 48 49 50 48 49 50 51 49 50 51 52 50 51 52 53 51 52 53 54 52 53 54 55 53 54 55 56 54 55 56 57 55 56 57 58 56 57 58 59 57 58 59 60 58 59 60 61 59 60 61 62 60 61 62 63 61 62 63 64 62 63 64 65 63 64 65 66 64 65 66 67 65 66 67 68 66 67 68 69 67 68 69 70 68 69 70 71 69 70 71 72 70 71 72 73 71 72 73 74 72 73 74 75 73 74 75 76 74 75 76 77 75 76 77 78 76 77 78 79 77 78 79 80 78 79 80 81 79 80 81 82 80 81 82 83 81 82 83 84 82 83 84 85 83 84 85 86 84 85 86 87 85 86 87 88 86 87 88 89 87 88 89 90 88 89 90 91 89 90 91 92 90 91 92 93 91 92 93 94 92 93 94 95 93 94 95 96 94 95 96 97 95 96 97 98 96 97 98 99 97 98 99 100 98 99 100 101 99 100 101 102 100 101 102 103 101 102 103 104 102 103 104 105 103 104 105 106 104 105 106 107 105 106 107 108 106 107 108 109 107 108 109 110 108 109 110 111 109 110 111 112 110 111 112 113 111 112 113 114 112 113 114 115 113 114 115 116 114 115 116 117 115 116 117 118 116 117 118 119 117 118 119 120 118 119 120 121 119 120 121 122 120 121 122 123 121 122 123 124 122 123 124 125 123 124 125 126 124 125 126 127 125 126 127 128 126 127 128 129 127 128 129 130 128 129 130 131 129 130 131 132 130 131 132 133 131 132 133 134 132 133 134 135 133 134 135 136 134 135 136 137 135 136 137 138 136 137 138 139 137 138 139 140 138 139 140 141 139 140 141 142 140 141 142 143 141 142 143 144 142 143 144 145 143 144 145 146 144 145 146 147 145 146 147 148 146 147 148 149 147 148 149 150 148 149 150 151 149 150 151 152 150 151 152 153 151 152 153 154 152 153 154 155 153 154 155 156 154 155 156 157 155 156 157 158 156 157 158 159 157 158 159 160 158 159 160 161 159 160 161 162 160 161 162 163 161 162 163 164 162 163 164 165 163 164 165 166 164 165 166 167 165 166 167 168 166 167 168 169 167 168 169 170 168 169 170 171 169 170 171 172 170 171 172 173 171 172 173 174 172 173 174 175 173 174 175 176 174 175 176 177 175 176 177 178 176 177 178 179 177 178 179 180 178 179 180 181 179 180 181 182 180 181 182 183 181 182 183 184 182 183 184 185 183 184 185 186 184 185 186 187 185 186 187 188 186 187 188 189 187 188 189 190 188 189 190 191 189 190 191 192 190 191 192 193 191 192 193 194 192 193 194 195 193 194 195 196 194 195 196 197 195 196 197 198 196 197 198 199 197 198 199 200 198 199 200 201 199 200 201 202 200 201 202 203 201 202 203 204 202 203 204 205 203 204 205 206 204 205 206 207 205 206 207 208 206 207 208 209 207 208 209 210 208 209 210 211 209 210 211 212 210 211 212 213 211 212 213 214 212 213 214 215 213 214 215 216 214 215 216 217 215 216 217 218 216 217 218 219 217 218 219 220 218 219 220 221 219 220 221 222 220 221 222 223 221 222 223 224 222 223 224 225 223 224 225 226 224 225 226 227 225 226 227 228 226 227 228 229 227 228 229 230 228 229 230 231 229 230 231 232 230 231 232 233 231 232 233 234 232 233 234 235 233 234 235 236 234 235 236 237 235 236 237 238 236 237 238 239 237 238 239 240 238 239 240 241 239 240 241 242 240 241 242 243 241 242 243 244 242 243 244 245 243 244 245 246 244 245 246 247 245 246 247 248 246 247 248 249 247 248 249 250 248 249 250 251 249 250 251 252 250 251 252 253 251 252 253 254 252 253 254 255 253 254 255 256 254 255 256 257 255 256 257 258

// client
sample 1 2 3 4

// result
0
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/const_add.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 2

// client
b 3

// result
6
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/const_eq_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 0

// client
b 0

// result
0
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/const_eq_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 1

// client
b 0

// result
1
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/conv.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 0

// client
b 7

// result
7
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/div_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 10

// client
b 1

// result
10
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/div_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 10

// client
b 2

// result
5
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/div_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 11

// client
b 2

// result
5
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/div_4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 1

// client
b 2

// result
0
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/eq_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 1

// client
b 0

// result
0
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/eq_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 1

// client
b 1

// result
1
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/ge_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 1

// client
b 2

// result
0
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/ge_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 1

// client
b 1

// result
1
8 changes: 8 additions & 0 deletions scripts/aby_tests/test_inputs/ge_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// server
a 1

// client
b 0

// result
1