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

Refactor Query #1146

Merged
merged 3 commits into from
Feb 20, 2024
Merged

Refactor Query #1146

merged 3 commits into from
Feb 20, 2024

Conversation

porcuquine
Copy link
Collaborator

@porcuquine porcuquine commented Feb 17, 2024

This PR refactors the CircuitQuery and RecursiveCircuitQuery traits to allow more granular implementations. This is a step toward more flexible and optimized Coroutine circuit proofs.

UPDATE: 90d76ea intends to a fix a bug whereby the allocated keys and values were not properly connected.

Notice that this fix remove a few hashes and noticeably reduces constraints, since we are now correctly reusing an allocated value rather than expensively recomputing it.

@porcuquine porcuquine requested a review from a team as a code owner February 17, 2024 22:48
@porcuquine porcuquine marked this pull request as draft February 20, 2024 03:19
@porcuquine porcuquine changed the title Refactor Query to be more granular. Refactor Query Feb 20, 2024
@porcuquine porcuquine force-pushed the query-refactor branch 2 times, most recently from c69001e to 90d76ea Compare February 20, 2024 07:11
@porcuquine porcuquine marked this pull request as ready for review February 20, 2024 07:11
Comment on lines +1153 to +1161
let (key, value) = s.car_cdr(kv).expect("kv missing");
// NOTE: This is an unconstrained allocation, but when actually hooked up to Lurk reduction, it must be
// constrained appropriately.
let allocated_key =
AllocatedPtr::alloc(ns!(cs, "allocated_key"), || Ok(s.hash_ptr(&key))).unwrap();
// NOTE: The returned value is unused here, but when actually hooked up to Lurk reduction, it must be used
// as the result of evaluating the query.
let _allocated_value =
self.synthesize_toplevel_query(cs, g, s, i, &allocated_key, value)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By "constrained appropriately", you mean that the Lurk reduction will be computed the allocated_key and that the circuit_scope would allocate the allocated_value that would be reused here ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

adr1anh
adr1anh previously approved these changes Feb 20, 2024
@@ -87,8 +88,13 @@ where
store: &Store<F>,
result: AllocatedPtr<F>,
dependency_provenances: Vec<AllocatedPtr<F>>,
allocated_key: Option<&AllocatedPtr<F>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why you're passing an option here, since you only call this function once on a Some

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I wasn't sure if we would need to do this the other way. It's just for generality. Once we get this completely nailed down (and optimized), we can remove any unneeded code paths.

q.clone()
} else {
self.synthesize_query(ns!(cs, "query"), g, store)?
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems dangerous. none/some will lead to non-uniform circuits

@gabriel-barrett gabriel-barrett added this pull request to the merge queue Feb 20, 2024
Merged via the queue into main with commit 6f838e0 Feb 20, 2024
11 checks passed
@gabriel-barrett gabriel-barrett deleted the query-refactor branch February 20, 2024 21:58
winston-h-zhang pushed a commit that referenced this pull request Feb 27, 2024
* Refactor Query to be more granular.

* Use allocated_key when proving query.

* Fixed `allocated_key` (#1156)

---------

Co-authored-by: porcuquine <porcuquine@users.noreply.github.com>
Co-authored-by: Gabriel Barreto <gabriel.aquino.barreto@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants