diff --git a/co-circom/circom-mpc-vm/src/mpc/rep3.rs b/co-circom/circom-mpc-vm/src/mpc/rep3.rs index df786b50..84b1b178 100644 --- a/co-circom/circom-mpc-vm/src/mpc/rep3.rs +++ b/co-circom/circom-mpc-vm/src/mpc/rep3.rs @@ -397,7 +397,7 @@ impl VmCircomWitnessExtension 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)) => { @@ -460,7 +460,7 @@ impl VmCircomWitnessExtension 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)) => { @@ -523,7 +523,7 @@ impl VmCircomWitnessExtension 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)) => { @@ -586,7 +586,7 @@ impl VmCircomWitnessExtension 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)) => { diff --git a/co-circom/co-groth16/src/groth16.rs b/co-circom/co-groth16/src/groth16.rs index f5d8c401..37457638 100644 --- a/co-circom/co-groth16/src/groth16.rs +++ b/co-circom/co-groth16/src/groth16.rs @@ -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"); @@ -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( diff --git a/co-noir/co-acvm/Cargo.toml b/co-noir/co-acvm/Cargo.toml index d27bbe55..66eb6172 100644 --- a/co-noir/co-acvm/Cargo.toml +++ b/co-noir/co-acvm/Cargo.toml @@ -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 diff --git a/co-noir/co-acvm/src/mpc/rep3.rs b/co-noir/co-acvm/src/mpc/rep3.rs index d6114af1..4279f554 100644 --- a/co-noir/co-acvm/src/mpc/rep3.rs +++ b/co-noir/co-acvm/src/mpc/rep3.rs @@ -13,9 +13,11 @@ use mpc_core::{ use super::plain::PlainAcvmSolver; use super::NoirWitnessExtensionProtocol; +use tokio::runtime::{self, Runtime}; type ArithmeticShare = Rep3PrimeFieldShare; pub struct Rep3AcvmSolver { + runtime: Runtime, lut_provider: NaiveRep3LookupTable, io_context: IoContext, plain_solver: PlainAcvmSolver, @@ -24,7 +26,20 @@ pub struct Rep3AcvmSolver { impl Rep3AcvmSolver { pub(crate) fn new(network: N) -> Self { - todo!() + let runtime = runtime::Builder::new_current_thread() + .enable_all() + .build() + .unwrap(); + let plain_solver = PlainAcvmSolver::::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, + } } } @@ -156,7 +171,7 @@ impl NoirWitnessExtensionProtocol 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)) } }; @@ -180,12 +195,12 @@ impl NoirWitnessExtensionProtocol 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) } }; @@ -221,7 +236,7 @@ impl NoirWitnessExtensionProtocol 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)) } @@ -250,7 +265,7 @@ impl NoirWitnessExtensionProtocol for Rep3Acvm self.lut_provider.write_to_lut(index, value, lut) } }; - futures::executor::block_on(future)?; + self.runtime.block_on(future)?; Ok(()) } } diff --git a/mpc-core/src/protocols/rep3/lut.rs b/mpc-core/src/protocols/rep3/lut.rs index 4c7160a6..b2dc56e6 100644 --- a/mpc-core/src/protocols/rep3/lut.rs +++ b/mpc-core/src/protocols/rep3/lut.rs @@ -14,7 +14,7 @@ use super::{ pub type MpcMap = Vec<(F, F)>; pub struct NaiveRep3LookupTable { - io_context: IoContext, + pub io_context: IoContext, } impl LookupTableProvider for NaiveRep3LookupTable {