Closed Sword-Smith closed 2 months ago
This test crashes. Narrows down the problem.
#[test]
fn verify_agreement_with_tip5_sample_scalars_zero_zero() {
let snippet = SampleScalarsStaticLengthKMalloc {
num_elements_to_sample: 0,
extra_capacity: 0,
};
let init_stack = snippet.init_stack_for_isolated_run();
let mut sponge: Tip5 = Sponge::init();
let tasm = tasm_final_state(
&ShadowedProcedure::new(snippet),
&init_stack,
&[],
NonDeterminism::default(),
&Some(sponge.clone()),
);
let scalar_pointer = snippet.k_malloc_address_isolated_run();
let read_scalar = |i| array_get(scalar_pointer, i, &tasm.ram, EXTENSION_DEGREE);
let scalars_from_tip5 = sponge.sample_scalars(0);
for (i, expected_scalar) in scalars_from_tip5.into_iter().enumerate() {
assert_eq!(expected_scalar.coefficients.to_vec(), read_scalar(i));
}
}
The problem happens in kmalloc
because it's called with an argument value of 0
. That probably should be allowed TBH. Let's just add an assert that kmalloc
is not called with an argument of 0
.
pub fn kmalloc(&mut self, num_words: u32) -> BFieldElement {
let address = STATIC_MEMORY_FIRST_ADDRESS
- bfe!(self.num_allocated_words)
- BFieldElement::new(num_words as u64 - 1);
self.num_allocated_words = self
.num_allocated_words
.checked_add(num_words)
.expect("Cannot allocate more that u32::MAX words through `kmalloc`.");
address
}