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

feat: add halo2_debug package #346

Merged
merged 2 commits into from
Jun 10, 2024
Merged

feat: add halo2_debug package #346

merged 2 commits into from
Jun 10, 2024

Conversation

ed255
Copy link
Member

@ed255 ed255 commented Jun 3, 2024

Introduce a halo2_debug package that fills the need identified in #343

For now it only contains helper types to nicely display prime fields, expressions, lookups and shuffles.

As an example usage I extended the compress_selectors tests:

assert_eq!(
"s_add * (l + r - o)",
format!("{}", expr_disp_names(&cs.gates[0].poly, names))
);
assert_eq!(
"s_mul * (l * r - o)",
format!("{}", expr_disp_names(&cs.gates[1].poly, names))
);
assert_eq!(
"s_cubed * (l * l * l - o)",
format!("{}", expr_disp_names(&cs.gates[2].poly, names))
);
.

NOTE: I just saw this #345 we'll have to converge into the same name 😄

@codecov-commenter
Copy link

codecov-commenter commented Jun 3, 2024

Codecov Report

Attention: Patch coverage is 90.56604% with 25 lines in your changes missing coverage. Please review.

Project coverage is 82.28%. Comparing base (80e69b9) to head (5750849).
Report is 1 commits behind head on main.

Files Patch % Lines
halo2_middleware/src/circuit.rs 56.25% 14 Missing ⚠️
halo2_debug/src/display.rs 97.27% 6 Missing ⚠️
halo2_backend/src/plonk/circuit.rs 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #346      +/-   ##
==========================================
+ Coverage   81.90%   82.28%   +0.38%     
==========================================
  Files          82       83       +1     
  Lines       17019    17458     +439     
==========================================
+ Hits        13939    14366     +427     
- Misses       3080     3092      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

}
}

/// Wrapper type over `Expression` that implements Display with nice output.
Copy link
Member

Choose a reason for hiding this comment

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

Why adding a wrapper when we own the Expression type and we code in in an impl?

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 reason for the wrapper is to be able to include auxiliary information that allows displaying the expressions with column names.
In the Expression type we don't hold the column names, just the column type and index. Then in ConstraintSystemMid we have a HashMap for column names.
ExprDisp can have a reference to this HashMap so that we can show the columns by name, like in this example

assert_eq!(
"s_add * (l + r - o)",
format!("{}", expr_disp_names(&cs.gates[0].poly, names))
);

Without these extra data, we could only print generic names like advice0, fixed2, instance3. I think being able to use named columns makes the expression much more readable.

@adria0
Copy link
Member

adria0 commented Jun 3, 2024

NOTE: I just saw this #345 we'll have to converge into the same name 😄

Renamed to halo2_debug 0c54819

halo2_middleware/src/zal.rs Outdated Show resolved Hide resolved
Copy link

@davidnevadoc davidnevadoc left a comment

Choose a reason for hiding this comment

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

Love this new feature! LGTM 👍


impl<F: PrimeField> fmt::Display for FDisp<'_, F> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let v = (*self.0).to_repr();

Choose a reason for hiding this comment

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

We could have this be a bit cleaner if we just had access to F::MODULUS... For now, I think this is as good as it can be done!

Copy link
Member

@adria0 adria0 left a comment

Choose a reason for hiding this comment

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

Thanks for making the human life easier.
LGTM

@adria0 adria0 merged commit edffc1e into main Jun 10, 2024
18 checks passed
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.

4 participants