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
43 changes: 22 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ tlsn-harness-runner = { path = "crates/harness/runner" }
tlsn-wasm = { path = "crates/wasm" }
tlsn = { path = "crates/tlsn" }

mpz-circuits = { git = "https://github.com/privacy-scaling-explorations/mpz", rev = "ccc0057" }
mpz-memory-core = { git = "https://github.com/privacy-scaling-explorations/mpz", rev = "ccc0057" }
mpz-common = { git = "https://github.com/privacy-scaling-explorations/mpz", rev = "ccc0057" }
mpz-core = { git = "https://github.com/privacy-scaling-explorations/mpz", rev = "ccc0057" }
mpz-vm-core = { git = "https://github.com/privacy-scaling-explorations/mpz", rev = "ccc0057" }
mpz-garble = { git = "https://github.com/privacy-scaling-explorations/mpz", rev = "ccc0057" }
mpz-garble-core = { git = "https://github.com/privacy-scaling-explorations/mpz", rev = "ccc0057" }
mpz-ole = { git = "https://github.com/privacy-scaling-explorations/mpz", rev = "ccc0057" }
mpz-ot = { git = "https://github.com/privacy-scaling-explorations/mpz", rev = "ccc0057" }
mpz-share-conversion = { git = "https://github.com/privacy-scaling-explorations/mpz", rev = "ccc0057" }
mpz-fields = { git = "https://github.com/privacy-scaling-explorations/mpz", rev = "ccc0057" }
mpz-zk = { git = "https://github.com/privacy-scaling-explorations/mpz", rev = "ccc0057" }
mpz-hash = { git = "https://github.com/privacy-scaling-explorations/mpz", rev = "ccc0057" }
mpz-circuits = { git = "https://github.com/privacy-scaling-explorations/mpz", branch = "refactor/zk_expose_ot_handle" }
mpz-memory-core = { git = "https://github.com/privacy-scaling-explorations/mpz", branch = "refactor/zk_expose_ot_handle" }
mpz-common = { git = "https://github.com/privacy-scaling-explorations/mpz", branch = "refactor/zk_expose_ot_handle" }
mpz-core = { git = "https://github.com/privacy-scaling-explorations/mpz", branch = "refactor/zk_expose_ot_handle" }
mpz-vm-core = { git = "https://github.com/privacy-scaling-explorations/mpz", branch = "refactor/zk_expose_ot_handle" }
mpz-garble = { git = "https://github.com/privacy-scaling-explorations/mpz", branch = "refactor/zk_expose_ot_handle" }
mpz-garble-core = { git = "https://github.com/privacy-scaling-explorations/mpz", branch = "refactor/zk_expose_ot_handle" }
mpz-ole = { git = "https://github.com/privacy-scaling-explorations/mpz", branch = "refactor/zk_expose_ot_handle" }
mpz-ot = { git = "https://github.com/privacy-scaling-explorations/mpz", branch = "refactor/zk_expose_ot_handle" }
mpz-share-conversion = { git = "https://github.com/privacy-scaling-explorations/mpz", branch = "refactor/zk_expose_ot_handle" }
mpz-fields = { git = "https://github.com/privacy-scaling-explorations/mpz", branch = "refactor/zk_expose_ot_handle" }
mpz-zk = { git = "https://github.com/privacy-scaling-explorations/mpz", branch = "refactor/zk_expose_ot_handle" }
mpz-hash = { git = "https://github.com/privacy-scaling-explorations/mpz", branch = "refactor/zk_expose_ot_handle" }

