pepper-project / pepper

A system for verifying outsourced computations. This repo always contains the latest release of the Pepper system.
Other
60 stars 16 forks source link

Private prover input on float numbers #4

Open fattaneh88 opened 5 years ago

fattaneh88 commented 5 years ago

Hi, I understand that to work with float numbers I need to write a code on SFDL. I also know pepper has a feature for private prover input like what we have in "apps_sfdl/genome_snp_freq.c". My question is how can I used the private prover input feature, and at the same type work with float numbers. I wrote a simple code:

program LR { //Constants //Dimention of inputs const SIZE = 3; //An upper bound for number of multiplication in exponentiation operations defined by a FOR LOOP const UPPER_B = 10000; //Precision const L = 3; //These two are defined based on L const TEN_P_L = 1000; const E_P_TEN_P_ML = 1.0010005;

//Types
type Param = struct {float<32,32>[SIZE] W, float<32,32>[1] B};
type Input = struct {float<32,32>[SIZE] X, hash_t WB};
type Output = struct {float P};

//Main method, called "output"
function Output output (Input In){
    var Param p;
hashget(&p, &(In.WB));

    var int<32> i;
    var float sum;
var float exp;
sum = 0;
exp = 1;

//Computing WX+B
    for (i = 0 to SIZE-1)
    sum = sum + In.X[i] * p.W[i];
    sum = sum + p.B[0];

//Appling precision L 
    sum = sum * TEN_P_L;

//Computing e^{WX+B}
    for (i = 1 to UPPER_B)
    if (sum >= i)
        exp = exp * E_P_TEN_P_ML;
    //Returning e^{WX+B} as the output
    output.P = exp;        
}

}

but I got the following error: LOG: Building executables

compile:

BUILD SUCCESSFUL Total time: 0 seconds make[1]: Leaving directory `/home/fara/pepper/compiler/frontend' WARNING: --cstdarithtruncate is disabled, so type errors will warn and arithmetic is not ANSI C compliant Compiling ../pepper/apps_sfdl/LR_S.sfdl java.text.ParseException: Unknown type hash_t at SFE.Compiler.SFECompiler.compileDataType(SFECompiler.java:670) at SFE.Compiler.SFECompiler.compileStructFields(SFECompiler.java:1041) at SFE.Compiler.SFECompiler.compileKnownType(SFECompiler.java:776) at SFE.Compiler.SFECompiler.compileDataType(SFECompiler.java:662) at SFE.Compiler.SFECompiler.compileType(SFECompiler.java:618) at SFE.Compiler.SFECompiler.compileTypeDeclarations(SFECompiler.java:575) at SFE.Compiler.SFECompiler.compileProgram(SFECompiler.java:334) at zcc.ZCC.compile(ZCC.java:207) at zcc.ZCC.main(ZCC.java:127) Error in line 15: Unknown type hash_t make: *** [apps_sfdl_gen/LR_S.cpp] Error 1

I appreciate if you can advise me on that. Thanks, Fattaneh

maxhowald commented 5 years ago

Unfortunately, constructs such as hashget and exo_compute which enable private prover input are only supported by the C compiler right now. If you need both, you'll need to port floats to C or these functions to SFDL.

I don't have much time to look at this myself, but if you or someone else are interested in taking it on, my recommendation would be to port floats to C in the pequin repository.

To do this, you'll need to modify the frontend part of the compiler in compiler/frontend, to parse float specifiers in .c files and generate the appropriate .circuit file. Probably, you'll want to write a simple floating-point program in both C and SFDL, compile the SFDL version with pepper, and then hack on the compiler in pequin until it can produce a matching .circuit file from the C version.

If you're interested in this and want more info or run in to problems, feel free to open more issues!

fattaneh88 commented 5 years ago

Thank you very much for your advice.

On Wed, Dec 26, 2018 at 1:10 PM Max Howald notifications@github.com wrote:

Unfortunately, constructs such as hashget and exo_compute which enable private prover input are only supported by the C compiler right now. If you need both, you'll need to port floats to C or these functions to SFDL.

I don't have much time to look at this myself, but if you or someone else are interested in taking it on, my recommendation would be to port floats to C in the pequin repository.

To do this, you'll need to modify the frontend part of the compiler in compiler/frontend, to parse float specifiers in .c files and generate the appropriate .circuit file. Probably, you'll want to write a simple floating-point program in both C and SFDL, compile the SFDL version with pepper, and then hack on the compiler in pequin until it can produce a matching .circuit file from the C version.

If you're interested in this and want more info or run in to problems, feel free to open more issues!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pepper-project/pepper/issues/4#issuecomment-450026883, or mute the thread https://github.com/notifications/unsubscribe-auth/AHfWZYsDTnasCai_zmuFCNNK4DbrMOdyks5u8-XbgaJpZM4ZdPCL .

-- F.B

fattaneh88 commented 5 years ago

Hi Max,

Thanks again for all your suggestion till know. I decided to add floating point implementation to C in the pequin repository. Based on my exploration, I think this is the place that I need to start adding my updates: https://github.com/pepper-project/pequin/blob/master/compiler/frontend/src/ccomp/parser_hw/CCompiler.java

I appreciate if I can get your comment on that.

Regards, Fattaneh

On Thu, Dec 27, 2018 at 6:50 PM Fattaneh Bayat fattaneh.bayat@gmail.com wrote:

Thank you very much for your advice.

  • Fattaneh

On Wed, Dec 26, 2018 at 1:10 PM Max Howald notifications@github.com wrote:

Unfortunately, constructs such as hashget and exo_compute which enable private prover input are only supported by the C compiler right now. If you need both, you'll need to port floats to C or these functions to SFDL.

I don't have much time to look at this myself, but if you or someone else are interested in taking it on, my recommendation would be to port floats to C in the pequin repository.

To do this, you'll need to modify the frontend part of the compiler in compiler/frontend, to parse float specifiers in .c files and generate the appropriate .circuit file. Probably, you'll want to write a simple floating-point program in both C and SFDL, compile the SFDL version with pepper, and then hack on the compiler in pequin until it can produce a matching .circuit file from the C version.

If you're interested in this and want more info or run in to problems, feel free to open more issues!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pepper-project/pepper/issues/4#issuecomment-450026883, or mute the thread https://github.com/notifications/unsubscribe-auth/AHfWZYsDTnasCai_zmuFCNNK4DbrMOdyks5u8-XbgaJpZM4ZdPCL .

-- F.B

-- F.B

maxhowald commented 5 years ago

Yes, that should be the right place to start. The float type specifier and float constant specifications should already by part of the grammar. You'll probably want to compare *.circuit files generated by the existing Pepper release from SFDL files with your implementation.