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
Fix exp circuit padding #1062
Fix exp circuit padding #1062
Conversation
I'm having an issue with cells not being assigned. Specifically, when starting at the padding offset, I can enable selectors of 3 rows until the 4th row, in which it throws an error like so |
I think the issue is that what you call the self.q_usable.enable(region, offset)?;
dbg!(offset + 1);
self.q_usable.enable(region, offset + 1)?;
dbg!(offset + 2);
self.q_usable.enable(region, offset + 2)?;
dbg!(offset + 3);
self.q_usable.enable(region, offset + 3)?;
dbg!(offset + 4);
self.q_usable.enable(region, offset + 4)?; This is enabling the
I have some questions about the approach for the constant fixed columns. I see that the ExpCircuit can be divided into steps, where each step takes 7 rows. I think we should have a parameter called |
We can put this PR on hold until privacy-scaling-explorations/zkevm-specs#359 is reviewed and merged. |
The approach followed in the last two commits seems to be working! Regarding choosing the circuit length (currently you're doing Also, could you add the following test (or a similar one) that verifies that the fixed columns stay constant no matter the input? #[test]
fn variadic_size_check() {
let k = 20;
// Empty
let block: GethData = TestContext::<0, 0>::new(None, |_| {}, |_, _| {}, |b, _| b)
.unwrap()
.into();
let mut builder =
BlockData::new_from_geth_data_with_params(block.clone(), CircuitsParams::default())
.new_circuit_input_builder();
builder
.handle_block(&block.eth_block, &block.geth_traces)
.unwrap();
let block = block_convert::<Fr>(&builder.block, &builder.code_db).unwrap();
let circuit = ExpCircuit::<Fr>::new(block);
let prover1 = MockProver::<Fr>::run(k, &circuit, vec![]).unwrap();
// Non-empty
let code = bytecode! {
PUSH32(8)
PUSH32(10)
EXP
PUSH32(3)
PUSH32(5)
EXP
STOP
};
let builder = gen_data(code);
let block = block_convert::<Fr>(&builder.block, &builder.code_db).unwrap();
let circuit = ExpCircuit::<Fr>::new(block);
let prover2 = MockProver::<Fr>::run(k, &circuit, vec![]).unwrap();
assert_eq!(prover1.fixed(), prover2.fixed());
assert_eq!(prover1.permutation(), prover2.permutation());
} I tried this test on the current state of the PR and it passes :) |
Hi @ed255, I think the passed in parameter k is of the form 1 << k because I passed in self.size which is equal to 1 << k. The latest commit actually does not pass the unit tests. If you pull the latest commit from the branch, and run cargo test --package zkevm-circuits --lib -- exp_circuit::tests::exp_circuit_single --exact you will get this error: |
Also, what should the default max_exp_rows value be? I've been testing 1 << 18 most of the time. |
I see! In that case I suggest using the variable name
I didn't check any unit tests, I only tried running the
I think we should consider a default value that is good for testing. Maybe |
I have debugged the |
@ed255 whats the difference between the value k that is inputted into MockProver::run and max_rows? I am testing with k = 10 (1 << 10 = 1024) and max_rows = 1000. I'm getting a new error when trying this:
Does this mean there is a cell outside the usable rows range? But usable rows should be between 0..1000? |
In
Ah, halo2 doesn't report too much details here... Actually the I've spent some time debugging and I made a branch with a commit that fixes the issues (and makes all the tests pass). Please take a look: 3e17bbf In particular the files:
I used a local version of halo2 to add debugging logs. The approach I followed in the commit is:
Please review the changes and feel free to integrate them in this PR or discuss them here :) |
@ed255 I spent some time updating this as well. I am in favour of The minimum number of rows required would be calculated by the number of steps in the exponentiation trace times Wdyt? @rrzhang139 Is the above explanation clear? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, added a few comments though!
@ed255 @roynalnaruto If you can resolve my failing test cases that would be very much appreciated. Somehow failing on testtool even though I never touched it. |
I can look into it tomorrow! |
This should fix it, can you try this change? --- a/zkevm-circuits/src/table.rs
+++ b/zkevm-circuits/src/table.rs
@@ -1297,7 +1297,7 @@ impl ExpTable {
}
// pad an empty row
- let row = [F::from_u128(0); 6];
+ let row = [F::from_u128(0); 5];
for (column, value) in exp_table_columns.iter().zip_eq(row) {
region.assign_advice(
|| format!("exponentiation table row {}", offset), |
@rrzhang139 Could you resolve conflicts coming from the latest update to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Great job! 😀
Need to enforce the soundness of the exp_circuit padding. Basically there is no selector that fixes the padding so padding constraints are not being checked.