lducas / FHEW

Other
218 stars 46 forks source link

Compilation warnings #19

Open Bktero opened 5 years ago

Bktero commented 5 years ago

Hello,

When I clone the repository and simply type 'make' in my terminal, I get a lot of scary warnings:

g++ -ansi -Wall -O3 -c distrib.cpp
In file included from distrib.h:4:0,
                 from distrib.cpp:2:
params.h:24:1: warning: this decimal constant is unsigned only in ISO C90
 const ZmodQ v_inverse = 3758096385; // 1/v mod Q
 ^~~~~
In file included from distrib.h:4:0,
                 from distrib.cpp:2:
params.h:17:36: warning: left shift count >= width of type [-Wshift-count-overflow]
 const long int Q = (long int) 1 << 32;
                                    ^~
g++ -ansi -Wall -O3 -c FFT.cpp
In file included from FFT.h:4:0,
                 from FFT.cpp:3:
params.h:24:1: warning: this decimal constant is unsigned only in ISO C90
 const ZmodQ v_inverse = 3758096385; // 1/v mod Q
 ^~~~~
params.h:17:36: warning: left shift count >= width of type [-Wshift-count-overflow]
 const long int Q = (long int) 1 << 32;
                                    ^~
g++ -ansi -Wall -O3 -c LWE.cpp
In file included from LWE.h:4:0,
                 from LWE.cpp:3:
params.h:24:1: warning: this decimal constant is unsigned only in ISO C90
 const ZmodQ v_inverse = 3758096385; // 1/v mod Q
 ^~~~~
params.h:17:36: warning: left shift count >= width of type [-Wshift-count-overflow]
 const long int Q = (long int) 1 << 32;
                                    ^~
g++ -ansi -Wall -O3 -c FHEW.cpp
In file included from FHEW.h:4:0,
                 from FHEW.cpp:3:
params.h:24:1: warning: this decimal constant is unsigned only in ISO C90
 const ZmodQ v_inverse = 3758096385; // 1/v mod Q
 ^~~~~
params.h:17:36: warning: left shift count >= width of type [-Wshift-count-overflow]
 const long int Q = (long int) 1 << 32;
                                    ^~
ar -q libfhew.a distrib.o FFT.o LWE.o FHEW.o
ar: creating libfhew.a
g++ -ansi -Wall -O3 -c cmd/common.cpp 
In file included from cmd/../LWE.h:4:0,
                 from cmd/common.cpp:3:
cmd/../params.h:24:1: warning: this decimal constant is unsigned only in ISO C90
 const ZmodQ v_inverse = 3758096385; // 1/v mod Q
 ^~~~~
cmd/../params.h:17:36: warning: left shift count >= width of type [-Wshift-count-overflow]
 const long int Q = (long int) 1 << 32;
                                    ^~
g++ -ansi -Wall -O3 -o cmd/gen cmd/gen.cpp common.o -L. -lfhew -lfftw3 
In file included from cmd/../LWE.h:4:0,
                 from cmd/gen.cpp:3:
cmd/../params.h:24:1: warning: this decimal constant is unsigned only in ISO C90
 const ZmodQ v_inverse = 3758096385; // 1/v mod Q
 ^~~~~
cmd/../params.h:17:36: warning: left shift count >= width of type [-Wshift-count-overflow]
 const long int Q = (long int) 1 << 32;
                                    ^~
g++ -ansi -Wall -O3 -o cmd/enc cmd/enc.cpp common.o -L. -lfhew -lfftw3 
In file included from cmd/../LWE.h:4:0,
                 from cmd/enc.cpp:3:
cmd/../params.h:24:1: warning: this decimal constant is unsigned only in ISO C90
 const ZmodQ v_inverse = 3758096385; // 1/v mod Q
 ^~~~~
cmd/../params.h:17:36: warning: left shift count >= width of type [-Wshift-count-overflow]
 const long int Q = (long int) 1 << 32;
                                    ^~
g++ -ansi -Wall -O3 -o cmd/nand cmd/nand.cpp common.o -L. -lfhew -lfftw3 
In file included from cmd/../FHEW.h:4:0,
                 from cmd/nand.cpp:3:
cmd/../params.h:24:1: warning: this decimal constant is unsigned only in ISO C90
 const ZmodQ v_inverse = 3758096385; // 1/v mod Q
 ^~~~~
cmd/../params.h:17:36: warning: left shift count >= width of type [-Wshift-count-overflow]
 const long int Q = (long int) 1 << 32;
                                    ^~
