Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private prover input on float numbers #4

Open
fattaneh88 opened this issue Dec 21, 2018 · 4 comments
Open

Private prover input on float numbers #4

fattaneh88 opened this issue Dec 21, 2018 · 4 comments

Comments

@fattaneh88
Copy link

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 apps_sfdl/LR_S.sfdl --metrics --cql -b 0 -w 10240 -t ZAATAR -db-hash-func ggh -db-num-addresses 1024 -ram-cell-num-bits 32 -db-hash-num-bits 1216 -db-thr-num-addresses-naive 32768 -fast-ram-address-width 32 -fast-ram-word-width 64
    metric_num_lines_in_sfdl LR_S 38
    metric_num_lines_in_source LR_S 38
    make[1]: Entering directory `/home/fara/pepper/compiler/frontend'
    ant compile
    Buildfile: /home/fara/pepper/compiler/frontend/build.xml

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
Copy link
Contributor

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
Copy link
Author

fattaneh88 commented Dec 28, 2018 via email

@fattaneh88
Copy link
Author

fattaneh88 commented Jan 21, 2019 via email

@maxhowald
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants