diff --git a/src/coprocessor/memoset/demo.rs b/src/coprocessor/memoset/demo.rs index 5165287483..3b76aad52f 100644 --- a/src/coprocessor/memoset/demo.rs +++ b/src/coprocessor/memoset/demo.rs @@ -26,6 +26,8 @@ pub(crate) enum DemoCircuitQuery { } impl Query for DemoQuery { + type CQ = DemoCircuitQuery; + // DemoQuery and Scope depend on each other. fn eval(&self, s: &Store, scope: &mut Scope>) -> Ptr { match self { @@ -95,14 +97,6 @@ impl Query for DemoQuery { } impl CircuitQuery for DemoCircuitQuery { - type Q = DemoQuery; - - fn dummy_query_variant(&self, s: &Store) -> Self::Q { - match self { - Self::Factorial(_) => Self::Q::Factorial(s.num(F::ZERO)), - } - } - fn synthesize_eval>( &self, cs: &mut CS, @@ -143,8 +137,7 @@ impl CircuitQuery for DemoCircuitQuery { ); let subquery = { - let symbol = - g.alloc_ptr(cs, &store.intern_symbol(&self.symbol(store)), store); + let symbol = g.alloc_ptr(cs, &self.symbol_ptr(store), store); let new_num = AllocatedPtr::alloc_tag( &mut cs.namespace(|| "new_num"), @@ -215,10 +208,10 @@ impl CircuitQuery for DemoCircuitQuery { s: &Store, ptr: &Ptr, ) -> Result, SynthesisError> { - let query = Self::Q::from_ptr(s, ptr); + let query = DemoQuery::from_ptr(s, ptr); Ok(if let Some(q) = query { match q { - Self::Q::Factorial(n) => Some(Self::Factorial(AllocatedPtr::alloc(cs, || { + DemoQuery::Factorial(n) => Some(Self::Factorial(AllocatedPtr::alloc(cs, || { Ok(s.hash_ptr(&n)) })?)), _ => unreachable!(), @@ -227,6 +220,10 @@ impl CircuitQuery for DemoCircuitQuery { None }) } + + fn symbol(&self) -> Symbol { + todo!() + } } #[cfg(test)] diff --git a/src/coprocessor/memoset/mod.rs b/src/coprocessor/memoset/mod.rs index 892181bc5d..816ad86434 100644 --- a/src/coprocessor/memoset/mod.rs +++ b/src/coprocessor/memoset/mod.rs @@ -340,14 +340,14 @@ impl> Scope> { (transcript, unique_keys) } - pub fn synthesize, CQ: CircuitQuery>( + pub fn synthesize>( &mut self, cs: &mut CS, g: &mut GlobalAllocator, s: &Store, ) -> Result<(), SynthesisError> { self.ensure_transcript_finalized(s); - let mut circuit_scope: CircuitScope<_, CQ, _> = + let mut circuit_scope: CircuitScope<_, Q::CQ, _> = CircuitScope::from_scope(&mut cs.namespace(|| "transcript"), g, s, self); circuit_scope.init(cs, g, s); { @@ -360,11 +360,11 @@ impl> Scope> { } impl> CircuitScope> { - pub fn from_scope>( + fn from_scope, Q: Query>( cs: &mut CS, g: &mut GlobalAllocator, s: &Store, - scope: &Scope>, + scope: &Scope>, ) -> Self { let queries = scope .queries @@ -498,9 +498,9 @@ impl> CircuitScope> { Ok((value, new_acc, new_insertion_transcript)) } - fn synthesize_insert_toplevel_queries>( + fn synthesize_insert_toplevel_queries, Q: Query>( &mut self, - scope: &mut Scope>, + scope: &mut Scope>, cs: &mut CS, g: &mut GlobalAllocator, s: &Store, @@ -548,9 +548,9 @@ impl> CircuitScope> { Ok(()) } - fn synthesize_prove_all_queries>( + fn synthesize_prove_all_queries, Q: Query>( &mut self, - scope: &mut Scope>, + scope: &mut Scope>, cs: &mut CS, g: &mut GlobalAllocator, s: &Store, @@ -746,18 +746,15 @@ mod test { use crate::state::State; use bellpepper_core::{test_cs::TestConstraintSystem, Comparable}; - use demo::DemoCircuitQuery; + use demo::DemoQuery; use expect_test::{expect, Expect}; use pasta_curves::pallas::Scalar as F; use std::default::Default; - type ScopeCircuitQuery = DemoCircuitQuery; - type ScopeQuery = as CircuitQuery>::Q; - #[test] fn test_query() { let s = &Store::::default(); - let mut scope: Scope, LogMemo> = Scope::default(); + let mut scope: Scope, LogMemo> = Scope::default(); let state = State::init_lurk_state(); let fact_4 = s.read_with_default_state("(factorial 4)").unwrap(); @@ -785,9 +782,7 @@ mod test { let cs = &mut TestConstraintSystem::new(); let g = &mut GlobalAllocator::default(); - scope - .synthesize::<_, ScopeCircuitQuery>(cs, g, s) - .unwrap(); + scope.synthesize(cs, g, s).unwrap(); println!( "transcript: {}", @@ -810,7 +805,7 @@ mod test { assert!(cs.is_satisfied()); } { - let mut scope: Scope, LogMemo> = Scope::default(); + let mut scope: Scope, LogMemo> = Scope::default(); scope.query(s, fact_4); scope.query(s, fact_3); @@ -826,9 +821,7 @@ mod test { let cs = &mut TestConstraintSystem::new(); let g = &mut GlobalAllocator::default(); - scope - .synthesize::<_, ScopeCircuitQuery>(cs, g, s) - .unwrap(); + scope.synthesize(cs, g, s).unwrap(); expect_eq(cs.num_constraints(), expect!["11408"]); expect_eq(cs.aux().len(), expect!["11445"]); diff --git a/src/coprocessor/memoset/query.rs b/src/coprocessor/memoset/query.rs index a2a8bb7b8f..0ef04d9607 100644 --- a/src/coprocessor/memoset/query.rs +++ b/src/coprocessor/memoset/query.rs @@ -11,6 +11,8 @@ pub trait Query where Self: Sized + Clone, { + type CQ: CircuitQuery; + fn eval(&self, s: &Store, scope: &mut Scope>) -> Ptr; fn recursive_eval( &self, @@ -33,8 +35,6 @@ pub trait CircuitQuery where Self: Sized + Clone, { - type Q: Query; - fn synthesize_eval>( &self, cs: &mut CS, @@ -45,12 +45,10 @@ where transcript: &CircuitTranscript, ) -> Result<(AllocatedPtr, AllocatedPtr, CircuitTranscript), SynthesisError>; - fn symbol(&self, s: &Store) -> Symbol { - self.dummy_query_variant(s).symbol() - } + fn symbol(&self) -> Symbol; fn symbol_ptr(&self, s: &Store) -> Ptr { - self.dummy_query_variant(s).symbol_ptr(s) + s.intern_symbol(&self.symbol()) } fn from_ptr>( @@ -58,6 +56,4 @@ where s: &Store, ptr: &Ptr, ) -> Result, SynthesisError>; - - fn dummy_query_variant(&self, s: &Store) -> Self::Q; }