-
Notifications
You must be signed in to change notification settings - Fork 72
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
Block machine witgen: Always run default sequence after the cached sequence #1562
Conversation
5436684
to
aa1048d
Compare
@@ -517,18 +510,6 @@ impl<'a, T: FieldElement> BlockMachine<'a, T> { | |||
let process_result = | |||
self.process(mutable_state, &mut sequence_iterator, outer_query.clone())?; | |||
|
|||
let process_result = if sequence_iterator.is_cached() && !process_result.is_success() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code tried to solve the same problem.
Disadvantages of the old approach:
process_result.is_success()
returnstrue
if it was able to complete the outer query. But there might still be cells in the block that could not be solved. They will be set to 0, which might violate some constraints. This causes the issue described in Witgen produces wrong witness when reordering constraints #1559.- If this block does get executed, the block processor is invoked again from scratch, forgetting any progress it has made already in the first call.
std/machines/split/split_gl.asm
Outdated
@@ -70,11 +70,11 @@ machine SplitGL with | |||
let P_B: col = b; | |||
col fixed P_LT(i) { if a(i) < b(i) { 1 } else { 0 } }; | |||
col fixed P_GT(i) { if a(i) > b(i) { 1 } else { 0 } }; | |||
[ bytes, BYTES_MAX, lt, gt ] in [ P_A, P_B, P_LT, P_GT ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change makes the machine less readable in my opinion. Also in my example it was triggered by the lookup being after was_lt
, does this also trigger it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think I did the same and when trying to undo the change, I put it in the wrong place. Fixed now!
Fixes #1559 (alternative to #1560)
With this PR, we always run the "default" sequence iterator, even if we have a cached sequence (which is still run before). This way, if the cached sequence was not sufficient to solve the entire block, the default solving sequence will have another attempt.
The reason this doesn't lead to a dramatic performance degradation is because since #1528, we skip identities that have been completed. In the typical case, the cached sequence will have completed most identities.
The reason this is better than #1560 is because the cached sequence typically makes progress with every identity, whereas the default iterator does not.
Benchmark
I ran the RISC-V Keccak example 3 times. It looks like the time spent in block machines increases by roughly 20%. Given that this fixes a bug and the overall time spent in block machines is small (even in the bitwise-heavy Keccak example), I think it's worth it!
Main
This branch