Implements the Task 2 (secure sin(x) for a fix point) and is designed to see how I manage basic coding and the documentation on SPDZ.
This is to test how well you can code using the SPDZ subsystem. See the attached draft document. It is a draft, so it could contain bugs. We would like an implementation of the sin(x) function for FIXED POINT x.
The solution is a standalone .mpc file that strictly follows the logic presented by the SPDZ documentation provided. As backup material, I have also followed [1] and [2] ([1] and [2] are basically the same). The sin functionality was implemented on the file:
-ssin.mpc (task 2.)
As requested, this is a generic implementation of ssin and contains a call and printing code for single fix point parameter that is written directly in the code. The method places the input (angle in radians) in-between [0,pi/2). From that moment on the algorithm evaluates the polynomial AS INDICATED and returns an sfix value containing the sin of x.
-
I made use of existing functionality currently present at the SPDZ repo.
-
Although papers such as [1] and [2] indicate the method could use PreMul functionality they are clear on mentioning that current state of the art only addresses the case where all inputs are integers smaller than p. They suggest the idea of what could be such a mechanism for fix point operations. This could be further discussed and added if requested.
-
The functionality is given in the form of a function, that can be called by the body of any program. Indeed, for my example, you just need to (on the same file) edit the function call and send any angle that you might want to calculate.
##Instructions:
1. Compile the exercise:
.. `./compile.py ssin`
2. Run the code following the instructions provided by SPDZ e.g.:
.. `Scripts/run-online.sh ssin`
3. In case you want to change the agle edit:
`angle= sfix(your_angle)`
You can reach me for questions at any time
[1]. Bayatbabolghani, Fattaneh, et al. "Secure Fingerprint Alignment and Matching Protocols." arXiv preprint arXiv:1702.03379 (2017). [2]. Bayatbabolghani, Fattaneh, et al. "Poster: Secure Computations of Trigonometric and Inverse Trigonometric Functions."
In the past days, becuase of the limitiations of current state of the art, I introduced a discussion about PreMul for fix point that might hold some relevance for ssin functionality. As noticed in the group, the best approach for an implementation of a PreMul for fix point would only work for small size arrays (4 elements) and small values, on the default SPDZ config. Although, it would still be proven to be innefective to accelerate the ssin implementation, I have taken the liberty to implement and test the PreMul mechanism to analyze its viability for our functionality just in case. The code of the PreMul is as follows:
def fPreMul(A):
B= Array(len(A),sfix)
C= Array(len(A),sint)
@for_range(len(A))
def f(i):
C[i]=A[i].v
C= comparison.PreMulC(C)
#@for_range(len(C))
#def f(i):
for i in range(len(C)):
B[i]=sfix(C[i].__rshift__((i)*(sfix.f), program.bit_length, program.security))
return B
The experimentation confirms the derived conclusions, the funcitonality works only on small size vectors. This also confirms what is stated in [1] and [2], singaling further research is needed to obtain a viable and efficient PreMul for fix point. Hence making it not adequate for our ssin funcitonality. I harbor hopes that further research could provide an adequate and efficient protocol.
Bug detected: Sign of the reult not correct on sections of the interval. It was corrected adding the expression -2 * s + 1 at the end of the function call. We have included the results of the automated tests as well: on the left hand sight the result generated by our secure sin implementation and on the other the corresponding sin value for the given angle, starting on 0.1 until 2 * \pi in 0.1 intervals:
sin is: 0.099830 0.0998334166468
sin is: 0.198663 0.198669330795
sin is: 0.295516 0.295520206661
sin is: 0.389413 0.389418342309
sin is: 0.479421 0.479425538604
sin is: 0.564639 0.564642473395
sin is: 0.644212 0.644217687238
sin is: 0.717352 0.7173560909
sin is: 0.783320 0.783326909627
sin is: 0.841466 0.841470984808
sin is: 0.891204 0.891207360061
sin is: 0.932032 0.932039085967
sin is: 0.963553 0.963558185417
sin is: 0.985445 0.985449729988
sin is: 0.997490 0.997494986604
sin is: 0.999566 0.999573603042
sin is: 0.991660 0.991664810452
sin is: 0.973841 0.973847630878
sin is: 0.946295 0.946300087687
sin is: 0.909293 0.909297426826
sin is: 0.863203 0.863209366649
sin is: 0.808489 0.80849640382
sin is: 0.745699 0.745705212177
sin is: 0.675460 0.675463180551
sin is: 0.598468 0.598472144104
sin is: 0.515493 0.515501371821
sin is: 0.427375 0.427379880234
sin is: 0.334985 0.334988150156
sin is: 0.239245 0.239249329214
sin is: 0.141117 0.14112000806
sin is: 0.041575 0.0415806624333
sin is: -0.058370 -0.0583741434276
sin is: -0.157740 -0.157745694143
sin is: -0.255537 -0.255541102027
sin is: -0.350778 -0.35078322769
sin is: -0.442515 -0.442520443295
sin is: -0.529832 -0.529836140908
sin is: -0.611853 -0.611857890943
sin is: -0.687760 -0.687766159184
sin is: -0.756797 -0.756802495308
sin is: -0.818273 -0.818277111064
sin is: -0.871569 -0.871575772414
sin is: -0.916160 -0.916165936749
sin is: -0.951598 -0.95160207389
sin is: -0.977525 -0.977530117665
sin is: -0.993685 -0.993691003633
sin is: -0.999916 -0.999923257564
sin is: -0.996161 -0.996164608836
sin is: -0.982447 -0.982452612624
sin is: -0.958917 -0.958924274663
sin is: -0.925811 -0.925814682328
sin is: -0.883448 -0.88345465572
sin is: -0.832262 -0.832267442224
sin is: -0.772759 -0.772764487556
sin is: -0.705536 -0.70554032557
sin is: -0.631262 -0.631266637872
sin is: -0.550681 -0.550685542598
sin is: -0.464598 -0.464602179414
sin is: -0.373872 -0.37387666483
sin is: -0.279412 -0.279415498199
sin is: -0.182159 -0.182162504272
sin is: -0.083087 -0.0830894028175