-
Notifications
You must be signed in to change notification settings - Fork 16
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/divu remainder larger than quotient #335
Conversation
8e15306
to
77a250c
Compare
77a250c
to
37085d1
Compare
fn test_opcode_srl() { | ||
verify::<SrlOp>("basic", 0b_1000, 3, 0b_0001); | ||
// 33 >> 33 === 33 >> 1 | ||
verify::<SrlOp>(0b_1001, 1, 0b_100); | ||
verify::<SrlOp>("rs2 over 5-bits", 0b_1010, 33, 0b_0101); | ||
verify::<SrlOp>("bit loss", 0b_1001, 1, 0b_0100); | ||
verify::<SrlOp>("zero shift", 0b_1000, 0, 0b_1000); | ||
verify::<SrlOp>("all zeros", 0b_0000, 0, 0b_0000); | ||
verify::<SrlOp>("base is zero", 0b_0000, 1, 0b_0000); |
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.
Is it better to merge the test cases?
When we do any change in the future, the cargo test console printing is good, it highlights the tests that fail and pass. This can be a good DX.
If we merge the tests in single one, the tests run serially until mock prover panics in one of them. But if we want just a single test for opcode for less verbosity while cargo test then ok.
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.
I vote +1 for the design, and think for now merge all of them in one place improve readibility, and we dont need to come up with function name for each small case. If we suffer one failed, we can easily targeting which is failed with small effort.
Later, we can have macro to rendering test cases, similar tricks we have in another project zkevm (sth like this https://github.com/privacy-scaling-explorations/zkevm-circuits/blob/main/integration-tests/tests/circuits.rs#L113-L128), so it looks like test are write in single place, but macro will help to expand to rust test implementation. With that, we can achieve both good readibility + rendering test individually.
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.
Is it better to merge the test cases?
When we do any change in the future, the cargo test console printing is good, it highlights the tests that fail and pass. This can be a good DX.
I completely understand your point. I’ve faced similar challenges when verifying tests, just as you mentioned. However, I find that this pattern helps me think about which types of tests might be missing. Having more tests is really important for me, so making the process easier is definitely helpful.
12b7d72
to
a8387c9
Compare
a8387c9
to
77063b7
Compare
On every PR GitHub helpfully complains about 'Unchanged files with check annotations'. So here we silence most of that, to make all our PRs easier to review. Either by outright fixing the issue, or by flagging it to the compiler as a known problem. This should make it easier for me to review eg #335 (or any other PR).
582a84b
to
594bc28
Compare
594bc28
to
9b6d1a6
Compare
…r_larger_than_quotient
128277e
to
681eba9
Compare
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
Thanks for fixing reported issue and refactor :)
Desc.
This PR is trying to integrateDivConfig
introduced in #304 intodivu
opcode. However,DivConfig
fails whendivisor
is zero.Findings
assert_less_than
should beNone
in this case since both oflhs: remainder
andrhs: divisor
are witnesses and range-checked.ceno/ceno_zkvm/src/gadgets/div.rs
Lines 44 to 50 in 77a250c
Update
In the first place, this PR is trying to fix a failure whendivisor
is zero. During fixing this issue, realized we don't really needDivConfig
since there are not much duplicated code betweenSRL
andDIVU
. Therefore, we don't really need to "fix" this issue since it works well onSRL
. But I need to add "remainder < divisor" constraints inDIVU
.I was trying to use
DivConfig
in this PR, but it made more complicated code. So, the current version is only to addremainder < divisor
constraints indivu
.Changes
less_than
divu
SRL
andSLL