Skip to content

Commit

Permalink
add panic for less_than usage in riv64
Browse files Browse the repository at this point in the history
remove tests
  • Loading branch information
zemse committed Sep 9, 2024
1 parent 99c53ed commit 18999b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 109 deletions.
22 changes: 7 additions & 15 deletions ceno_zkvm/src/chip_handler/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ impl<'a, E: ExtensionField> CircuitBuilder<'a, E> {
NR: Into<String> + Display + Clone,
N: FnOnce() -> NR,
{
#[cfg(feature = "riv64")]
panic!("less_than is not supported for riv64 yet");

#[cfg(feature = "riv32")]
self.namespace(
|| "less_than",
|cb| {
Expand Down Expand Up @@ -314,18 +318,9 @@ impl<'a, E: ExtensionField> CircuitBuilder<'a, E> {
)
};

let diff = {
#[cfg(feature = "riv32")]
{
0..2
}
#[cfg(feature = "riv64")]
{
0..4
}
}
.map(|i| witin_u16(format!("diff_{i}")))
.collect::<Result<Vec<WitIn>, _>>()?;
let diff = (0..2)
.map(|i| witin_u16(format!("diff_{i}")))
.collect::<Result<Vec<WitIn>, _>>()?;

let diff_expr = diff
.iter()
Expand All @@ -335,10 +330,7 @@ impl<'a, E: ExtensionField> CircuitBuilder<'a, E> {
sum + if i > 0 { a * (1 << (16 * i)).into() } else { a }
});

#[cfg(feature = "riv32")]
let range = Expression::Constant((u32::MAX as u64).into());
#[cfg(feature = "riv64")]
let range = Expression::Constant(u64::MAX.into()); // TODO beyond modulus

cb.require_equal(|| name.clone(), lhs - rhs, diff_expr - is_lt_expr * range)?;

Expand Down
94 changes: 0 additions & 94 deletions ceno_zkvm/src/scheme/mock_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,6 @@ mod tests {
.into_mle()
.into(),
vec![Goldilocks::from(u16::MAX as u64)].into_mle().into(),
#[cfg(feature = "riv64")]
vec![Goldilocks::from(u16::MAX as u64)].into_mle().into(),
#[cfg(feature = "riv64")]
vec![Goldilocks::from(u16::MAX as u64)].into_mle().into(),
];

MockProver::assert_satisfied(&mut builder, &wits_in, None);
Expand All @@ -592,34 +588,6 @@ mod tests {
.into_mle()
.into(),
vec![Goldilocks::from(u16::MAX as u64)].into_mle().into(),
#[cfg(feature = "riv64")]
vec![Goldilocks::from(u16::MAX as u64)].into_mle().into(),
#[cfg(feature = "riv64")]
vec![Goldilocks::from(u16::MAX as u64)].into_mle().into(),
];

MockProver::assert_satisfied(&mut builder, &wits_in, None);
}

#[test]
#[cfg(feature = "riv64")]
fn test_assert_lt_u64() {
let mut cs = ConstraintSystem::new(|| "test_lt_u64");
let mut builder = CircuitBuilder::<GoldilocksExt2>::new(&mut cs);

let _ = AssertLtCircuit::construct_circuit(&mut builder).unwrap();

let wits_in = vec![
vec![Goldilocks::from(u64::MAX - 5)].into_mle().into(),
vec![Goldilocks::from(u64::MAX - 3)].into_mle().into(),
vec![Goldilocks::from(u16::MAX as u64 + 3 - 5)]
.into_mle()
.into(),
vec![Goldilocks::from(u16::MAX as u64)].into_mle().into(),
#[cfg(feature = "riv64")]
vec![Goldilocks::from(u16::MAX as u64)].into_mle().into(),
#[cfg(feature = "riv64")]
vec![Goldilocks::from(u16::MAX as u64)].into_mle().into(),
];

MockProver::assert_satisfied(&mut builder, &wits_in, None);
Expand Down Expand Up @@ -668,14 +636,6 @@ mod tests {
vec![Goldilocks::from(u16::MAX as u64), Goldilocks::from(0)]
.into_mle()
.into(),
#[cfg(feature = "riv64")]
vec![Goldilocks::from(u16::MAX as u64), Goldilocks::from(0)]
.into_mle()
.into(),
#[cfg(feature = "riv64")]
vec![Goldilocks::from(u16::MAX as u64), Goldilocks::from(0)]
.into_mle()
.into(),
];

MockProver::assert_satisfied(&mut builder, &wits_in, None);
Expand Down Expand Up @@ -713,60 +673,6 @@ mod tests {
vec![Goldilocks::from(u16::MAX as u64), Goldilocks::from(0)]
.into_mle()
.into(),
#[cfg(feature = "riv64")]
vec![Goldilocks::from(u16::MAX as u64), Goldilocks::from(0)]
.into_mle()
.into(),
#[cfg(feature = "riv64")]
vec![Goldilocks::from(u16::MAX as u64), Goldilocks::from(0)]
.into_mle()
.into(),
];

MockProver::assert_satisfied(&mut builder, &wits_in, None);
}

#[test]
#[cfg(feature = "riv64")]
fn test_lt_u64() {
let mut cs = ConstraintSystem::new(|| "test_lt_u64");
let mut builder = CircuitBuilder::<GoldilocksExt2>::new(&mut cs);

let _ = LtCircuit::construct_circuit(&mut builder).unwrap();

let wits_in = vec![
vec![
Goldilocks::from(u64::MAX - 5),
Goldilocks::from(u64::MAX - 3),
]
.into_mle()
.into(),
vec![
Goldilocks::from(u64::MAX - 3),
Goldilocks::from(u64::MAX - 5),
]
.into_mle()
.into(),
vec![Goldilocks::from(1u64), Goldilocks::from(0u64)]
.into_mle()
.into(),
vec![
Goldilocks::from(u16::MAX as u64 + 3 - 5),
Goldilocks::from(5 - 3),
]
.into_mle()
.into(),
vec![Goldilocks::from(u16::MAX as u64), Goldilocks::from(0)]
.into_mle()
.into(),
#[cfg(feature = "riv64")]
vec![Goldilocks::from(u16::MAX as u64), Goldilocks::from(0)]
.into_mle()
.into(),
#[cfg(feature = "riv64")]
vec![Goldilocks::from(u16::MAX as u64), Goldilocks::from(0)]
.into_mle()
.into(),
];

MockProver::assert_satisfied(&mut builder, &wits_in, None);
Expand Down

0 comments on commit 18999b7

Please sign in to comment.