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

Add Public Key Encryption #34

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

auryn-macmillan
Copy link

This PR resolves the comments from unmerged PR #31.

I'll also make a PR back to the OPs fork so that these changes could be incorporated into the original PR.

Copy link
Member

@enricobottazzi enricobottazzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On top of the in-line comments, can you please add further indication in the README on how to generate the parameters for the public key encryption case? I would also ask you to add a gtihub action for testing the new circuit.

As I run

python3 scripts/circuit_sk.py -n 4096 -qis '[                                      
    27424203952895201,
    27424203952895203
]' -t 65537

I first run into this error (you can also see it from the GitHub action)


  File "/Users/enricobottazzi/Developer/GitHub/greco/scripts/circuit_sk.py", line 478, in <module>
    main(args)
  File "/Users/enricobottazzi/Developer/GitHub/greco/scripts/circuit_sk.py", line 30, in main
    bfv_crt = BFVCrt(crt_moduli, n, t, discrete_gaussian)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/enricobottazzi/Developer/GitHub/greco/scripts/venv/lib/python3.11/site-packages/bfv/bfv.py", line 342, in __init__
    self.bfv_q = BFV(RLWE(n, crt_moduli.q, t, discrete_gauss))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/enricobottazzi/Developer/GitHub/greco/scripts/venv/lib/python3.11/site-packages/bfv/bfv.py", line 32, in __init__
    assert np.gcd(q, t) == 1, "modulus q and t must be coprime"
           ^^^^^^^^^^^^
OverflowError: Python int too large to convert to C long

I think this might be caused by an updated version of np which is a dependency on my bfv-py repo. If you confirm that you are facing the same error, I’ll update the requirements.txt in bfv-py to pin to the correct (old) version of np.

In general it seems that there are some small errors in the naming of the variables or in the related comments. Some errors might be carried from the original PR.

The tests seem to be passing correctly based on your generated data. But I'm quite outside the loop with Greco, so I will leave it to @0xjei to provide a more thorough review on the PR and the adherence of the protocol to what has been described in the paper

scripts/circuit_sk.py Outdated Show resolved Hide resolved
scripts/circuit_sk.py Outdated Show resolved Hide resolved
scripts/circuit_sk.py Outdated Show resolved Hide resolved
scripts/circuit_pk.py Outdated Show resolved Hide resolved
scripts/circuit_pk.py Show resolved Hide resolved
scripts/circuit_pk.py Outdated Show resolved Hide resolved
scripts/circuit_pk.py Outdated Show resolved Hide resolved
src/pk_encryption_circuit.rs Outdated Show resolved Hide resolved
src/pk_encryption_circuit.rs Outdated Show resolved Hide resolved
src/pk_encryption_circuit.rs Outdated Show resolved Hide resolved
@auryn-macmillan
Copy link
Author

Yes, I can confirm I see the same numpy error. For the time being, I updated the requirements.txt in this repo. But it would be better for it to be updated in bfv.py.

I also had to make these changes in bfv.py

In polynomial.py, I had to add an implementation for len

    def __len__(self) -> int:
        return len(self.coefficients)

In bfv.py, I changed line 442 to this.

    ct_1 = pk1_u.coefficients + e1

@0xjei
Copy link
Member

0xjei commented Aug 22, 2024

hey @auryn-macmillan and @fhedude, Thanks for the update. I'm still getting the same error as Enrico mentioned above.

I first run into this error (you can also see it from the GitHub action)


  File "/Users/enricobottazzi/Developer/GitHub/greco/scripts/circuit_sk.py", line 478, in <module>
    main(args)
  File "/Users/enricobottazzi/Developer/GitHub/greco/scripts/circuit_sk.py", line 30, in main
    bfv_crt = BFVCrt(crt_moduli, n, t, discrete_gaussian)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/enricobottazzi/Developer/GitHub/greco/scripts/venv/lib/python3.11/site-packages/bfv/bfv.py", line 342, in __init__
    self.bfv_q = BFV(RLWE(n, crt_moduli.q, t, discrete_gauss))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/enricobottazzi/Developer/GitHub/greco/scripts/venv/lib/python3.11/site-packages/bfv/bfv.py", line 32, in __init__
    assert np.gcd(q, t) == 1, "modulus q and t must be coprime"
           ^^^^^^^^^^^^
OverflowError: Python int too large to convert to C long

I'm just checking in to see if you need any help or hints on this and how I can be of service. Thanks!

@auryn-macmillan
Copy link
Author

@0xjei, do you still get that error after doing pip3 install -r requirements.txt in scripts/?

That error is caused by an incompatible version of Numpy.

There is also a subsequent error that requires the above changes to BFV.py.

I think we should perhaps have Greco depend on an instance of BFV.py in the PSE GitHub org, rather than the one in @enricobottazzi profile. Just so we're not dependent on Enrico to merge fixes.

@0xjei
Copy link
Member

0xjei commented Aug 22, 2024

@0xjei, do you still get that error after doing pip3 install -r requirements.txt in scripts/?

yes, I'm still getting the same error after running the installation on a fresh venv.

I think we should perhaps have Greco depend on an instance of BFV.py in the PSE GitHub org, rather than the one in @enricobottazzi profile. Just so we're not dependent on Enrico to merge fixes.

sure, we should move whatever Greco is dependent on under the same organization. I will get back to you on this asap.

@auryn-macmillan
Copy link
Author

@0xjei I've just updated the requirements.txt to point to an updated version of bfv.py in the Gnosis Guild github org. Give it a try again now, the errors should be resolved.

@0xjei
Copy link
Member

0xjei commented Aug 26, 2024

@0xjei I've just updated the requirements.txt to point to an updated version of bfv.py in the Gnosis Guild github org. Give it a try again now, the errors should be resolved.

thank you @auryn-macmillan - I've got it working locally now, using cargo build && cargo test --release --nocapture. But I'm still getting errors on the CI. I've traced it back to the --feature bench in the cargo test command. Could you please make sure you get rid of these errors when running the benchmarks too? This should be the last 10% that's causing problems.

@Vishalkulkarni45
Copy link

Hi @auryn-macmillan and @0xjei, I've implemented the changes suggested by Enrico in my PR. You can check it out here. I hope this is helpful, and please let me know if there's anything else I can assist with

@0xjei
Copy link
Member

0xjei commented Sep 10, 2024

Hi @auryn-macmillan and @0xjei, I've implemented the changes suggested by Enrico in my PR. You can check it out here. I hope this is helpful, and please let me know if there's anything else I can assist with

Hey @Vishalkulkarni45 thx - can you just push your new changes back on your PR about public key encryption to ease the review process? tysm

@Vishalkulkarni45
Copy link

Hi! @0xjei i had already made the PR of it #32 but enrico said it's not relevant because SK and PK encryption have almost same algorithm or may be its because of my bad python skills 😅 😁

@auryn-macmillan
Copy link
Author

@Vishalkulkarni45 and @0xjei, we've shifted our efforts to supporting fhe.rs rather than bfv.py over in our fork of Greco.

Could you please make sure you get rid of these errors when running the benchmarks too? This should be the last 10% that's causing problems.

Will try to address this in our fork as well. cc @fhedude

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

Successfully merging this pull request may close these issues.

5 participants