Skip to content

Commit

Permalink
ABY VM and Interpreter (circify#47)
Browse files Browse the repository at this point in the history
Updated ABY testing framework with an ABY bytecode and interpreter
  • Loading branch information
edwjchen authored and elefthei committed Oct 11, 2022
1 parent 674c377 commit 127b37f
Show file tree
Hide file tree
Showing 88 changed files with 1,805 additions and 1,134 deletions.
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
File renamed without changes.
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 @@ -22,7 +22,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 @@ -391,7 +390,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 @@ -41,12 +41,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

0 comments on commit 127b37f

Please sign in to comment.