Some questions about BFV and BGV

I tested the BFV mode and BGV mode in OpenFHE
They both use the same parameters and features
But in a certain arithmetic BFV is able to calculate the result while BGV is not. Is it because their two noise management is different, thus the ciphertext of BGV is corrupted by noise and cannot be decrypted? Also I would like to know if OpenFHE has a function that can look at the noise management? :smile:

Both BGV and BFV should work correctly as long as correct CryptoContextGen parameters are set. See openfhe-development/src/pke/examples at main · openfheorg/openfhe-development · GitHub for more details on CryptoContextGen parameters. The multiplicative depth you use during the CryptoContext generation should not be exceeded by your computation.

This is the set of parameters I chose for both BFV and BGV modes

    CCParams<CryptoContextBFVRNS> parameters;
    parameters.SetPlaintextModulus(65537);
    parameters.SetMultiplicativeDepth(2);

    std::cout << parameters << std::endl;

    CryptoContext<DCRTPoly> cryptoContext = GenCryptoContext(parameters);
    // Enable features that you wish to use
    cryptoContext->Enable(PKE);
    cryptoContext->Enable(KEYSWITCH);
    cryptoContext->Enable(LEVELEDSHE);

The plaintext is std::vector<int64_t> vectorOfInts1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
then performed an operation where I multiplied the ciphertext, which was encrypted from this plaintext, by itself four times, raising it to the fourth power.

