Skip to content

Commit

Permalink
Faster split
Browse files Browse the repository at this point in the history
  • Loading branch information
Oppen committed Oct 26, 2023
1 parent 2c10b8e commit dfb536c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions vm/src/hint_processor/builtin_hint_processor/uint256_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,15 @@ pub fn split_64(
ids_data: &HashMap<String, HintReference>,
ap_tracking: &ApTracking,
) -> Result<(), HintError> {
let shift = Felt252::TWO.pow(64_u32);

let a = get_integer_from_var_name("a", vm, ids_data, ap_tracking)?;
let (high, low) = a.div_rem(&shift.try_into().expect("nonzero by construction"));
let digits = a.to_le_digits();
let mut bytes = [0u8; 32];
bytes[..8].copy_from_slice(&digits[1].to_le_bytes().as_slice());
bytes[8..16].copy_from_slice(&digits[2].to_le_bytes().as_slice());
bytes[16..24].copy_from_slice(&digits[3].to_le_bytes().as_slice());

let low = Felt252::from(digits[0]);
let high = Felt252::from_bytes_le(&bytes.as_slice()).expect("come on!");
insert_value_from_var_name("high", high, vm, ids_data, ap_tracking)?;
insert_value_from_var_name("low", low, vm, ids_data, ap_tracking)
}
Expand Down

0 comments on commit dfb536c

Please sign in to comment.