Skip to content

Commit

Permalink
Add extension fields
Browse files Browse the repository at this point in the history
  • Loading branch information
WizardOfMenlo committed Jul 27, 2024
1 parent b304c00 commit 3a171a4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ark-bls12-381 = {version="0.4.0", optional=true}


[features]
default = []
default = [ "ark" ]
ark = ["dep:ark-ff", "dep:ark-ec", "dep:ark-serialize"]
group = ["dep:group"]
ark-bls12-381 = ["ark", "dep:ark-bls12-381"]
Expand Down
11 changes: 8 additions & 3 deletions src/plugins/ark/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,20 @@ where

impl<F, T> FieldChallenges<F> for T
where
F: PrimeField,
F: Field,
T: ByteChallenges,
{
fn fill_challenge_scalars(&mut self, output: &mut [F]) -> ProofResult<()> {
let mut buf = vec![0u8; bytes_uniform_modp(F::MODULUS_BIT_SIZE)];
let base_field_size = bytes_uniform_modp(F::BasePrimeField::MODULUS_BIT_SIZE);
let mut buf = vec![0u8; F::extension_degree() as usize * base_field_size];

for o in output.iter_mut() {
self.fill_challenge_bytes(&mut buf)?;
*o = F::from_be_bytes_mod_order(&buf).into();
*o = F::from_base_prime_field_elems(
buf.chunks(base_field_size)
.map(F::BasePrimeField::from_be_bytes_mod_order),
)
.expect("Could not convert");
}
Ok(())
}
Expand Down
18 changes: 14 additions & 4 deletions src/plugins/ark/iopattern.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
use ark_ec::CurveGroup;
use ark_ff::{Fp, FpConfig, PrimeField};
use ark_ff::{Field, Fp, FpConfig, PrimeField};

use super::*;
use crate::plugins::{bytes_modp, bytes_uniform_modp};

impl<F, H> FieldIOPattern<F> for IOPattern<H>
where
F: PrimeField,
F: Field,
H: DuplexHash,
{
fn add_scalars(self, count: usize, label: &str) -> Self {
self.add_bytes(count * bytes_modp(F::MODULUS_BIT_SIZE), label)
self.add_bytes(
count
* F::extension_degree() as usize
* bytes_modp(F::BasePrimeField::MODULUS_BIT_SIZE),
label,
)
}

fn challenge_scalars(self, count: usize, label: &str) -> Self {
self.challenge_bytes(count * bytes_uniform_modp(F::MODULUS_BIT_SIZE), label)
self.challenge_bytes(
count
* F::extension_degree() as usize
* bytes_uniform_modp(F::BasePrimeField::MODULUS_BIT_SIZE),
label,
)
}
}

Expand Down

0 comments on commit 3a171a4

Please sign in to comment.