tfhe / spqlios-arithmetic

spqlios arithmetic library for FHE and post-quantum crypto
Apache License 2.0
13 stars 0 forks source link

q120_ntt cmd prints & behavior documentation #25

Closed Pro7ech closed 3 months ago

Pro7ech commented 3 months ago

I'm trying to call spqlios-arithmetic from Go. I was able to reproduce the simple-fft example. However, when trying to do the same with q120_ntt.h, I run into the following issues:

Calling

prints in the command line:

NTT parameters:
        size = 1024
        logQ = 30
        input bit-size = 64
        level   1024 output bit-size = 63 (a_k.omega^k)
        level    512 output bit-size = 64
        reduce       output bit-size = 48
        level    256 output bit-size = 56
        level    128 output bit-size = 60
        level     64 output bit-size = 62
        level     32 output bit-size = 63
        level     16 output bit-size = 64
        reduce       output bit-size = 48
        level      8 output bit-size = 56
        level      4 output bit-size = 60
        level      2 output bit-size = 62
        level      1 output bit-size = 63
iNTT parameters:
        size = 1024
        logQ = 30
        input bit-size = 64
        reduce       output bit-size = 48
        level      1 output bit-size = 49
        level      2 output bit-size = 57
        level      4 output bit-size = 61
        level      8 output bit-size = 63
        level     16 output bit-size = 64
        reduce       output bit-size = 48
        level     32 output bit-size = 56
        level     64 output bit-size = 60
        level    128 output bit-size = 62
        level    256 output bit-size = 63
        level    512 output bit-size = 64
        reduce       output bit-size = 48
        level   1024 output bit-size = 55
Input 0.000000 64
Iter 1024 - 0.000000 63
Iter   1 - 62.317033 63
Input 62.317033 64
Iter 1024 - 54.536322 55
Input 61.992309 64
Iter 1024 - 60.720435 63
Iter   1 - 62.324599 63
Input 62.324599 64
Iter 1024 - 54.425796 55

And the output vectors of q120_ntt_bb_avx2 and q120_intt_bb_avx2 for zero inputs are non-zero. It turns out that they are not reduced modulo their respective Q1, Q2, Q3, Q4 primes and can be in the range [0, 2^{63}-1], which is not documented in q120_ntt.h.

ssmiler commented 3 months ago

These logs are only printed in debug mode. We shall remove them in future.

And the output vectors of q120_ntt_bb_avx2 and q120_intt_bb_avx2 for zero inputs are non-zero. It turns out that they are not reduced modulo their respective Q1, Q2, Q3, Q4 primes and can be in the range [0, 2^{63}-1], which is not documented in q120_ntt.h.

The q120 is in draft mode currently, so no much comments. This should change once we fully support q120 backend. NTT/INTT does only the strictly necessary reduction so that the 4 i64 do not overflow. It's up to the calling party to do the reduction as a function of whether this is needed.

Pro7ech commented 3 months ago

@ssmiler Is the q120 therefore currently by default in debug mode?

ssmiler commented 3 months ago

Not that I'm aware of. Last time I've compiled in release mode no ntt logs were shown. What compiler are you using?

Pro7ech commented 3 months ago

I'm on wsl with Ubuntu 22.04. This is the output of $ cmake ..

-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Compiling spqlios-fft version: 1.0.0
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/cc
-- Found gtest: I=/usr/include L=/usr/lib/x86_64-linux-gnu/libgtest.a,/usr/lib/x86_64-linux-gnu/libgtest_main.a
-- Found benchmark: I=/usr/local/include L=/usr/local/lib/libbenchmark.a
-- CANNOT FIND valgrind header: VALGRIND_DIR-NOTFOUND
-- /usr/lib/x86_64-linux-gnu/libgtest.a;/usr/lib/x86_64-linux-gnu/libgtest_main.a;pthread
-- Configuring done (1.8s)
-- Generating done (0.3s)
-- Build files have been written to: [...]/spqlios/build

There is no information about a release/debug mode in the readme, it states that calling cmake and then make will compile the shared library in optimized mode.

ssmiler commented 3 months ago

You're right. The default mode is debug. I've open a pr #26 to fix it.

Pro7ech commented 3 months ago

Should this issue be closed since #26 has been merged?

ssmiler commented 3 months ago

Yes, you can close it. Thx