From a4297bc022f6b00a365a600fb3cb24d856a26824 Mon Sep 17 00:00:00 2001 From: Edward Chen Date: Mon, 27 Sep 2021 19:39:17 -0400 Subject: [PATCH] updated testing suite for both zok and c frontends --- Makefile | 2 +- .../__pycache__/test_suite.cpython-38.pyc | Bin 6422 -> 6277 bytes .../__pycache__/utils.cpython-38.pyc | Bin 2428 -> 3746 bytes scripts/aby_tests/c_test_aby.py | 20 +++ .../{zokrates_test_suite.py => test_suite.py} | 144 +++++++++--------- scripts/aby_tests/utils.py | 65 ++++++-- scripts/aby_tests/zokrates_test_aby.py | 43 +----- scripts/build_mpc_c_test.zsh | 48 +++--- 8 files changed, 175 insertions(+), 147 deletions(-) create mode 100755 scripts/aby_tests/c_test_aby.py rename scripts/aby_tests/{zokrates_test_suite.py => test_suite.py} (65%) diff --git a/Makefile b/Makefile index ee754b81..6cf5f415 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ init: git submodule update --init aby: - ./scripts/build_mpc_c_test.zsh && ./scripts/build_aby.zsh && python3 ./scripts/aby_tests/test_aby.py + ./scripts/build_mpc_c_test.zsh && ./scripts/build_aby.zsh && python3 ./scripts/aby_tests/c_test_aby.py clean: # remove all generated files diff --git a/scripts/aby_tests/__pycache__/test_suite.cpython-38.pyc b/scripts/aby_tests/__pycache__/test_suite.cpython-38.pyc index e51c065199496c5265823893900f301efa497fa6..c99313e14373206bd43a4630539b7612d4032f17 100644 GIT binary patch delta 704 zcmYjP&ui2`6mDFhNhXg^Wep!cyW@^-}~P8zBe;3>rWT)Ez{IT#QAdl z2K}?}9^V;NCZTGP676(gd-Sr*c+wiEZDlGi^%Eans85vHEQ1-%fQI&3IhSQR3u4#X zOsLO6)h|F|R^hI08>w^C<1rCc(u7S^fq^~+byS0II)*p;7#u+h%3P*kW(vN?xf}Or z03K?>8m?OVs1*N-Hk9*%UxS{3;jwW_naSOJG!T3?mZh5(iyt!XxnTsC%;kcDhTtQC zzBQXeGz@)@1}+UcFpgJ-0umL}X9AqhXZ*q#{^44-oE^|;%WWO%U9+xAD?1i~U29q@ zwZnkNIa7c&ShbHA_h+!!b0bfdw(Tpj`>%~aE6*xtvymrg6wxi0C;b$!WFZk9Bo~_K>LV3#&55-6UwoLR;pD_gFU`68ns|i}>A0M8sc>$cNSO-O_&mq~OW` delta 805 zcmY*YL5tHs6yBjOO(w~tX)8iqFbfu{ZndeqD6U;7D}u0s9#$~0#%wpGfwa-gR5748 zLGj>WL_8?ENAaXy1QER~o)+0(pm-N=o;;Y$o62rZ$@jkZ-uJ%ua^HE{CaZ>lr?Thg z^^5-1_FJ-6L=A2cTk$tGJQh&K9~YM;M91p@{VDd)5y2XcBbHdKdIV{4k#74|Pp;c%pZN-dPf|+aV3S zH~~q2^^Tyr#)KLeO9FX86vZD&r@k3ok$+UyTO?g{GSk%9qvs8&XS45+mSiFGJZk02 zOTBnRndc`V8$jPJvtDpgu<)aaWx|%Z1Xf!i3%n#?-g+EIkkKlggJR|+7LH&+FH22y zTp0ALq|OL-O1eqn-?6h2cE0Mg(8f**q^6}F1X6h=j&Im>JhX*AyJt#);!#d5e;DF>Hd|V&o|2z-YK7v_ms#Ozg9lL-<8jTa&A^8F4rm#;Lg;n z^(~n2Yvobjl~(L;)_>f$KVE@9Fik9sVO;moM3(LvZ3-efs=7}6dP SUr!~q?1xBd?>|(x3;zI500N}| diff --git a/scripts/aby_tests/__pycache__/utils.cpython-38.pyc b/scripts/aby_tests/__pycache__/utils.cpython-38.pyc index 9d7d01d8a908ca94769c0051505d1faf9ae981cc..f685fd98ce8e3ed939a86b7890565994b90e40c8 100644 GIT binary patch literal 3746 zcma)9Pj4H?72nxE%_3fU`2)7fb=iuukZr|&9 z6I!iT6BmRhYR_1&F6zR6X7zm05COgo8OWw+KDR|nw4b@XmTc2c%sqF+yy$>32Rx9T zY@f5l8BiC*BB=AHs7vBCP&;O|nLAz~&xqyco>&oQ!Ce5?lL6$M!+z(*>!2+P`<~T( z;}GYux_0H=%?2{9+`Av&y|dnBmHX>B*N0cZj2KOsJT&(3euy`J4?x2fdyH9{J+Sv3 zVGF0UmaJv#U`lfjtRt>lTEbfapSYri{p-VX{Nps%ahSwI$p4Uh*ZI)>@=AXHCF3ude@F_gcfHCRs5sS?lketLE!QF|bmcu!v6hv$ zl@$3-m-X5@%MwW5coGY}^TJZNY3t>?t3|GEuI^-gxhfw-J2G93G9g!^SVgOOq~d|j zSHsQS4YT=bq2naKG1#rn#L#GCs__Qol9S{J9l3)@6W_GPM1n&u_Dwcd3V`K)RZXc1@=pfk;Yd7#x|F%Y4aCzPeh zxeH*~Ev6Rm{cc6+7_*8_)LY^oCRu*^*6jPide=Fv+pE;-$W)xriL}UV0Lxa3fbdH< zRNJ^wC3T_F6Rt?QAGzYYK(?(BE3JL&!1|?i|MG9`kv(!sw$HR(+Iz;p6U-T7k6I;z z3$o!w{!tQYEmJPyNXJSpP!@bqOmg_O|*V?R%NP6#}o` zJW67OA#F~RrkhiOMD}ro%%jSePX{v6QdGgQs#S2ja%?XXbXZ3Z1uyx7x!AXm%wQ!r zt6&e^d`ZJ{d+aL)8eG=Uu7ZZ~SFE&!dk%Dh5AFO@(7iEj1(|ha!dbCs?(nY^0@~4z zsQ?rtM@Hz0*{u~&*=*;?|1Jez=V`Fn%4Hucrd75dy6F!z)rdhGQ!x5YX z<b&OxSHQgN8)U`0gmhGu`jnOyp8H`sd)QIu^nZ;JEWYVbfd_&y=Ij4`zXB;%12cbk}6~6A^pXJs&VIOBnPyr z+f-dz@)m&~6S!s;kIz6UK7yoi02yRPsor!9yYyyGb2J9MV)ArU`l?7xHlqm4DIZuU zxl8sn+eTWQLrrU$m&O;^1y*AVwt5G%a6^>yD$kVj6N!TYzk$~TV+Rg^ih|NSLR*8N zL5o8PtaQ)AWzo{ugrU-Wi_q~#HE?SPQX4M*D}-LRU&M#QC?LqY$5^ea-R~PJlLbf4;O2 zCLt=C2)S0c2(ttnk1-$WOp@?T$-{A}%(i$4!kCBpiA%b{Wf<*nnT*?*IOP;Irm#*I z8+mWv;FLtE-GWDPNFpgb3Uj%}$>Gv%Gw&x5I7zd7?CmGmKP9$|3LS1H=uA+-POyJ= zgHHnMC@HL&s{dt*IKIzs@yB6ONVC&BH>P3t{d3iI_{|};Bg3m>y|Z*H-Y!%~r$O8+ z$)BhUz3f(|%*occNimB0#X}0XL#hh})vMb_CLDwaOu_&8{P)94FdGRWuocD$$VUds z*Mi1%K6DALcRQx-RI89wHDrp^2Q8$!30$2eKy}=dO+~>|c?x}kR4YWK2&tSf-8CJd zX~GnRMCCrn;YW*DVS;djt}gF2vDpS%H5JRe*E(vA<20(6?zyDzOrkLT z$8ol35gV)XBGGxp;?oh|m_~g50k+R6!&nWM(XWHw1?ICBg+2n_#b_Blcz_h(vl>BL zy^r}_rs$5kOQ_JrCZ!_$**H#jrfKcf&@RE-6x~PV>KOK;mh0FeDEH_S(W{|5H0|3f z&FXIA--a=$*?Q(Urok|smj8=>CW=J9N7W{$%juY7_;yhDJ>Tv43+}SB>|8wmU%x|$ Axc~qF delta 921 zcmZva&ui3B5XUpgOPWnL+w6~ayS8gj3ZeEFSWu~+JP8(mAmV~uw)^qzF1MTaYdd_ zdB{uDE%6y1@$wP0rg(){kE~Y2YkZnwncGjTxc&8EonA+^ zJGd(|c$LBasf9)T8#ZnhO+$$^?|EdE`Gsr-5tQh~64hcSW8$^wqG6$@-?667+_?v5 z_7Y~WN+CHNIZthzGM?O6G+8boWm&X6OnSU61?~%MclWqKOPj<3{gy2da{hi~oUn!! zidZ#LGjchq+e<{M4600~a}?I~9d8-D&x!XP{LGVz_lHV9@_$9M2GuZf#mJm~Qh3}L zL;E;P+e%1P(_adU>>3$$9kx7+*6VHR_YhZOH**J=q$+ddfyAbg?;O}f!mvBa5rYSNZp)?H%zu< int - 1", 0, - "./third_party/ABY/build/bin/2pc_int_greater_than_zok_test", + "./third_party/ABY/build/bin/2pc_int_greater_than", {"a": 5, "b": 0}, {"a": 0, "b": 7}, ], [ "Test int > int - 2", 0, - "./third_party/ABY/build/bin/2pc_int_greater_than_zok_test", + "./third_party/ABY/build/bin/2pc_int_greater_than", {"a": 7, "b": 0}, {"a": 0, "b": 7}, ], [ "Test int > int - 3", 1, - "./third_party/ABY/build/bin/2pc_int_greater_than_zok_test", + "./third_party/ABY/build/bin/2pc_int_greater_than", {"a": 8, "b": 0}, {"a": 0, "b": 7}, ], [ "Test int >= int - 1", 1, - "./third_party/ABY/build/bin/2pc_int_greater_equals_zok_test", + "./third_party/ABY/build/bin/2pc_int_greater_equals", {"a": 8, "b": 0}, {"a": 0, "b": 7}, ], [ "Test int >= int - 2", 1, - "./third_party/ABY/build/bin/2pc_int_greater_equals_zok_test", + "./third_party/ABY/build/bin/2pc_int_greater_equals", {"a": 7, "b": 0}, {"a": 0, "b": 7}, ], [ "Test int >= int - 3", 0, - "./third_party/ABY/build/bin/2pc_int_greater_equals_zok_test", + "./third_party/ABY/build/bin/2pc_int_greater_equals", {"a": 6, "b": 0}, {"a": 0, "b": 7}, ], [ "Test int < int - 1", 0, - "./third_party/ABY/build/bin/2pc_int_less_than_zok_test", + "./third_party/ABY/build/bin/2pc_int_less_than", {"a": 7, "b": 0}, {"a": 0, "b": 2}, ], [ "Test int < int - 2", 0, - "./third_party/ABY/build/bin/2pc_int_less_than_zok_test", + "./third_party/ABY/build/bin/2pc_int_less_than", {"a": 7, "b": 0}, {"a": 0, "b": 7}, ], [ "Test int < int - 3", 1, - "./third_party/ABY/build/bin/2pc_int_less_than_zok_test", + "./third_party/ABY/build/bin/2pc_int_less_than", {"a": 2, "b": 0}, {"a": 0, "b": 7}, ], [ "Test int <= int - 1", 1, - "./third_party/ABY/build/bin/2pc_int_less_equals_zok_test", + "./third_party/ABY/build/bin/2pc_int_less_equals", {"a": 7, "b": 0}, {"a": 0, "b": 8}, ], [ "Test int <= int - 2", 1, - "./third_party/ABY/build/bin/2pc_int_less_equals_zok_test", + "./third_party/ABY/build/bin/2pc_int_less_equals", {"a": 7, "b": 0}, {"a": 0, "b": 7}, ], [ "Test int <= int - 3", 0, - "./third_party/ABY/build/bin/2pc_int_less_equals_zok_test", + "./third_party/ABY/build/bin/2pc_int_less_equals", {"a": 8, "b": 0}, {"a": 0, "b": 7}, ], [ "Test int == int - 1", 0, - "./third_party/ABY/build/bin/2pc_int_equals_zok_test", + "./third_party/ABY/build/bin/2pc_int_equals", {"a": 7, "b": 0}, {"a": 0, "b": 8}, ], [ "Test int == int - 2", 1, - "./third_party/ABY/build/bin/2pc_int_equals_zok_test", + "./third_party/ABY/build/bin/2pc_int_equals", {"a": 12, "b": 0}, {"a": 0, "b": 12}, ], @@ -185,7 +185,7 @@ nary_arithmetic_tests = [ [ "Test a + b + c", 6, - "./third_party/ABY/build/bin/2pc_nary_arithmetic_add_zok_test", + "./third_party/ABY/build/bin/2pc_nary_arithmetic_add", {"a": 1, "b": 0, "c": 0}, {"a": 0, "b": 2, "c": 3}, ], @@ -195,84 +195,84 @@ bitwise_tests = [ [ "Bitwise & - 1", 0, - "./third_party/ABY/build/bin/2pc_bitwise_and_zok_test", + "./third_party/ABY/build/bin/2pc_bitwise_and", {"a": 0, "b": 0}, {"a": 0, "b": 0}, ], [ "Bitwise & - 2", 0, - "./third_party/ABY/build/bin/2pc_bitwise_and_zok_test", + "./third_party/ABY/build/bin/2pc_bitwise_and", {"a": 1, "b": 0}, {"a": 0, "b": 0}, ], [ "Bitwise & - 3", 0, - "./third_party/ABY/build/bin/2pc_bitwise_and_zok_test", + "./third_party/ABY/build/bin/2pc_bitwise_and", {"a": 0, "b": 0}, {"a": 0, "b": 1}, ], [ "Bitwise & - 4", 1, - "./third_party/ABY/build/bin/2pc_bitwise_and_zok_test", + "./third_party/ABY/build/bin/2pc_bitwise_and", {"a": 1, "b": 0}, {"a": 0, "b": 1}, ], [ "Bitwise | - 1", 0, - "./third_party/ABY/build/bin/2pc_bitwise_or_zok_test", + "./third_party/ABY/build/bin/2pc_bitwise_or", {"a": 0, "b": 0}, {"a": 0, "b": 0}, ], [ "Bitwise | - 2", 1, - "./third_party/ABY/build/bin/2pc_bitwise_or_zok_test", + "./third_party/ABY/build/bin/2pc_bitwise_or", {"a": 1, "b": 0}, {"a": 0, "b": 0}, ], [ "Bitwise | - 3", 1, - "./third_party/ABY/build/bin/2pc_bitwise_or_zok_test", + "./third_party/ABY/build/bin/2pc_bitwise_or", {"a": 0, "b": 0}, {"a": 0, "b": 1}, ], [ "Bitwise | - 4", 1, - "./third_party/ABY/build/bin/2pc_bitwise_or_zok_test", + "./third_party/ABY/build/bin/2pc_bitwise_or", {"a": 1, "b": 0}, {"a": 0, "b": 1}, ], [ "Bitwise ^ - 1", 0, - "./third_party/ABY/build/bin/2pc_bitwise_xor_zok_test", + "./third_party/ABY/build/bin/2pc_bitwise_xor", {"a": 0, "b": 0}, {"a": 0, "b": 0}, ], [ "Bitwise ^ - 2", 1, - "./third_party/ABY/build/bin/2pc_bitwise_xor_zok_test", + "./third_party/ABY/build/bin/2pc_bitwise_xor", {"a": 1, "b": 0}, {"a": 0, "b": 0}, ], [ "Bitwise ^ - 3", 1, - "./third_party/ABY/build/bin/2pc_bitwise_xor_zok_test", + "./third_party/ABY/build/bin/2pc_bitwise_xor", {"a": 0, "b": 0}, {"a": 0, "b": 1}, ], [ "Bitwise ^ - 4", 0, - "./third_party/ABY/build/bin/2pc_bitwise_xor_zok_test", + "./third_party/ABY/build/bin/2pc_bitwise_xor", {"a": 1, "b": 0}, {"a": 0, "b": 1}, ], @@ -282,70 +282,70 @@ boolean_tests = [ [ "Boolean && - 1", 0, - "./third_party/ABY/build/bin/2pc_boolean_and_zok_test", + "./third_party/ABY/build/bin/2pc_boolean_and", {"a": 0, "b": 0}, {"a": 0, "b": 0}, ], [ "Boolean && - 2", 0, - "./third_party/ABY/build/bin/2pc_boolean_and_zok_test", + "./third_party/ABY/build/bin/2pc_boolean_and", {"a": 1, "b": 0}, {"a": 0, "b": 0}, ], [ "Boolean && - 3", 0, - "./third_party/ABY/build/bin/2pc_boolean_and_zok_test", + "./third_party/ABY/build/bin/2pc_boolean_and", {"a": 0, "b": 0}, {"a": 0, "b": 1}, ], [ "Boolean && - 4", 1, - "./third_party/ABY/build/bin/2pc_boolean_and_zok_test", + "./third_party/ABY/build/bin/2pc_boolean_and", {"a": 1, "b": 0}, {"a": 0, "b": 1}, ], [ "Boolean || - 1", 0, - "./third_party/ABY/build/bin/2pc_boolean_or_zok_test", + "./third_party/ABY/build/bin/2pc_boolean_or", {"a": 0, "b": 0}, {"a": 0, "b": 0}, ], [ "Boolean || - 2", 1, - "./third_party/ABY/build/bin/2pc_boolean_or_zok_test", + "./third_party/ABY/build/bin/2pc_boolean_or", {"a": 1, "b": 0}, {"a": 0, "b": 0}, ], [ "Boolean || - 3", 1, - "./third_party/ABY/build/bin/2pc_boolean_or_zok_test", + "./third_party/ABY/build/bin/2pc_boolean_or", {"a": 0, "b": 0}, {"a": 0, "b": 1}, ], [ "Boolean || - 4", 1, - "./third_party/ABY/build/bin/2pc_boolean_or_zok_test", + "./third_party/ABY/build/bin/2pc_boolean_or", {"a": 1, "b": 0}, {"a": 0, "b": 1}, ], [ "Boolean == - 1", 0, - "./third_party/ABY/build/bin/2pc_boolean_equals_zok_test", + "./third_party/ABY/build/bin/2pc_boolean_equals", {"a": 0, "b": 0}, {"a": 0, "b": 1}, ], [ "Boolean == - 2", 1, - "./third_party/ABY/build/bin/2pc_boolean_equals_zok_test", + "./third_party/ABY/build/bin/2pc_boolean_equals", {"a": 1, "b": 0}, {"a": 0, "b": 1}, ], @@ -355,14 +355,14 @@ nary_boolean_tests = [ [ "Test a & b & c - 1", 0, - "./third_party/ABY/build/bin/2pc_nary_boolean_and_zok_test", + "./third_party/ABY/build/bin/2pc_nary_boolean_and", {"a": 1, "b": 0, "c": 0}, {"a": 0, "b": 1, "c": 0}, ], [ "Test a & b & c - 2", 1, - "./third_party/ABY/build/bin/2pc_nary_boolean_and_zok_test", + "./third_party/ABY/build/bin/2pc_nary_boolean_and", {"a": 1, "b": 0, "c": 0}, {"a": 0, "b": 1, "c": 1}, ], @@ -373,7 +373,7 @@ const_arith_tests = [ [ "Test add client int + server int to const value", 6, - "./third_party/ABY/build/bin/2pc_const_arith_zok_test", + "./third_party/ABY/build/bin/2pc_const_arith", {"a": 2, "b": 0}, {"a": 0, "b": 3}, ], @@ -383,14 +383,14 @@ const_bool_tests = [ [ "Test server value == const value - 1", 0, - "./third_party/ABY/build/bin/2pc_const_bool_zok_test", + "./third_party/ABY/build/bin/2pc_const_bool", {"a": 0, "b": 0}, {"a": 0, "b": 0}, ], [ "Test server value == const value - 2", 1, - "./third_party/ABY/build/bin/2pc_const_bool_zok_test", + "./third_party/ABY/build/bin/2pc_const_bool", {"a": 1, "b": 0}, {"a": 0, "b": 0}, ], @@ -400,28 +400,28 @@ ite_tests = [ [ "Test ite ret bool - 1", 0, - "./third_party/ABY/build/bin/2pc_ite_ret_bool_zok_test", + "./third_party/ABY/build/bin/2pc_ite_ret_bool", {"a": 0, "b": 0, "sel": 1}, {"a": 0, "b": 1, "sel": 1}, ], [ "Test ite ret bool - 2", 1, - "./third_party/ABY/build/bin/2pc_ite_ret_bool_zok_test", + "./third_party/ABY/build/bin/2pc_ite_ret_bool", {"a": 0, "b": 0, "sel": 0}, {"a": 0, "b": 1, "sel": 0}, ], [ "Test ite ret int - 1", 32, - "./third_party/ABY/build/bin/2pc_ite_ret_int_zok_test", + "./third_party/ABY/build/bin/2pc_ite_ret_int", {"a": 32, "b": 0, "sel": 1}, {"a": 0, "b": 45, "sel": 1}, ], [ "Test ite ret int - 2", 45, - "./third_party/ABY/build/bin/2pc_ite_ret_int_zok_test", + "./third_party/ABY/build/bin/2pc_ite_ret_int", {"a": 32, "b": 0, "sel": 0}, {"a": 0, "b": 45, "sel": 0}, ], @@ -431,14 +431,14 @@ arr_tests = [ [ "Array sum test", 3, - "./third_party/ABY/build/bin/2pc_array_sum_zok_test", + "./third_party/ABY/build/bin/2pc_array_sum", {"a": 2, "b": 0}, {"a": 0, "b": 1}, ], [ "Array ret test", "2\n1", - "./third_party/ABY/build/bin/2pc_array_ret_zok_test", + "./third_party/ABY/build/bin/2pc_array_ret", {"a": 2, "b": 0}, {"a": 0, "b": 1}, ], @@ -448,14 +448,14 @@ loop_tests = [ [ "Loop sum const - 1", 10, - "./third_party/ABY/build/bin/2pc_loop_sum_zok_test", + "./third_party/ABY/build/bin/2pc_loop_sum", {"a": 2, "b": 0}, {"a": 0, "b": 1}, ], [ "Loop sum const - 2", 10, - "./third_party/ABY/build/bin/2pc_loop_sum_zok_test", + "./third_party/ABY/build/bin/2pc_loop_sum", {"a": 10, "b": 0}, {"a": 0, "b": 3}, ], @@ -465,14 +465,14 @@ function_tests = [ [ "Sum() two numbers - 1", 3, - "./third_party/ABY/build/bin/2pc_function_sum_zok_test", + "./third_party/ABY/build/bin/2pc_function_sum", {"a": 1, "b": 0}, {"a": 0, "b": 2}, ], [ "Sum() two numbers - 2", 2, - "./third_party/ABY/build/bin/2pc_function_sum_zok_test", + "./third_party/ABY/build/bin/2pc_function_sum", {"a": 0, "b": 0}, {"a": 0, "b": 2}, ], @@ -483,35 +483,35 @@ shift_tests = [ [ "Left Shift a by 1 - 1", 20, - "./third_party/ABY/build/bin/2pc_lhs_zok_test", + "./third_party/ABY/build/bin/2pc_lhs", {"a": 10, "b": 0}, {"a": 0, "b": 2}, ], [ "Left Shift a by 1 - 2", 0, - "./third_party/ABY/build/bin/2pc_lhs_zok_test", + "./third_party/ABY/build/bin/2pc_lhs", {"a": 0, "b": 0}, {"a": 0, "b": 2}, ], [ "Left Shift a by 1 - 3", 0, - "./third_party/ABY/build/bin/2pc_lhs_zok_test", + "./third_party/ABY/build/bin/2pc_lhs", {"a": 2147483648, "b": 0}, {"a": 0, "b": 2}, ], [ "Right Shift a by 1 - 1", 10, - "./third_party/ABY/build/bin/2pc_rhs_zok_test", + "./third_party/ABY/build/bin/2pc_rhs", {"a": 20, "b": 0}, {"a": 0, "b": 2}, ], [ "Right Shift a by 1 - 2", 0, - "./third_party/ABY/build/bin/2pc_rhs_zok_test", + "./third_party/ABY/build/bin/2pc_rhs", {"a": 0, "b": 0}, {"a": 0, "b": 2}, ], @@ -521,28 +521,28 @@ misc_tests = [ [ "Millionaire's problem: server has more money than client", 0, - "./third_party/ABY/build/bin/2pc_millionaire_zok_test", + "./third_party/ABY/build/bin/2pc_millionaire", {"a": 2, "b": 0}, {"a": 0, "b": 1}, ], [ "Millionaire's problem: server has equal money to client", 0, - "./third_party/ABY/build/bin/2pc_millionaire_zok_test", + "./third_party/ABY/build/bin/2pc_millionaire", {"a": 1, "b": 0}, {"a": 0, "b": 1}, ], [ "Millionaire's problem: server has less money than client", 1, - "./third_party/ABY/build/bin/2pc_millionaire_zok_test", + "./third_party/ABY/build/bin/2pc_millionaire", {"a": 1, "b": 0}, {"a": 0, "b": 2}, ], [ "Conversion problem", 7, - "./third_party/ABY/build/bin/2pc_conv_zok_test", + "./third_party/ABY/build/bin/2pc_conv", {"a": 0, "b": 0}, {"a": 0, "b": 7}, ], diff --git a/scripts/aby_tests/utils.py b/scripts/aby_tests/utils.py index 4e6f5ee1..71707c5c 100644 --- a/scripts/aby_tests/utils.py +++ b/scripts/aby_tests/utils.py @@ -3,14 +3,34 @@ import sys from typing import List import time +def init_progress_bar(toolbar_width=40): + ''' Initialize progress bar ''' + print("Running ABY unit tests") + sys.stdout.write("[%s]" % (" " * toolbar_width)) + sys.stdout.flush() + sys.stdout.write("\b" * (toolbar_width+1)) + +def update_progress_bar(): + ''' Increment progress bar ''' + sys.stdout.write("=") + sys.stdout.flush() + +def end_progress_bar(): + ''' Close progress bar ''' + sys.stdout.write("]\n") # this ends the progress bar + def flatten_args(args: dict) -> list: - ''' flatten dictionary into list ''' + ''' Flatten dictionary into list ''' flat_args = [] for k, v in args.items(): flat_args.append(str(k)) flat_args.append(str(v)) return flat_args +def update_path(path: str, lang: str) -> str: + '''Append path with language type''' + return f'{path}_{lang}_test' + def build_server_cmd(exec: str, args: dict) -> List[str]: return [exec, "-r", "0", "-i"] + flatten_args(args) @@ -43,16 +63,39 @@ def run_test(desc: str, expected: str, server_cmd: List[str], client_cmd: List[s # print("Exception: ", e) return False +def run_tests(lang: str, tests: List[dict]): + ''' + tests will be a list of all tests to run. each element in the list will be + 1. description of test case: string + 2. expected output: string + 3. executable path: string + 4. server arguments: dict[name] = value + 5. client arguments: dict[name] = value + ''' + failed_test_descs = [] + num_retries = 3 + progress_inc = 5 + init_progress_bar(len(tests) // progress_inc) + for t, test in enumerate(tests): + assert len(test) == 5, "test configurations are wrong for test: "+test[0] + desc = test[0] + expected = str(test[1]) + path = update_path(test[2], lang) + server_cmd = build_server_cmd(path, test[3]) + client_cmd = build_client_cmd(path, test[4]) -def init_progress_bar(toolbar_width=40): - print("Running ABY unit tests") - sys.stdout.write("[%s]" % (" " * toolbar_width)) - sys.stdout.flush() - sys.stdout.write("\b" * (toolbar_width+1)) + test_results = [] + for i in range(num_retries): + test_results.append(run_test(desc, expected, server_cmd, client_cmd)) + + if not any(test_results): + failed_test_descs.append(desc) -def update_progress_bar(): - sys.stdout.write("=") - sys.stdout.flush() + if t % progress_inc == 0: + update_progress_bar() + end_progress_bar() + + if len(failed_test_descs) == 0: + print("All tests passed ✅") -def end_progress_bar(): - sys.stdout.write("]\n") # this ends the progress bar \ No newline at end of file + assert len(failed_test_descs) == 0, "there were failed test cases:\n\t- " + "\n\t- ".join(failed_test_descs) \ No newline at end of file diff --git a/scripts/aby_tests/zokrates_test_aby.py b/scripts/aby_tests/zokrates_test_aby.py index cbcf585b..bbd1b1f8 100755 --- a/scripts/aby_tests/zokrates_test_aby.py +++ b/scripts/aby_tests/zokrates_test_aby.py @@ -1,13 +1,7 @@ -from utils import * -from zokrates_test_suite import * +from utils import run_tests +from test_suite import * -def run_tests(): - # tests will be a list of all tests to run. each element in the list will be - # 1. description of test case: string - # 2. expected output: string - # 3. executable path: string - # 4. server arguments: dict[name] = value - # 5. client arguments: dict[name] = value +if __name__ == "__main__": tests = arithmetic_tests + \ arithmetic_boolean_tests + \ nary_arithmetic_tests + \ @@ -23,33 +17,4 @@ def run_tests(): misc_tests # arr_tests + \ - failed_test_descs = [] - num_retries = 3 - progress_inc = 5 - init_progress_bar(len(tests) // progress_inc) - for t, test in enumerate(tests): - assert len(test) == 5, "test configurations are wrong for test: "+test[0] - desc = test[0] - expected = str(test[1]) - path = test[2] - server_cmd = build_server_cmd(path, test[3]) - client_cmd = build_client_cmd(path, test[4]) - - test_results = [] - for i in range(num_retries): - test_results.append(run_test(desc, expected, server_cmd, client_cmd)) - - if not any(test_results): - failed_test_descs.append(desc) - - if t % progress_inc == 0: - update_progress_bar() - end_progress_bar() - - if len(failed_test_descs) == 0: - print("All tests passed ✅") - - assert len(failed_test_descs) == 0, "there were failed test cases:\n\t- " + "\n\t- ".join(failed_test_descs) - -if __name__ == "__main__": - run_tests() + run_tests('zok', tests) diff --git a/scripts/build_mpc_c_test.zsh b/scripts/build_mpc_c_test.zsh index ef297b7d..cec3742e 100755 --- a/scripts/build_mpc_c_test.zsh +++ b/scripts/build_mpc_c_test.zsh @@ -23,35 +23,35 @@ function mpc_test { RUST_BACKTRACE=1 measure_time $BIN -p $parties $zpath } -# # build mpc arithmetic tests -# mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_add.c -# mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_sub.c -# mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_mult.c -# mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_mult_add_pub.c +# build mpc arithmetic tests +mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_add.c +mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_sub.c +mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_mult.c +mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_mult_add_pub.c -# mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_int_equals.c -# mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_int_greater_than.c -# mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_int_greater_equals.c -# mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_int_less_than.c -# mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_int_less_equals.c +mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_int_equals.c +mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_int_greater_than.c +mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_int_greater_equals.c +mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_int_less_than.c +mpc_test 2 ./examples/C/mpc/unit_tests/arithmetic_tests/2pc_int_less_equals.c -# # build mpc nary arithmetic tests -# mpc_test 2 ./examples/C/mpc/unit_tests/nary_arithmetic_tests/2pc_nary_arithmetic_add.c +# build mpc nary arithmetic tests +mpc_test 2 ./examples/C/mpc/unit_tests/nary_arithmetic_tests/2pc_nary_arithmetic_add.c -# # build mpc bitwise tests -# mpc_test 2 ./examples/C/mpc/unit_tests/bitwise_tests/2pc_bitwise_and.c -# mpc_test 2 ./examples/C/mpc/unit_tests/bitwise_tests/2pc_bitwise_or.c -# mpc_test 2 ./examples/C/mpc/unit_tests/bitwise_tests/2pc_bitwise_xor.c +# build mpc bitwise tests +mpc_test 2 ./examples/C/mpc/unit_tests/bitwise_tests/2pc_bitwise_and.c +mpc_test 2 ./examples/C/mpc/unit_tests/bitwise_tests/2pc_bitwise_or.c +mpc_test 2 ./examples/C/mpc/unit_tests/bitwise_tests/2pc_bitwise_xor.c -# # build mpc boolean tests -# mpc_test 2 ./examples/C/mpc/unit_tests/boolean_tests/2pc_boolean_and.c -# mpc_test 2 ./examples/C/mpc/unit_tests/boolean_tests/2pc_boolean_or.c -# mpc_test 2 ./examples/C/mpc/unit_tests/boolean_tests/2pc_boolean_equals.c +# build mpc boolean tests +mpc_test 2 ./examples/C/mpc/unit_tests/boolean_tests/2pc_boolean_and.c +mpc_test 2 ./examples/C/mpc/unit_tests/boolean_tests/2pc_boolean_or.c +mpc_test 2 ./examples/C/mpc/unit_tests/boolean_tests/2pc_boolean_equals.c -# # build mpc nary boolean tests -# mpc_test 2 ./examples/C/mpc/unit_tests/nary_boolean_tests/2pc_nary_boolean_and.c +# build mpc nary boolean tests +mpc_test 2 ./examples/C/mpc/unit_tests/nary_boolean_tests/2pc_nary_boolean_and.c -# # build mpc const tests -# mpc_test 2 ./examples/C/mpc/unit_tests/const_tests/2pc_const_arith.c +# build mpc const tests +mpc_test 2 ./examples/C/mpc/unit_tests/const_tests/2pc_const_arith.c mpc_test 2 ./examples/C/mpc/unit_tests/const_tests/2pc_const_bool.c