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

Add cell name to assertion errors of APIs like assign_advice, assign_fixed, etc. #253

Open
ChihChengLiang opened this issue Jan 22, 2024 · 0 comments

Comments

@ChihChengLiang
Copy link

In the halo2 assign_advice function, we can add a cell name as the function argument, as shown below.

region.assign_advice(|| "a", ...)

But that argument is never used in the function body.

Inside the function body, we have an assertion.:

assert!(
self.usable_rows.contains(&row),
"row={}, usable_rows={:?}, k={}",
row,
self.usable_rows,
self.k,
);

When the panic is triggered, the error message looks like below, it is hard to pin down the actual location of the root cause assignment.

panicked at 'row=131049, usable_rows=0..131049, k=17', .../halo2_proofs/src/dev.rs:494:9

A quick fix is to add the cell name to the panic string, so that the error message looks more helpful.

panicked at 'cell `a`, row=131049, usable_rows=0..131049, k=17', .../halo2_proofs/src/dev.rs:494:9

For a more ambitious goal, we can adopt the style written in this blog post https://mmapped.blog/posts/12-rust-error-handling.html#lift-input-validation. We can abstract the cell name, degree, column, row, and value as a new structure. We can define a validation error for this new struct, so that we no longer need input validation inside the assign_x function.

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

No branches or pull requests

1 participant