rangeset = { version = "0.2" }
serio = { version = "0.2" }
Expand Down
67 changes: 60 additions & 7 deletions crates/components/deap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ pub struct Deap<Mpc, Zk> {
/// Outputs of the follower from the ZK VM. The references
/// correspond to the MPC VM.
outputs: Vec<(Slice, DecodeFuture<BitVec>)>,
/// Whether the DEAP VM should operate in a limited mode.
///
/// The following limitations will apply:
///
/// - `wants_flush`, `flush`, `wants_preprocess`, `preprocess` will **NOT**
/// have an effect on the ZK VM, only on the MPC VM.
/// - `call_raw` will **not** accept calls which have AND gates.
///
/// This mode facilitates the ZK VM preprocessing in an
/// external context concurrently with the execution of the DEAP VM.
limited: bool,
}

impl<Mpc, Zk> Deap<Mpc, Zk> {
Expand All @@ -56,6 +67,7 @@ impl<Mpc, Zk> Deap<Mpc, Zk> {
follower_input_ranges: RangeSet::default(),
follower_inputs: Vec::default(),
outputs: Vec::default(),
limited: false,
}
}

Expand Down Expand Up @@ -91,6 +103,11 @@ impl<Mpc, Zk> Deap<Mpc, Zk> {
self.memory_map.try_get(value.to_raw()).map(T::from_raw)
}

/// Sets the limited mode of operation.
pub fn limited(&mut self) {
self.limited = true;
}

#[cfg(test)]
fn mpc(&self) -> MutexGuard<'_, Mpc> {
self.mpc.try_lock().unwrap()
Expand Down Expand Up @@ -301,6 +318,12 @@ where
Zk: Vm<Binary>,
{
fn call_raw(&mut self, call: Call) -> Result<Slice, VmError> {
if self.limited && call.circ().and_count() > 0 {
return Err(VmError::call(
"calls with AND gates not allowed in limited mode",
));
}

let (circ, inputs) = call.clone().into_parts();
let mut builder = Call::builder(circ);

Expand All @@ -326,14 +349,29 @@ where
Zk: Execute + Send + 'static,
{
fn wants_flush(&self) -> bool {
self.mpc.try_lock().unwrap().wants_flush() || self.zk.try_lock().unwrap().wants_flush()
if self.limited {
self.mpc.try_lock().unwrap().wants_flush()
} else {
self.mpc.try_lock().unwrap().wants_flush() || self.zk.try_lock().unwrap().wants_flush()
}
}

async fn flush(&mut self, ctx: &mut Context) -> Result<(), VmError> {
let mut zk = self.zk.clone().try_lock_owned().unwrap();
let mut mpc = self.mpc.clone().try_lock_owned().unwrap();

let zk = if self.limited {
None
} else {
Some(self.zk.clone().try_lock_owned().unwrap())
};

ctx.try_join(
async move |ctx| zk.flush(ctx).await,
async move |ctx| {
if let Some(mut zk) = zk {
zk.flush(ctx).await.unwrap();
}
Ok(())
},
async move |ctx| mpc.flush(ctx).await,
)
.await
Expand All @@ -343,15 +381,30 @@ where
}

fn wants_preprocess(&self) -> bool {
self.mpc.try_lock().unwrap().wants_preprocess()
|| self.zk.try_lock().unwrap().wants_preprocess()
if self.limited {
self.mpc.try_lock().unwrap().wants_preprocess()
} else {
self.mpc.try_lock().unwrap().wants_preprocess()
|| self.zk.try_lock().unwrap().wants_preprocess()
}
}

async fn preprocess(&mut self, ctx: &mut Context) -> Result<(), VmError> {
let mut zk = self.zk.clone().try_lock_owned().unwrap();
let mut mpc = self.mpc.clone().try_lock_owned().unwrap();

let zk = if self.limited {
None
} else {
Some(self.zk.clone().try_lock_owned().unwrap())
};

ctx.try_join(
async move |ctx| zk.preprocess(ctx).await,
async move |ctx| {
if let Some(mut zk) = zk {
zk.preprocess(ctx).await.unwrap();
}
Ok(())
},
async move |ctx| mpc.preprocess(ctx).await,
)
.await
Expand Down
Loading
Loading