Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate coroutine circuits. #1076

Merged
merged 2 commits into from
Jan 31, 2024
Merged
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
38 changes: 23 additions & 15 deletions src/coroutine/memoset/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bellpepper_core::{num::AllocatedNum, ConstraintSystem, SynthesisError};

use super::{
query::{CircuitQuery, Query},
CircuitScope, CircuitTranscript, LogMemo, Scope,
CircuitScope, CircuitTranscript, LogMemo, LogMemoCircuit, Scope,
};
use crate::circuit::gadgets::constraints::alloc_is_zero;
use crate::circuit::gadgets::pointer::AllocatedPtr;
Expand Down Expand Up @@ -88,6 +88,22 @@ impl<F: LurkField> Query<F> for DemoQuery<F> {
}
}

fn to_circuit<CS: ConstraintSystem<F>>(&self, cs: &mut CS, s: &Store<F>) -> Self::CQ {
match self {
DemoQuery::Factorial(n) => {
Self::CQ::Factorial(AllocatedPtr::alloc_infallible(cs, || s.hash_ptr(n)))
}
_ => unreachable!(),
}
}

fn dummy_from_index(s: &Store<F>, index: usize) -> Self {
match index {
0 => Self::Factorial(s.num(0.into())),
_ => unreachable!(),
}
}

fn index(&self) -> usize {
match self {
Self::Factorial(_) => 0,
Expand All @@ -106,7 +122,7 @@ impl<F: LurkField> CircuitQuery<F> for DemoCircuitQuery<F> {
cs: &mut CS,
g: &GlobalAllocator<F>,
store: &Store<F>,
scope: &mut CircuitScope<F, LogMemo<F>>,
scope: &mut CircuitScope<F, LogMemoCircuit<F>>,
acc: &AllocatedPtr<F>,
transcript: &CircuitTranscript<F>,
) -> Result<(AllocatedPtr<F>, AllocatedPtr<F>, CircuitTranscript<F>), SynthesisError> {
Expand Down Expand Up @@ -208,19 +224,11 @@ impl<F: LurkField> CircuitQuery<F> for DemoCircuitQuery<F> {
}

fn from_ptr<CS: ConstraintSystem<F>>(cs: &mut CS, s: &Store<F>, ptr: &Ptr) -> Option<Self> {
let query = DemoQuery::from_ptr(s, ptr);
if let Some(q) = query {
match q {
DemoQuery::Factorial(n) => {
Some(Self::Factorial(AllocatedPtr::alloc_infallible(cs, || {
s.hash_ptr(&n)
})))
}
_ => unreachable!(),
}
} else {
None
}
DemoQuery::from_ptr(s, ptr).map(|q| q.to_circuit(cs, s))
}

fn dummy_from_index<CS: ConstraintSystem<F>>(cs: &mut CS, s: &Store<F>, index: usize) -> Self {
DemoQuery::dummy_from_index(s, index).to_circuit(cs, s)
}

fn symbol(&self) -> Symbol {
Expand Down
Loading