Skip to content

Commit

Permalink
franco before vacation
Browse files Browse the repository at this point in the history
  • Loading branch information
0xThemis committed Sep 13, 2024
1 parent c7ce9da commit 6df7bbd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
8 changes: 4 additions & 4 deletions co-circom/circom-mpc-vm/src/mpc/rep3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl<F: PrimeField, N: Rep3Network> VmCircomWitnessExtension<F>
let b = self.val(b);
Ok(self
.runtime
.block_on(arithmetic::gt_public(b, a, &mut self.io_context0))?
.block_on(arithmetic::ge_public(b, a, &mut self.io_context0))?
.into())
}
(Rep3VmType::Arithmetic(a), Rep3VmType::Public(b)) => {
Expand Down Expand Up @@ -460,7 +460,7 @@ impl<F: PrimeField, N: Rep3Network> VmCircomWitnessExtension<F>
let b = self.val(b);
Ok(self
.runtime
.block_on(arithmetic::ge_public(b, a, &mut self.io_context0))?
.block_on(arithmetic::gt_public(b, a, &mut self.io_context0))?
.into())
}
(Rep3VmType::Arithmetic(a), Rep3VmType::Public(b)) => {
Expand Down Expand Up @@ -523,7 +523,7 @@ impl<F: PrimeField, N: Rep3Network> VmCircomWitnessExtension<F>
let b = self.val(b);
Ok(self
.runtime
.block_on(arithmetic::lt_public(b, a, &mut self.io_context0))?
.block_on(arithmetic::le_public(b, a, &mut self.io_context0))?
.into())
}
(Rep3VmType::Arithmetic(a), Rep3VmType::Public(b)) => {
Expand Down Expand Up @@ -586,7 +586,7 @@ impl<F: PrimeField, N: Rep3Network> VmCircomWitnessExtension<F>
let b = self.val(b);
Ok(self
.runtime
.block_on(arithmetic::le_public(b, a, &mut self.io_context0))?
.block_on(arithmetic::lt_public(b, a, &mut self.io_context0))?
.into())
}
(Rep3VmType::Arithmetic(a), Rep3VmType::Public(b)) => {
Expand Down
6 changes: 3 additions & 3 deletions co-circom/co-groth16/src/groth16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ where
let fft_span = tracing::debug_span!("fft in dist pows").entered();
T::fft_in_place(&mut ab, domain.as_ref());
fft_span.exit();
let c_dist_pow = ab;
let c = ab;
mul_vec_span.exit();

tracing::error!("DONE MUL VEC SCOPE");
Expand All @@ -246,9 +246,9 @@ where
//TODO we can merge the mul and sub commands but it most likely is not that
//much of a difference
let mut ab = self.runtime.block_on(self.driver.mul_vec(&a, &b))?;
T::sub_assign_vec(&mut ab, &c_dist_pow);
T::sub_assign_vec(&mut ab, &c);
mul_vec_span.exit();
Ok(a)
Ok(ab)
}

fn calculate_coeff_g1(
Expand Down
1 change: 1 addition & 0 deletions co-noir/co-acvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ num-bigint.workspace = true
num-traits.workspace = true
thiserror.workspace = true
tracing.workspace = true
tokio.workspace = true

[dev-dependencies]
paste.workspace = true
27 changes: 21 additions & 6 deletions co-noir/co-acvm/src/mpc/rep3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ use mpc_core::{

use super::plain::PlainAcvmSolver;
use super::NoirWitnessExtensionProtocol;
use tokio::runtime::{self, Runtime};
type ArithmeticShare<F> = Rep3PrimeFieldShare<F>;

pub struct Rep3AcvmSolver<F: PrimeField, N: Rep3Network> {
runtime: Runtime,
lut_provider: NaiveRep3LookupTable<N>,
io_context: IoContext<N>,
plain_solver: PlainAcvmSolver<F>,
Expand All @@ -24,7 +26,20 @@ pub struct Rep3AcvmSolver<F: PrimeField, N: Rep3Network> {

impl<F: PrimeField, N: Rep3Network> Rep3AcvmSolver<F, N> {
pub(crate) fn new(network: N) -> Self {
todo!()
let runtime = runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
let plain_solver = PlainAcvmSolver::<F>::default();
let mut io_context = runtime.block_on(IoContext::init(network)).unwrap();
let forked = runtime.block_on(io_context.fork()).unwrap();
Self {
runtime,
lut_provider: NaiveRep3LookupTable { io_context: forked },
io_context,
plain_solver,
phantom_data: PhantomData,
}
}
}

Expand Down Expand Up @@ -156,7 +171,7 @@ impl<F: PrimeField, N: Rep3Network> NoirWitnessExtensionProtocol<F> for Rep3Acvm
}
(Rep3AcvmType::Shared(lhs), Rep3AcvmType::Shared(rhs)) => {
let future = arithmetic::mul(lhs, rhs, &mut self.io_context);
let shared_mul = futures::executor::block_on(future)?;
let shared_mul = self.runtime.block_on(future)?;
Rep3AcvmType::Shared(arithmetic::mul_public(shared_mul, c))
}
};
Expand All @@ -180,12 +195,12 @@ impl<F: PrimeField, N: Rep3Network> NoirWitnessExtensionProtocol<F> for Rep3Acvm
}
(Rep3AcvmType::Shared(q_l), Rep3AcvmType::Public(c)) => {
let future = arithmetic::div_public_by_shared(-c, q_l, io_context);
let result = futures::executor::block_on(future)?;
let result = self.runtime.block_on(future)?;
Rep3AcvmType::Shared(result)
}
(Rep3AcvmType::Shared(q_l), Rep3AcvmType::Shared(c)) => {
let future = arithmetic::div(arithmetic::neg(c), q_l, io_context);
let result = futures::executor::block_on(future)?;
let result = self.runtime.block_on(future)?;
Rep3AcvmType::Shared(result)
}
};
Expand Down Expand Up @@ -221,7 +236,7 @@ impl<F: PrimeField, N: Rep3Network> NoirWitnessExtensionProtocol<F> for Rep3Acvm
}
Rep3AcvmType::Shared(shared) => self.lut_provider.get_from_lut(*shared, lut),
};
let value = futures::executor::block_on(value)?;
let value = self.runtime.block_on(value)?;
Ok(Rep3AcvmType::Shared(value))
}

Expand Down Expand Up @@ -250,7 +265,7 @@ impl<F: PrimeField, N: Rep3Network> NoirWitnessExtensionProtocol<F> for Rep3Acvm
self.lut_provider.write_to_lut(index, value, lut)
}
};
futures::executor::block_on(future)?;
self.runtime.block_on(future)?;
Ok(())
}
}
2 changes: 1 addition & 1 deletion mpc-core/src/protocols/rep3/lut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::{
pub type MpcMap<F> = Vec<(F, F)>;

pub struct NaiveRep3LookupTable<N: Rep3Network> {
io_context: IoContext<N>,
pub io_context: IoContext<N>,
}

impl<F: PrimeField, N: Rep3Network> LookupTableProvider<F> for NaiveRep3LookupTable<N> {
Expand Down

0 comments on commit 6df7bbd

Please sign in to comment.