Skip to content

Commit

Permalink
Merge pull request #1299 from o1-labs/rot/0_64
Browse files Browse the repository at this point in the history
Adds trivial support for rotation by 0 and 64 bits
  • Loading branch information
querolita authored Oct 26, 2023
2 parents 45d3ada + 5eb5fcc commit f637cb7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 4 additions & 4 deletions kimchi/src/circuits/polynomials/rot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ pub fn extend_rot<F: PrimeField>(
rot: u32,
side: RotMode,
) {
assert!(rot < 64, "Rotation value must be less than 64");
assert_ne!(rot, 0, "Rotation value must be non-zero");
assert!(rot <= 64, "Rotation value must be less or equal than 64");

let rot = if side == RotMode::Right {
64 - rot
} else {
Expand All @@ -343,8 +343,8 @@ pub fn extend_rot<F: PrimeField>(
// shifted [------] * 2^rot
// rot = [------|000]
// + [---] excess
let shifted = (word as u128 * 2u128.pow(rot) % 2u128.pow(64)) as u64;
let excess = word / 2u64.pow(64 - rot);
let shifted = (word as u128) * 2u128.pow(rot) % 2u128.pow(64);
let excess = (word as u128) / 2u128.pow(64 - rot);
let rotated = shifted + excess;
// Value for the added value for the bound
// Right input of the "FFAdd" for the bound equation
Expand Down
6 changes: 2 additions & 4 deletions kimchi/src/tests/rot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,20 @@ fn test_rot_random() {
test_rot::<Pallas>(word, rot, RotMode::Right);
}

#[should_panic]
#[test]
// Test that a bad rotation fails as expected
fn test_zero_rot() {
let rng = &mut StdRng::from_seed(RNG_SEED);
let word = rng.gen_range(0..2u128.pow(64)) as u64;
create_rot_witness::<Vesta>(word, 0, RotMode::Left);
test_rot::<Pallas>(word, 0, RotMode::Left);
}

#[should_panic]
#[test]
// Test that a bad rotation fails as expected
fn test_large_rot() {
let rng = &mut StdRng::from_seed(RNG_SEED);
let word = rng.gen_range(0..2u128.pow(64)) as u64;
create_rot_witness::<Vesta>(word, 64, RotMode::Left);
test_rot::<Pallas>(word, 64, RotMode::Left);
}

#[test]
Expand Down

0 comments on commit f637cb7

Please sign in to comment.