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

Witgen: Pass range constraints to callee #1389

Merged
merged 13 commits into from
May 28, 2024
Merged

Conversation

georgwiese
Copy link
Collaborator

@georgwiese georgwiese commented May 21, 2024

Cherry-picked b1a07bd from #1380, and extended on it.

Fixes #1382.

With this PR, a lookup like selector { byte_lower + 256 * byte_upper } in { <some other machine> } works, even if the range constraints on byte_lower and byte_upper are not "global". For example, they could be implemented as selector { byte_lower } in { BYTES } (i.e., byte_lower is only range constrained when the machine call is active).

To make this work, I changed the Machine::process_plookup interface like this:

    fn process_plookup<'b, Q: QueryCallback<T>>(
        &mut self,
        mutable_state: &'b mut MutableState<'a, 'b, T, Q>,
        identity_id: u64,
-       args: &[AffineExpression<&'a AlgebraicReference, T>],
+       caller_rows: &'b RowPair<'b, 'a, T>,
    ) -> EvalResult<'a, T>;

The RowPair passed by the caller contains all range constraints known at runtime. The LHS of the lookup (or permutation) is no longer evaluated by the caller but by the callee. For this, the callee needs to remember the identity associated with the identity_id (before this PR, most machines just remembered the RHS, not the full identity). I don't expect there to be any performance implications, because we only invoke one machine (since #1154).

Benchmark results

executor-benchmark/keccak
                        time:   [14.609 s 14.645 s 14.678 s]
                        change: [-2.5984% -2.3127% -2.0090%] (p = 0.00 < 0.05)
                        Performance has improved.

executor-benchmark/many_chunks_chunk_0
                        time:   [39.299 s 39.380 s 39.452 s]
                        change: [-3.9505% -3.6909% -3.4063%] (p = 0.00 < 0.05)
                        Performance has improved.

Comment on lines -48 to -52
/// Process a plookup. Not all values on the LHS need to be available.
/// Can update internal data.
/// Only return an error if this machine is able to handle the query and
/// it results in a constraint failure.
/// If this is not the right machine for the query, return `None`.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This comment was outdated.

@georgwiese georgwiese changed the title [WIP] Witgen: Pass range constraints to callee Witgen: Pass range constraints to callee May 24, 2024
@georgwiese georgwiese marked this pull request as ready for review May 24, 2024 13:46
Copy link
Member

@leonardoalt leonardoalt left a comment

Choose a reason for hiding this comment

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

just one comment

test_data/asm/pass_range_constraints.asm Outdated Show resolved Hide resolved
Co-authored-by: Leo <leo@powdrlabs.com>
@leonardoalt leonardoalt added this pull request to the merge queue May 28, 2024
Merged via the queue into main with commit f2457f2 May 28, 2024
6 checks passed
@leonardoalt leonardoalt deleted the pass-range-constraints branch May 28, 2024 19:08
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.

Witgen: Range constraints not transferred for machine-to-machine call
2 participants