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

Filter later-stage witnesses and identities #2129

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

georgwiese
Copy link
Collaborator

@georgwiese georgwiese commented Nov 22, 2024

Prepares #2129

With this PR, later-stage witness columns & identities referencing them (or later-stage challenges) are completely ignored. The columns are not assigned to any machine. Previously, they would end up in the main machine and never receive any updates. That doesn't work if machines have different sized though.

Comment on lines -64 to -66
refs_in_parsed_expression(pf).unique().all(|n| {
let def = self.fixed.analyzed.definitions.get(n);
def.and_then(|(s, _)| s.stage).unwrap_or_default() <= stage as u32
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this was actually wrong, it wouldn't resolve array elements.

@georgwiese georgwiese changed the title [WIP] Filter later-stage witnesses and identities Filter later-stage witnesses and identities Nov 22, 2024
@georgwiese georgwiese marked this pull request as ready for review November 22, 2024 12:36
@@ -225,7 +233,7 @@ impl<'a, 'b, T: FieldElement> WitnessGenerator<'a, 'b, T> {
mut machines,
base_parts,
} = if self.stage == 0 {
MachineExtractor::new(&fixed).split_out_machines(retained_identities, self.stage)
MachineExtractor::new(&fixed).split_out_machines(retained_identities)
Copy link
Collaborator

Choose a reason for hiding this comment

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

So we don't pass the stage because we already only pass the identities up to this stage

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, and also the machine extractor can use functions like FixedData::current_stage_witnesses.

fn current_stage_witnesses(&self) -> impl Iterator<Item = PolyID> + '_ {
self.witness_cols
.iter()
.filter(|(_, col)| col.stage <= self.stage as u32)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't this filtering already happen in the constructor?

Copy link
Member

Choose a reason for hiding this comment

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

And shouldn't it be == self.stage?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Doesn't this filtering already happen in the constructor?

No

And shouldn't it be == self.stage?

I mean it's only currently used by the MachineExtractor, which is only run in stage 0, so it doesn't matter in practice. But I think it makes more sense to have a function that returns all witnesses relevant in the current stage, which would include previous-stage witnesses. Maybe I should rename it to witnesses_for_current_stage()?

Copy link
Member

Choose a reason for hiding this comment

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

witnesses_until_current_stage

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!

executor/src/witgen/mod.rs Outdated Show resolved Hide resolved
fn polynomial_references(
&self,
expr: &impl AllChildren<AlgebraicExpression<T>>,
) -> HashSet<PolyID> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it fine for this to be non-deterministic? Maybe BTreeSet is safer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It shouldn't matter, but I can change it!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, it is used by the machine extractor, which uses hash sets everywhere. It would propagate quite far, so unless you feel strongly about it, I'd leave it as is. As long as its only used as a set, it should be fine.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not strongly, all good.

@@ -375,6 +383,7 @@ pub struct FixedData<'a, T: FieldElement> {
challenges: BTreeMap<u64, T>,
global_range_constraints: GlobalConstraints<T>,
intermediate_definitions: BTreeMap<PolyID, &'a AlgebraicExpression<T>>,
stage: u8,
Copy link
Member

Choose a reason for hiding this comment

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

Now it's only fixed for one stage of witness generation.

Copy link
Member

Choose a reason for hiding this comment

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

Although we already had challenges right?

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, it's fixed for the duration of the call to WitnessGenerator::generate!

Copy link
Member

@chriseth chriseth Nov 22, 2024

Choose a reason for hiding this comment

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

Can you mention that in the docstring? ("Fixed for witness generation for a certain proof stage")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!

Base automatically changed from split-include-prover-functions to main November 22, 2024 15:05
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.

3 participants