pepper-project / pequin

A system for verifying outsourced computations, and applying SNARKs. Simplified release of the main Pepper codebase.
Other
122 stars 46 forks source link

Example for exponential function? #11

Closed jasonge27 closed 6 years ago

jasonge27 commented 6 years ago

Do we have examples for evaluating exponential function? Can you give some hints on how to implement the exponential function in this framework efficiently? Thank you very much!

maxhowald commented 6 years ago

We don't have any examples of implementing the exponential function, but one way that is easy and efficient would be to use a fixed number of terms of the power series expanded around a point near the input. Even simpler, (but perhaps less accurate), expand around a fixed point (e.g. 0) so that you can calculate the coefficients in advance.

Anyway, another thing to keep in mind is that we only support use of floats in verifiable computations written in the SFDL language, not C. There are some example .sfdl files in the apps/ directory that should give you a pretty good idea of the syntax of the language, but if you want more information on SFDL specifically, you can check out https://www.cs.huji.ac.il/project/Fairplay/FairplayMP/SFDL2.0.pdf

So a simple exponential function would be just a couple of nested for loops to calculate the power series coefficients terms and add them up. Loops are required to have a compile-time constant bound, but that shouldn't be a problem in this case.

As for efficiency, because the exponential is a mathematical function approximated by a series of additions and multiplications, it is very amenable to a representation in constraints. Embedding floating point computations in a finite field has a small cost, though. For details on how the compiler does this embedding, see https://eprint.iacr.org/2012/598.pdf, appendix B.

jasonge27 commented 6 years ago

Thank you so much for your comment @maxhowald ! I found out a fixed point implementation of exp function that works pretty well in pequin. I'm posting the link here for anyone who may encounter similar problems https://sourceforge.net/p/fixedptc/code/ci/default/tree/fixedptc.h