g++ -ansi -Wall -O3 -o cmd/dec cmd/dec.cpp common.o -L. -lfhew -lfftw3 
In file included from cmd/../FHEW.h:4:0,
                 from cmd/dec.cpp:3:
cmd/../params.h:24:1: warning: this decimal constant is unsigned only in ISO C90
 const ZmodQ v_inverse = 3758096385; // 1/v mod Q
 ^~~~~
cmd/../params.h:17:36: warning: left shift count >= width of type [-Wshift-count-overflow]
 const long int Q = (long int) 1 << 32;
                                    ^~
g++ -ansi -Wall -O3 -o cmd/gate cmd/gate.cpp common.o -L. -lfhew -lfftw3 
In file included from cmd/../FHEW.h:4:0,
                 from cmd/gate.cpp:3:
cmd/../params.h:24:1: warning: this decimal constant is unsigned only in ISO C90
 const ZmodQ v_inverse = 3758096385; // 1/v mod Q
 ^~~~~
cmd/../params.h:17:36: warning: left shift count >= width of type [-Wshift-count-overflow]
 const long int Q = (long int) 1 << 32;
                                    ^~
g++ -ansi -Wall -O3 -o fhewTest fhewTest.cpp -L. -lfhew -lfftw3 
In file included from LWE.h:4:0,
                 from fhewTest.cpp:3:
params.h:24:1: warning: this decimal constant is unsigned only in ISO C90
 const ZmodQ v_inverse = 3758096385; // 1/v mod Q
 ^~~~~
params.h:17:36: warning: left shift count >= width of type [-Wshift-count-overflow]
 const long int Q = (long int) 1 << 32;
                                    ^~

Here are some details about my OS & compiler :

    Linux pierre-virtual 4.15.0-42-generic #45-Ubuntu SMP Thu Nov 15 19:32:10 UTC 2018 i686 i686 i686 GNU/Linux
    $ g++ --version
    g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
    Copyright (C) 2017 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Looking at closed issues, these problems have already arose on other platforms, other versions. Seems like it's still here. You should used types like std::uint64_t to enfore the sizes of your integers.

Regards, Bktero

Bktero commented 5 years ago
params.h:24:1: warning: this decimal constant is unsigned only in ISO C90
 const ZmodQ v_inverse = 3758096385; // 1/v mod Q

Adding a U at the end of the constant makes it unsigned ;)

Bktero commented 5 years ago

In params.h, I tried to replace all long ints with int64_ts and all ints with int32_t. Calling make no longer generates warnings.

Bktero commented 5 years ago

However, I can tell you about if the modifications still generates a correct software. Indeed, with or without my modifications, the tests fails on my machine. The output seems to be the same in both cases:

$ ./fhewTest 15
Setting up FHEW 
Generating secret key ...  Done.
Generating evaluation key ... this may take a while ...  Done.

Testing depth-2 homomorphic circuits 15 times.
Circuit shape : (a GATE NOT(b)) GATE (c GATE d)

       NOT  Enc(1) = Enc(0)
Enc(1) AND  Enc(0) = Enc(0)
Enc(1) NOR  Enc(1) = Enc(0)
Enc(0) OR   Enc(0) = ERROR: Please only use independant ciphertexts as inputs.
lducas commented 5 years ago

The error message above ( ERROR: Please only use independant ciphertexts as inputs.) is not normal behavior, but I can't reproduce the issue.

I'm shooting in the dark here, but maybe you can give a shot at commit #827dfbd ?

Bktero commented 5 years ago

I have updated my repository and switched to the type_bug. The code compiles fine 👍

The test still fails but now the cause is different:

$ ./fhewTest 15
Setting up FHEW 
Generating secret key ...  Done.
Generating evaluation key ... this may take a while ...  Done.

Testing depth-2 homomorphic circuits 15 times.
Circuit shape : (a GATE NOT(b)) GATE (c GATE d)

       NOT  Enc(1) = Enc(0)
Enc(1) AND  Enc(0) = Enc(3)

 ERROR: incorrect Homomorphic Gate computation at iteration 2
lducas commented 5 years ago

Darn.

Am I right to understand that you are running a 32 bit system ? I've only tested 64 bits systems...

Maybe there is another int with unspecified size somewhere beyond params.h and that is the source of all those issues. I can take a look, but since you have the possibility to test and I don't maybe it will be much easier for you...

Could be that the issue is at the interface with the FFTW library ?

lducas commented 5 years ago

Did you solved this in the end ?

Bktero commented 5 years ago

Sorry but this is very old... I don't remember to be honest :/