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

Access to nonconstant fixed columns. #2368

Merged
merged 9 commits into from
Jan 23, 2025

Conversation

chriseth
Copy link
Member

@chriseth chriseth commented Jan 21, 2025

Some machines need non-constant fixed column values even outside of fixed lookups. An example for that is the STEP column in a riscv VM.

This PR introduces variables for those columns and implements access in the compiled code.

id: column,
ptype: PolynomialType::Constant,
};
// TODO which size?
Copy link
Member Author

Choose a reason for hiding this comment

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

Does it always work to use the largest one?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it should be fine, if some outer code still decides when to down-size and handles the corner cases of the last row. We do most of the computation assuming we'll pick the largest size, end then downscale and full up the remaining rows.

Copy link
Member Author

Choose a reason for hiding this comment

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

But that's not the issue - the question is: Can we pick the largest size and assume it's the same value in the other sizes?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's the assumption we currently go with already ;) We could assert that as well.

Copy link
Collaborator

@georgwiese georgwiese left a comment

Choose a reason for hiding this comment

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

Nice!

id: column,
ptype: PolynomialType::Constant,
};
// TODO which size?
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it should be fine, if some outer code still decides when to down-size and handles the corner cases of the last row. We do most of the computation assuming we'll pick the largest size, end then downscale and full up the remaining rows.

@@ -16,6 +16,8 @@ pub enum Variable {
/// An input or output value of a machine call on a certain
/// identity on a certain row offset.
MachineCallParam(MachineCallVariable),
/// A fixed column cell.
FixedColumn(Cell),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
FixedColumn(Cell),
FixedCell(Cell),

No? And also, we should rename Cell -> WitnessCell.

@@ -456,11 +459,27 @@ impl<'a, T: FieldElement, FixedEval: FixedEvaluator<T>> WitgenInference<'a, T, F
true
}

/// Record a variable as known. Return true if it was not known before.
fn record_known(&mut self, variable: Variable) -> bool {
// We do not record fixed columns as known.
Copy link
Collaborator

Choose a reason for hiding this comment

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

A consequence of this is that it is not returned by known_variables(), and a consequence of that is that we'll never branch on fixed column values. I don't see where this would be useful, but it's not the most consistent behavior.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it hurt to initialize the known values with all fixed cells?

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem is that we don't know which row offsets we will operate on

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh and there is #2369 to fix this

variable
.try_to_witness_poly_id()
.try_to_poly_id()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice, so we do get range constraints on fixed columns too.

georgwiese
georgwiese previously approved these changes Jan 23, 2025
@chriseth chriseth added this pull request to the merge queue Jan 23, 2025
…0e956786ecbb89ecd302c089de815bc8ec8b356' into access_to_nonconstant_fixed_columns
@chriseth chriseth removed this pull request from the merge queue due to a manual request Jan 23, 2025
georgwiese
georgwiese previously approved these changes Jan 23, 2025
@chriseth chriseth dismissed georgwiese’s stale review January 23, 2025 11:18

The merge-base changed after approval.

georgwiese
georgwiese previously approved these changes Jan 23, 2025
@chriseth chriseth dismissed georgwiese’s stale review January 23, 2025 11:43

The merge-base changed after approval.

@georgwiese georgwiese enabled auto-merge January 23, 2025 11:43
@georgwiese georgwiese added this pull request to the merge queue Jan 23, 2025
Merged via the queue into main with commit 229272f Jan 23, 2025
16 checks passed
@georgwiese georgwiese deleted the access_to_nonconstant_fixed_columns branch January 23, 2025 13:39
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.

2 participants