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

Bitwise AND between BigInt that come from PrimeField #715

Closed
hdvanegasm opened this issue Dec 15, 2023 · 0 comments
Closed

Bitwise AND between BigInt that come from PrimeField #715

hdvanegasm opened this issue Dec 15, 2023 · 0 comments

Comments

@hdvanegasm
Copy link
Contributor

hdvanegasm commented Dec 15, 2023

Hi everyone,

I wan to implement the following function considering the last contribution to bitwise operations between BigInt (#713):

use ark_ff::fields::PrimeField;

fn compute_and<F: PrimeField>(a: F, b: F) -> F {
    let a_bigint = a.into_bigint();
    let b_bigint = b.into_bigint();
    let and_bigint =  a_bigint & b_bigint;
    let and_field = match F::from_bigint(and_bigint) {
        Some(value) => value,
        None => panic!("Something bad happened."),
    };

    and_field
}

This code is incorrect, and the output shows the following error which I can understand:

error[E0308]: mismatched types
  --> src/main.rs:7:42
   |
6  |     let and_bigint =  a_bigint & b_bigint;
   |                       ------------------- here the type of `and_bigint` is inferred to be `<<F as PrimeField>::BigInt as BitAnd>::Output`
7  |     let and_field = match F::from_bigint(and_bigint) {
   |                           -------------- ^^^^^^^^^^ expected `ark_ff::PrimeField::BigInt`, found `std::ops::BitAnd::Output`
   |                           |
   |                           arguments to this function are incorrect
   |
   = note: expected associated type `<F as PrimeField>::BigInt`
              found associated type `<<F as PrimeField>::BigInt as BitAnd>::Output`
   = note: an associated type was expected, but a different one was found
note: associated function defined here
  --> /home/hdvanegasm/.cargo/git/checkouts/algebra-7e23afa68841b66e/b7b988f/ff/src/fields/prime.rs:55:8
   |
55 |     fn from_bigint(repr: Self::BigInt) -> Option<Self>;
   |        ^^^^^^^^^^^

For more information about this error, try `rustc --explain E0308`.
error: could not compile `ark` (bin "ark") due to previous error

Is it possible to implement this function for arbitrary PrimeField elements with the current state of the library, or do we need to extend the functionality by submitting a PR?

mmaker added a commit that referenced this issue Dec 15, 2023
PR #713 introduced underdefined trait constraints for BigInteger and tests
were not really using the `BigInteger` trait.
@mmaker mmaker mentioned this issue Dec 15, 2023
mmaker added a commit that referenced this issue Dec 15, 2023
PR #713 introduced underdefined trait constraints for BigInteger and tests
were not really using the `BigInteger` trait.
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

1 participant