BFV Result:( 1 16 81 256 625 1296 2401 4096 6561 10000 14641 20736 … )
BGV Result:( -3404 25733 -526 -8073 407 -23513 -11068 -26463 -30586 31881 13851 2602 -6905 19068 28724 -4322 21504 -13529 25809 -26181 -11641 -24085 -21351 -9138 10337 -16835 -28199 10838 27098 -1809 30203 4923 10806 20497 26212 18519 -20856 12330 24185 30107 -14008 -10797 -362 -17369 -11942 -468 -9193 10665 8231 -27020 17569 19149 -17597 -23829 12250 19305 -15057 11624 22344 6743 29128 29110 21878 -27307 10376 -13796 -26175 -11982 29006 25380 1318 -19044 9540 -7741 -20541 -30635 -24204 5463 -10815 27198 32198 -10465 -13933 31292 27983 -20561 -20389 32549 23329 -24754 -25021 5220 3314 -16071 9198 3835 8739 30976 -29434 32247 16495 -5292 21984 16483 25220 -18348 -11465 -2701 -5764 30923 12077 -3199 -2554 -10597 -24426 28912 28075 28021 14605 -2343 4988 -16206 28988 -3035 -11787 -13251 28834 10011 -24088 16210 -3581 8284 -29985 -25390 23800 -5601 22519 -11187 -5382 -761 20868 -17804 -11562 -22390 14282 -9721 23796 -10755 27512 -31308 20650 -30480 30764 14448 -956 -2969 -27338 29390 -17141 30328 3284 6858 12530 13154 -18207 -10085 5352 3718 -18134 28079 -31832 -11926 -1730 19450 -29588 -29277 -17872 24835 16250 -26681 -2605 25995 12246 -22892 7628 27644 -21596 26761 -4149 9552 7749 -10061 12679 4981 32204 -12731 22566 -3774 1025 5368 9232 -25441 -5650 14188 -17301 -3580 23056 -32486 -15031 -30239 20776 31807 -947 -7410 1317 -26328 15235 12618 -9652 9270 -6129 -13986 -26319 -4086 20326 -21031 22177 5277 24395 -11095 3293 -21695 -31024 -1910 24744 -29857 28513 17462 -27891 -27867 -11242 12866 -32298 -16902 19939 18285 -2464 9946 21462 -13956 -6272 -14467 -24918 -13651 -22414 25536 26324 -18250 -30819 -27564 211 -20679 -11692 -13839 27263 14164 5666 -3880 -17616 9180 14919 -6406 -13615 -5527 -4422 -11759 7486 -5935 -835 -14656 3374 -22938 18231 -8035 11499 -4507 -30674 -4082 21428 5089 -11957 7710 -25126 23431 -3424 12883 -4424 8915 10841 -23599 17170 32274 -12145 -2457 -13454 11103 -19530 18043 -31537 5455 9548 2572 -26842 -17183 30052 8254 -3757 -24654 11983 -25433 -27232 -2707 -17717 32068 -5483 17827 26315 -5834 206 -16234 -10133 -334 27016 1764 -10936 -29212 -2636 13527 17092 20317 9278 -16952 7384 3614 -19115 -21590 -1532 -8496 -22107 -27059 8508 17978 9685 21416 29102 -32242 3354 16058 27521 21749 -4582 17715 -22741 5578 31102 -14784 -1105 -28779 28674 9465 16771 27101 -29164 28945 -16749 20372 -1079 -9844 -10018 -25323 -5142 5858 26193 4975 -26242 25676 -23218 -30916 -13334 4085 21334 -27605 -22525 25796 -24566 28190 16497 -32644 3634 -16764 -30364 -16959 -23182 -7345 -9374 -6904 27547 6290 -16864 -15424 -17841 -7254 -16285 13541 -27715 19845 -12596 -28899 -31493 -30774 -13435 26223 -21604 16921 -15635 -32051 -11407 -28308 4150 -6500 -24734 -28012 -8112 6862 -25921 -19637 -10610 -28603 325 2907 -9077 12696 -25586 -1013 5809 -26017 17669 -15576 -22048 29461 -24628 32546 30732 -10236 -11649 -14154 31872 11310 17260 -13475 -18795 -26610 -17136 6094 -21327 -28475 4603 -28530 29765 25876 471 28451 -6324 -6453 -12507 32320 -806 26619 23629 8627 -24387 3519 -10511 -6096 -25196 2047 -13903 22256 -22303 27025 12554 9512 19659 1210 -31100 15475 -28306 20626 -28510 5638 31684 24023 -14972 -26524 10482 22299 -31836 -6832 -6559 6754 1287 13660 12143 -9422 -27332 -3498 -31546 -16755 -5336 -28972 9044 -32178 -31891 15269 -27096 -32220 -19115 16549 1201 -4584 4776 29773 11123 -16337 19223 -22290 -10928 -26099 12734 361 -15036 31499 -30192 -25835 -9705 -7610 -17867 11379 -21401 -29374 29326 -19038 -8183 -13318 -6732 7722 -9220 23164 -22527 -6525 -7001 16366 -27270 -27972 -13736 -6371 32373 14542 16592 -30196 27966 -21278 12478 -2305 7182 16526 -17238 1211 30383 -19346 16095 -18246 -19080 15074 31068 -3471 13308 17312 -22711 -280 507 9869 2977 -8239 -15631 7210 -10466 5268 -14337 -26086 16110 -19664 -15719 26637 -31766 10505 -18778 18172 2690 -40 -4664 -3779 6030 30598 13151 24788 20042 18502 17918 28148 -30199 -4208 -26989 -14574 -4208 12727 -6815 12429 14615 -10947 3677 -1512 1795 120 12749 -4317 -31984 1841 -14876 9753 -22050 14983 27349 13527 -22524 3903 -22390 20629 11251 16310 32315 22973 -21742 2458 28755 -18672 -22577 21450 27885 -7374 10731 -32627 11951 -20872 31062 4676 -18261 3553 -27193 8969 9948 12424 28971 10157 18927 -9875 28888 -6586 -14137 14671 19088 -15070 -24471 7795 -7303 31383 19004 -4386 -6751 11330 -18845 17514 12395 3538 11100 -30090 -24698 -23621 5211 26298 9596 9165 10139 -3474 -29633 22444 8187 -31564 -407 etc…)

BGV is rendering a bunch of gibberish, is this due to a bug or something else?
I’d like to know the exact cause if it’s a specific cause.

I would really appreciate any insights or explanations regarding this behavior.

Thank you for your help!

Best regards,
wowblk

In crypto context generation, the multiplicative depth is set to 2. The circuit you evaluated (3 multiplications) exceeds the depth of 2. This is why you get incorrect results (by design). To get correct results, the multiplicative depth should either be increased to 3 (assuming you evaluate x^4, i.e., 3 multiplications) or a binary tree method should be used to evaluate x^4 using only 2 levels.

But why in bfv scheme can calculate the result. they are same parameters in cryptocontext. Both scheme using the multiplicative depth of 2; I think the result should be the same for both scheme with the same parameters.

I would really appreciate any insights or explanations regarding this behavior.
Thank you for your help!

Best regards,
wowblk

In BFV, the parameter selection logic is different. We find \log Q and the split it into maximum-size moduli, e.g., 60 bits. So 60 bits is the level of granularity (by default). This may leave a significant cushion (to accommodate another level). In BGV, the choice of parameters is more granular/tight. Each RNS modulus corresponds to one level, and there is no potential cushion for extra room. If you want to get more familiar with the differences of parameter selection between BFV and BGV, I suggest reading Revisiting Homomorphic Encryption Schemes for Finite Fields, e.g., Section 4 for BGV.