Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion co-circom/circom-mpc-vm/src/mpc/batched_rep3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl<F: PrimeField, N: Network> VmCircomWitnessExtension<F>
.collect_vec()
.into()),
(BatchedRep3VmType::Arithmetic(a), BatchedRep3VmType::Arithmetic(b)) => {
Ok(arithmetic::mul_vec(&a, &b, self.net0, &mut self.state0)?.into())
Ok(arithmetic::mul_many(&a, &b, self.net0, &mut self.state0)?.into())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion co-circom/co-groth16/src/groth16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl<P: Pairing, T: CircomGroth16Prover<P>> CoGroth16<P, T> {
);

let rs_span = tracing::debug_span!("r*s without networking").entered();
let rs = T::local_mul_vec(vec![r], vec![s], state0).pop().unwrap();
let rs = T::local_mul_many(vec![r], vec![s], state0).pop().unwrap();
let r_s_delta_g1 = T::scalar_mul_public_point_hs(&delta_g1, rs);
rs_span.exit();

Expand Down
6 changes: 3 additions & 3 deletions co-circom/co-groth16/src/groth16/reduction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl R1CSToQAP for CircomReduction {
},
|| {
let local_mul_vec_span = tracing::debug_span!("c: local_mul_vec").entered();
let mut ab = T::local_mul_vec(a, b, state);
let mut ab = T::local_mul_many(a, b, state);
local_mul_vec_span.exit();
let ifft_span = tracing::debug_span!("c: ifft in dist pows").entered();
domain.ifft_in_place(&mut ab);
Expand All @@ -161,7 +161,7 @@ impl R1CSToQAP for CircomReduction {

let local_ab_span = tracing::debug_span!("ab: local_mul_vec").entered();
// same as above. No IO task is run at the moment.
let mut ab = T::local_mul_vec(a, b, state);
let mut ab = T::local_mul_many(a, b, state);
local_ab_span.exit();
let compute_ab_span = tracing::debug_span!("compute ab").entered();
ab.par_iter_mut()
Expand Down Expand Up @@ -262,7 +262,7 @@ impl R1CSToQAP for LibSnarkReduction {
b
},
);
T::local_mul_vec(a, b, state)
T::local_mul_many(a, b, state)
},
|| {
let mut c = evaluate_constraint_half_share::<P, T>(
Expand Down
2 changes: 1 addition & 1 deletion co-circom/co-groth16/src/mpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub trait CircomGroth16Prover<P: Pairing>: Send + Sized {
///
/// # Security
/// You must *NOT* perform additional non-linear operations on the result of this function.
fn local_mul_vec(
fn local_mul_many(
a: Vec<Self::ArithmeticShare>,
b: Vec<Self::ArithmeticShare>,
state: &mut Self::State,
Expand Down
2 changes: 1 addition & 1 deletion co-circom/co-groth16/src/mpc/plain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<P: Pairing> CircomGroth16Prover<P> for PlainGroth16Driver {
public_values.to_vec()
}

fn local_mul_vec(
fn local_mul_many(
a: Vec<Self::ArithmeticShare>,
b: Vec<Self::ArithmeticShare>,
_: &mut Self::State,
Expand Down
4 changes: 2 additions & 2 deletions co-circom/co-groth16/src/mpc/rep3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ impl<P: Pairing> CircomGroth16Prover<P> for Rep3Groth16Driver {
.collect()
}

fn local_mul_vec(
fn local_mul_many(
a: Vec<Self::ArithmeticShare>,
b: Vec<Self::ArithmeticShare>,
state: &mut Self::State,
) -> Vec<P::ScalarField> {
arithmetic::local_mul_vec(&a, &b, state)
arithmetic::local_mul_many(&a, &b, state)
}

fn distribute_powers_and_mul_by_const(
Expand Down
4 changes: 2 additions & 2 deletions co-circom/co-groth16/src/mpc/shamir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ impl<P: Pairing> CircomGroth16Prover<P> for ShamirGroth16Driver {
arithmetic::promote_to_trivial_shares(public_values)
}

fn local_mul_vec(
fn local_mul_many(
a: Vec<Self::ArithmeticShare>,
b: Vec<Self::ArithmeticShare>,
_: &mut Self::State,
) -> Vec<P::ScalarField> {
arithmetic::local_mul_vec(&a, &b)
arithmetic::local_mul_many(&a, &b)
}

fn distribute_powers_and_mul_by_const(
Expand Down
18 changes: 9 additions & 9 deletions co-circom/co-plonk/src/mpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,24 @@ pub trait CircomPlonkProver<P: Pairing> {
///
/// # Security
/// If you want to perform additional non-linear operations on the result of this function,
/// you *MUST* call [`CircomPlonkProver::io_round_mul_vec`] first. Only then the relevant network round is performed.
fn local_mul_vec(
/// you *MUST* call [`CircomPlonkProver::io_round_mul_many`] first. Only then the relevant network round is performed.
fn local_mul_many(
a: &[Self::ArithmeticShare],
b: &[Self::ArithmeticShare],
state: &mut Self::State,
) -> Vec<P::ScalarField>;

/// Performs networking round of `local_mul_vec`
fn io_round_mul_vec<N: Network>(
/// Performs networking round of `local_mul_many`
fn io_round_mul_many<N: Network>(
a: Vec<P::ScalarField>,
net: &N,
state: &mut Self::State,
) -> eyre::Result<Vec<Self::ArithmeticShare>>;

/// Performs element-wise multiplication of two vectors of shared values.
///
/// Use this function for small vecs. For large vecs see [`CircomPlonkProver::local_mul_vec`]
fn mul_vec<N: Network>(
/// Use this function for small vecs. For large vecs see [`CircomPlonkProver::local_mul_many`]
fn mul_many<N: Network>(
a: &[Self::ArithmeticShare],
b: &[Self::ArithmeticShare],
net: &N,
Expand All @@ -79,8 +79,8 @@ pub trait CircomPlonkProver<P: Pairing> {

/// Performs element-wise multiplication of three vectors of shared values.
///
/// Use this function for small vecs. For large vecs see [`CircomPlonkProver::local_mul_vec`]
fn mul_vecs<N: Network>(
/// Use this function for small vecs. For large vecs see [`CircomPlonkProver::local_mul_many`]
fn mul_many_pairs<N: Network>(
a: &[Self::ArithmeticShare],
b: &[Self::ArithmeticShare],
c: &[Self::ArithmeticShare],
Expand All @@ -89,7 +89,7 @@ pub trait CircomPlonkProver<P: Pairing> {
) -> eyre::Result<Vec<Self::ArithmeticShare>>;

/// Convenience method for \[a\] + \[b\] * \[c\]
fn add_mul_vec<N: Network>(
fn add_mul_many<N: Network>(
a: &[Self::ArithmeticShare],
b: &[Self::ArithmeticShare],
c: &[Self::ArithmeticShare],
Expand Down
10 changes: 5 additions & 5 deletions co-circom/co-plonk/src/mpc/plain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ impl<P: Pairing> CircomPlonkProver<P> for PlainPlonkDriver {
}
}

fn local_mul_vec(
fn local_mul_many(
a: &[Self::ArithmeticShare],
b: &[Self::ArithmeticShare],
_: &mut Self::State,
) -> Vec<P::ScalarField> {
izip!(a, b).map(|(a, b)| *a * *b).collect()
}

fn io_round_mul_vec<N: Network>(
fn io_round_mul_many<N: Network>(
a: Vec<P::ScalarField>,
_: &N,
_: &mut Self::State,
Expand All @@ -74,7 +74,7 @@ impl<P: Pairing> CircomPlonkProver<P> for PlainPlonkDriver {
shared * public
}

fn mul_vec<N: Network>(
fn mul_many<N: Network>(
a: &[Self::ArithmeticShare],
b: &[Self::ArithmeticShare],
_: &N,
Expand All @@ -83,7 +83,7 @@ impl<P: Pairing> CircomPlonkProver<P> for PlainPlonkDriver {
Ok(izip!(a, b).map(|(a, b)| *a * *b).collect())
}

fn mul_vecs<N: Network>(
fn mul_many_pairs<N: Network>(
a: &[Self::ArithmeticShare],
b: &[Self::ArithmeticShare],
c: &[Self::ArithmeticShare],
Expand All @@ -93,7 +93,7 @@ impl<P: Pairing> CircomPlonkProver<P> for PlainPlonkDriver {
Ok(izip!(a, b, c).map(|(a, b, c)| *a * *b * *c).collect())
}

fn add_mul_vec<N: Network>(
fn add_mul_many<N: Network>(
a: &[Self::ArithmeticShare],
b: &[Self::ArithmeticShare],
c: &[Self::ArithmeticShare],
Expand Down
30 changes: 15 additions & 15 deletions co-circom/co-plonk/src/mpc/rep3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,51 +52,51 @@ impl<P: Pairing> CircomPlonkProver<P> for Rep3PlonkDriver {
arithmetic::mul_public(shared, public)
}

fn local_mul_vec(
fn local_mul_many(
a: &[Self::ArithmeticShare],
b: &[Self::ArithmeticShare],
state: &mut Self::State,
) -> Vec<P::ScalarField> {
arithmetic::local_mul_vec::<P::ScalarField>(a, b, state)
arithmetic::local_mul_many::<P::ScalarField>(a, b, state)
}

fn io_round_mul_vec<N: Network>(
fn io_round_mul_many<N: Network>(
a: Vec<P::ScalarField>,
net: &N,
_: &mut Self::State,
) -> eyre::Result<Vec<Self::ArithmeticShare>> {
arithmetic::reshare_vec(a, net)
}

fn mul_vec<N: Network>(
fn mul_many<N: Network>(
lhs: &[Self::ArithmeticShare],
rhs: &[Self::ArithmeticShare],
net: &N,
state: &mut Self::State,
) -> eyre::Result<Vec<Self::ArithmeticShare>> {
arithmetic::mul_vec(lhs, rhs, net, state)
arithmetic::mul_many(lhs, rhs, net, state)
}

fn mul_vecs<N: Network>(
fn mul_many_pairs<N: Network>(
a: &[Self::ArithmeticShare],
b: &[Self::ArithmeticShare],
c: &[Self::ArithmeticShare],
net: &N,
state: &mut Self::State,
) -> eyre::Result<Vec<Self::ArithmeticShare>> {
let tmp = arithmetic::mul_vec(a, b, net, state)?;
arithmetic::mul_vec(&tmp, c, net, state)
let tmp = arithmetic::mul_many(a, b, net, state)?;
arithmetic::mul_many(&tmp, c, net, state)
}

fn add_mul_vec<N: Network>(
fn add_mul_many<N: Network>(
a: &[Self::ArithmeticShare],
b: &[Self::ArithmeticShare],
c: &[Self::ArithmeticShare],
net: &N,
state: &mut Self::State,
) -> eyre::Result<Vec<Self::ArithmeticShare>> {
let mut result = arithmetic::mul_vec(b, c, net, state)?;
arithmetic::add_vec_assign(&mut result, a);
let mut result = arithmetic::mul_many(b, c, net, state)?;
arithmetic::add_many_assign(&mut result, a);
Ok(result)
}

Expand Down Expand Up @@ -187,8 +187,8 @@ impl<P: Pairing> CircomPlonkProver<P> for Rep3PlonkDriver {
net: &N,
state: &mut Self::State,
) -> eyre::Result<Vec<Self::ArithmeticShare>> {
let arr = arithmetic::mul_vec(arr1, arr2, net, state)?;
let arr = arithmetic::mul_vec(&arr, arr3, net, state)?;
let arr = arithmetic::mul_many(arr1, arr2, net, state)?;
let arr = arithmetic::mul_many(&arr, arr3, net, state)?;
// Do the multiplications of inp[i] * inp[i-1] in constant rounds
let len = arr.len();

Expand All @@ -198,9 +198,9 @@ impl<P: Pairing> CircomPlonkProver<P> for Rep3PlonkDriver {
}
let r_inv = arithmetic::inv_vec(&r, net, state)?;
let r_inv0 = vec![r_inv[0]; len];
let mut unblind = arithmetic::mul_vec(&r_inv0, &r[1..], net, state)?;
let mut unblind = arithmetic::mul_many(&r_inv0, &r[1..], net, state)?;

let mul = arithmetic::mul_vec(&r[..len], &arr, net, state)?;
let mul = arithmetic::mul_many(&r[..len], &arr, net, state)?;
let mut open = arithmetic::mul_open_vec(&mul, &r_inv[1..], net, state)?;

for i in 1..open.len() {
Expand Down
30 changes: 15 additions & 15 deletions co-circom/co-plonk/src/mpc/shamir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,51 +54,51 @@ impl<P: Pairing> CircomPlonkProver<P> for ShamirPlonkDriver {
arithmetic::mul_public(shared, public)
}

fn local_mul_vec(
fn local_mul_many(
a: &[Self::ArithmeticShare],
b: &[Self::ArithmeticShare],
_: &mut Self::State,
) -> Vec<P::ScalarField> {
arithmetic::local_mul_vec(a, b)
arithmetic::local_mul_many(a, b)
}

fn io_round_mul_vec<N: Network>(
fn io_round_mul_many<N: Network>(
a: Vec<P::ScalarField>,
net: &N,
state: &mut Self::State,
) -> eyre::Result<Vec<Self::ArithmeticShare>> {
net.degree_reduce_many(state, a)
}

fn mul_vec<N: Network>(
fn mul_many<N: Network>(
a: &[Self::ArithmeticShare],
b: &[Self::ArithmeticShare],
net: &N,
state: &mut Self::State,
) -> eyre::Result<Vec<Self::ArithmeticShare>> {
arithmetic::mul_vec(a, b, net, state)
arithmetic::mul_many(a, b, net, state)
}

fn mul_vecs<N: Network>(
fn mul_many_pairs<N: Network>(
a: &[Self::ArithmeticShare],
b: &[Self::ArithmeticShare],
c: &[Self::ArithmeticShare],
net: &N,
state: &mut Self::State,
) -> eyre::Result<Vec<Self::ArithmeticShare>> {
let tmp = arithmetic::mul_vec(a, b, net, state)?;
arithmetic::mul_vec(&tmp, c, net, state)
let tmp = arithmetic::mul_many(a, b, net, state)?;
arithmetic::mul_many(&tmp, c, net, state)
}

fn add_mul_vec<N: Network>(
fn add_mul_many<N: Network>(
a: &[Self::ArithmeticShare],
b: &[Self::ArithmeticShare],
c: &[Self::ArithmeticShare],
net: &N,
state: &mut Self::State,
) -> eyre::Result<Vec<Self::ArithmeticShare>> {
let mut result = arithmetic::mul_vec(b, c, net, state)?;
arithmetic::add_vec_assign(&mut result, a);
let mut result = arithmetic::mul_many(b, c, net, state)?;
arithmetic::add_many_assign(&mut result, a);
Ok(result)
}

Expand Down Expand Up @@ -193,8 +193,8 @@ impl<P: Pairing> CircomPlonkProver<P> for ShamirPlonkDriver {
net: &N,
state: &mut Self::State,
) -> eyre::Result<Vec<Self::ArithmeticShare>> {
let arr = arithmetic::mul_vec(arr1, arr2, net, state)?;
let arr = arithmetic::mul_vec(&arr, arr3, net, state)?;
let arr = arithmetic::mul_many(arr1, arr2, net, state)?;
let arr = arithmetic::mul_many(&arr, arr3, net, state)?;
// Do the multiplications of inp[i] * inp[i-1] in constant rounds
let len = arr.len();

Expand All @@ -204,9 +204,9 @@ impl<P: Pairing> CircomPlonkProver<P> for ShamirPlonkDriver {
}
let r_inv = arithmetic::inv_vec(&r, net, state)?;
let r_inv0 = vec![r_inv[0]; len];
let mut unblind = arithmetic::mul_vec(&r_inv0, &r[1..], net, state)?;
let mut unblind = arithmetic::mul_many(&r_inv0, &r[1..], net, state)?;

let mul = arithmetic::mul_vec(&r[..len], &arr, net, state)?;
let mul = arithmetic::mul_many(&r[..len], &arr, net, state)?;
let mut open = arithmetic::mul_open_vec(&mul, &r_inv[1..], net, state)?;

for i in 1..open.len() {
Expand Down
2 changes: 1 addition & 1 deletion co-circom/co-plonk/src/round2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl<'a, P: Pairing, T: CircomPlonkProver<P>, N: Network + 'static> Round2<'a, P
let num = num?;
let den = den?;

let mut buffer_z = T::mul_vec(&num, &den, &nets[0], state)?;
let mut buffer_z = T::mul_many(&num, &den, &nets[0], state)?;
buffer_z.rotate_right(1); // Required by SNARKJs/Plonk
batched_mul_span.exit();

Expand Down
Loading