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

Allow different degrees in witgen #1460

Merged
merged 51 commits into from
Jul 4, 2024
Merged

Allow different degrees in witgen #1460

merged 51 commits into from
Jul 4, 2024

Conversation

Schaeff
Copy link
Collaborator

@Schaeff Schaeff commented Jun 20, 2024

Fixes #1494

  • use cbor for witness and constant files (moving polygon serialisation to the relevant backend)
  • add degree field on Symbol, inherited from the namespace degree
  • have each machine in witgen operate over its own degree
  • fail in the backend if we have many degrees

ast/src/analyzed/mod.rs Outdated Show resolved Hide resolved
@leonardoalt
Copy link
Member

tests failing

let mut namespace =
AbsoluteSymbolPath::default().join(SymbolPath::from_str(name).unwrap());
let name = namespace.pop().unwrap();
if namespace != current_namespace {
Copy link
Member

Choose a reason for hiding this comment

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

Should we add an assertion that the degree is the same within a namespace?

}

/// Returns the set of all degrees in this [`Analyzed<T>`].
Copy link
Member

Choose a reason for hiding this comment

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

Symbols without explicit degree are ignored.

@@ -45,10 +44,28 @@ pub struct Analyzed<T> {
}

impl<T> Analyzed<T> {
/// @returns the degree if any. Panics if there is none.
/// Returns the common degree in this [`Analyzed<T>`].
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Returns the common degree in this [`Analyzed<T>`].
/// Returns the degree common among all symbols that have an explicit degree.

}

for i in 0..degree {
for (_name, constant) in polys {
Copy link
Member

Choose a reason for hiding this comment

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

constant?

@@ -65,18 +67,18 @@ fn create_stark_struct(degree: DegreeType, hash_type: &str) -> StarkStruct {
}
}

type PatchedConstants<F> = Vec<(String, Vec<F>)>;
type Constants<F> = Vec<(String, Vec<F>)>;
Copy link
Member

Choose a reason for hiding this comment

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

Is this typedef needed?

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 was already there thanks to clippy


// Pre-process the PIL and fixed columns.
let (pil, patched_constants) = first_step_fixup(analyzed, fixed);
let (pil, constants) = first_step_fixup(analyzed, fixed);
Copy link
Member

Choose a reason for hiding this comment

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

If we rename that variable, why not fixed?

@@ -279,6 +286,34 @@ pub struct FixedData<'a, T: FieldElement> {
}

impl<'a, T: FieldElement> FixedData<'a, T> {
pub fn common_degree<'b>(&self, ids: impl IntoIterator<Item = &'b PolyID>) -> DegreeType {
Copy link
Member

Choose a reason for hiding this comment

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

Please document

} else {
self.polynomial_degree = Some(namespace_degree);
}
self.polynomial_degree = Some(namespace_degree);
}
Copy link
Member

@chriseth chriseth Jul 2, 2024

Choose a reason for hiding this comment

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

I would set polynomial_degree to None here in the else case. Otherwise, the next namespace "inherits" the previous namespace's degree if it's not set.

@chriseth
Copy link
Member

chriseth commented Jul 2, 2024

I cannot really comment this in-line, so:

I would remove the degree parameter from Condenser::new and change Condenser::set_namespace to Condenser::set_namespace_and_degree, which takes the namespace and degree from the definition and stores it as the current namespace and degree in Condenser::degree.

chriseth
chriseth previously approved these changes Jul 3, 2024
@chriseth chriseth added this pull request to the merge queue Jul 3, 2024
@chriseth chriseth removed this pull request from the merge queue due to a manual request Jul 3, 2024
@@ -306,6 +306,13 @@ fn naive_byte_decomposition_gl() {
verify_pil(f, Default::default());
}

#[test]
#[should_panic = "NoVariableDegreeAvailable"]
Copy link
Member

Choose a reason for hiding this comment

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

Does this at least run witgen?

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! The error is thrown by the backend.

.collect();
let degrees = self.analyzed.degrees();

let values = match degrees.len() {
Copy link
Member

@chriseth chriseth Jul 4, 2024

Choose a reason for hiding this comment

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

could use match &degrees[..] { [degree] => { ... }, [] => { ... }, _ => unreachable!()}

@Schaeff Schaeff added this pull request to the merge queue Jul 4, 2024
Merged via the queue into main with commit 49ffd47 Jul 4, 2024
6 checks passed
@Schaeff Schaeff deleted the allow-different-degrees branch July 4, 2024 18:00
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.

Witness Generation: Generate columns of different length
3 participants