Skip to content

Commit 6464ac6

Browse files
committed
fix(test): Fix flaky test caused by sampling+allocating 0 words
This closes #132.
1 parent 9511d51 commit 6464ac6

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

tasm-lib/src/hashing/algebraic_hasher/sample_scalars_static_length_kmalloc.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ impl SampleScalarsStaticLengthKMalloc {
3333
.try_into()
3434
.unwrap()
3535
}
36-
37-
pub(crate) fn scalars_kmalloc_name(&self) -> String {
38-
let num_elements_to_sample = self.num_elements_to_sample;
39-
let extra_capacity = self.extra_capacity;
40-
format!("scalars_kmalloc_{num_elements_to_sample}_{extra_capacity}")
41-
}
4236
}
4337

4438
impl BasicSnippet for SampleScalarsStaticLengthKMalloc {
@@ -60,6 +54,10 @@ impl BasicSnippet for SampleScalarsStaticLengthKMalloc {
6054
fn code(&self, library: &mut Library) -> Vec<LabelledInstruction> {
6155
assert_eq!(10, tip5::RATE, "Code assumes Tip5's RATE is 10");
6256
assert_eq!(3, EXTENSION_DEGREE, "Code assumes extension degree 3");
57+
assert!(
58+
self.extra_capacity + self.num_elements_to_sample > 0,
59+
"Must allocate positive number of words"
60+
);
6361
let num_squeezes =
6462
SampleScalarsStaticLengthDynMalloc::num_squeezes(self.num_elements_to_sample);
6563

@@ -73,8 +71,7 @@ impl BasicSnippet for SampleScalarsStaticLengthKMalloc {
7371
let entrypoint = self.entrypoint();
7472
let squeeze_repeatedly_static_number =
7573
library.import(Box::new(SqueezeRepeatedlyStaticNumber { num_squeezes }));
76-
let scalars_pointer =
77-
library.pub_kmalloc(self.num_words_to_allocate(), self.scalars_kmalloc_name());
74+
let scalars_pointer = library.kmalloc(self.num_words_to_allocate());
7875

7976
triton_asm!(
8077
{entrypoint}:
@@ -182,8 +179,8 @@ pub(crate) mod tests {
182179

183180
#[proptest]
184181
fn verify_agreement_with_tip5_sample_scalars(
185-
#[strategy(0_usize..500)] num_elements_to_sample: usize,
186-
#[strategy(0_usize..500)] extra_capacity: usize,
182+
#[strategy(1_usize..500)] num_elements_to_sample: usize,
183+
#[strategy(1_usize..500)] extra_capacity: usize,
187184
#[strategy(arb())] mut sponge: Tip5,
188185
) {
189186
let snippet = SampleScalarsStaticLengthKMalloc {

0 commit comments

Comments
 (0)