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

SRAI #463

Merged
merged 21 commits into from
Oct 28, 2024
8 changes: 7 additions & 1 deletion ceno_zkvm/src/chip_handler/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,13 @@ impl<'a, E: ExtensionField> CircuitBuilder<'a, E> {
NR: Into<String>,
N: FnOnce() -> NR,
{
self.namespace(|| "require_equal", |cb| cb.cs.require_zero(name_fn, a - b))
self.namespace(
|| "require_equal",
|cb| {
cb.cs
.require_zero(name_fn, a.to_monomial_form() - b.to_monomial_form())
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this change have to do with SRAI?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is not related to SRAI. This is for MockProver accurate error description. The way MockProver infers assert equal is by destructuring LHS,RHS = Sum(LHS, RHS). After the monomial PR, Mock Prover is not able to infer require equal correctly because to_monomial_form is performed on Sum(LHS, RHS) the result doesn't correctly destructure to what it should be.

This change can be in other PR.

},
)
}

pub fn require_one<NR, N>(&mut self, name_fn: N, expr: Expression<E>) -> Result<(), ZKVMError>
Expand Down
4 changes: 3 additions & 1 deletion ceno_zkvm/src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,9 @@ pub mod fmt {
) -> String {
match expression {
Expression::WitIn(wit_in) => {
wtns.push(*wit_in);
if !wtns.contains(wit_in) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this change have to do with SRAI?

Seems like an unrelated improvement?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is not related to SRAI. If Wtns(x) appears multiple times in the expression, then it is duplicated.

This change can be in other PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm happy to review that extracted PR fast.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Putting unrelated changes in their own PR is best; but as a second best alternative you can also expand the PR description for this PR to include the additional unrelated changes.

wtns.push(*wit_in);
}
format!("WitIn({})", wit_in)
}
Expression::Challenge(id, pow, scaler, offset) => {
Expand Down
28 changes: 25 additions & 3 deletions ceno_zkvm/src/instructions/riscv/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ pub struct MsbConfig {
pub high_limb_no_msb: WitIn,
}

pub struct MsbInput<'a> {
pub limbs: &'a [u8],
pub struct MsbInput<'a, T> {
pub limbs: &'a [T],
}

impl MsbInput<'_> {
impl MsbInput<'_, u8> {
pub fn assign<F: SmallField>(
&self,
instance: &mut [MaybeUninit<F>],
Expand All @@ -43,6 +43,28 @@ impl MsbInput<'_> {
}
}

impl MsbInput<'_, u16> {
pub fn assign<F: SmallField>(
&self,
instance: &mut [MaybeUninit<F>],
config: &MsbConfig,
lk_multiplicity: &mut LkMultiplicity,
) -> (u16, u16) {
let n_limbs = self.limbs.len();
assert!(n_limbs > 0);
let high_limb = self.limbs[n_limbs - 1];
let msb = high_limb >> 15;
assert!(msb == 0 || msb == 1);
set_val!(instance, config.msb, { i64_to_base::<F>(msb as i64) });
let high_limb_no_msb = high_limb & 0b0111_1111_1111_1111;
set_val!(instance, config.high_limb_no_msb, {
i64_to_base::<F>(high_limb_no_msb as i64)
});
lk_multiplicity.assert_ux::<16>((high_limb_no_msb as u64) * 2);
(msb, high_limb_no_msb)
}
}

#[derive(Clone)]
pub struct UIntLtuConfig {
pub indexes: Vec<WitIn>,
Expand Down
Loading
Loading