From 924f9fed5c2067b732a9b27be8debf2da0661c49 Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Fri, 5 Jan 2024 09:25:20 +0100 Subject: [PATCH 1/3] powers_array & tests --- src/common.cairo | 1 + src/common/powers_array.cairo | 19 ++++++++++++++ src/common/tests.cairo | 2 ++ src/common/tests/test_powers_array.cairo | 33 ++++++++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 src/common/powers_array.cairo create mode 100644 src/common/tests/test_powers_array.cairo diff --git a/src/common.cairo b/src/common.cairo index 68b1bdd9c..f18c38db1 100644 --- a/src/common.cairo +++ b/src/common.cairo @@ -9,6 +9,7 @@ mod array_extend; mod array_split; mod consts; mod merge_sort; +mod powers_array; #[cfg(test)] mod tests; diff --git a/src/common/powers_array.cairo b/src/common/powers_array.cairo new file mode 100644 index 000000000..ef46fdb90 --- /dev/null +++ b/src/common/powers_array.cairo @@ -0,0 +1,19 @@ +// Writes the following `n` values into array: +// cur, cur * alpha, cur * alpha^2, ..., cur * alpha^(n - 1). +fn powers_array(cur: felt252, alpha: felt252, n: u32) -> Array { + let mut array = ArrayTrait::::new(); + let mut value = cur; + let mut i: u32 = 0; + loop { + if i == n { + break; + } + + array.append(value); + value *= alpha; + + i += 1; + }; + + array +} diff --git a/src/common/tests.cairo b/src/common/tests.cairo index 2dca85a79..6ef483ee4 100644 --- a/src/common/tests.cairo +++ b/src/common/tests.cairo @@ -5,6 +5,8 @@ mod test_horner_eval; mod test_array_append; mod test_math; mod test_merge_sort; +mod test_powers_array; + // notice: this test takes a lot of time and computation // uncomment it when making changes to blake2s // mod test_blake2s_big; diff --git a/src/common/tests/test_powers_array.cairo b/src/common/tests/test_powers_array.cairo new file mode 100644 index 000000000..34cd30bff --- /dev/null +++ b/src/common/tests/test_powers_array.cairo @@ -0,0 +1,33 @@ +use cairo_verifier::common::powers_array::powers_array; + +#[test] +#[available_gas(9999999999)] +fn test_powers_array_0() { + assert( + powers_array( + 8939912, 818129, 20 + ) == array![ + 8939912, + 7314001264648, + 5983796540645203592, + 4895517480001519769519368, + 4005164820396163367517111022472, + 3276741489345892739703406523703994888, + 2680797237937065881240808275831425633724552, + 2193237963476213772353661233897688422293434003208, + 1794351581820831297361928511627481931242504867610557832, + 1468011065283494888479417211289280164925499264833358068536328, + 1201022424829320389616777123654887492050333788038850403253557490312, + 982591275403187061036784251398649448983647531674436641563429735991466248, + 578798470452897618157604965420111599212769637660707731620770014798701463210, + 64897154080296376744067237228250081708262563085217890232603082073306308506, + 3570855249317241879864852740142508196913411001040536104120285926502587208042, + 296822332749766136374571546668437122679929036177024349694690002078960735182, + 1236122849353634764512930791639952640937217569299656172828823579696019234568, + 1554236852172389644389568626430917567621998253096118392892400158736329812430, + 2650676934462094271980856993953144424194696459174707922062388312529884397184, + 1618947405625354125126437534914831315303549411394098205806855140739005342069 + ], + 'Invalid value' + ); +} From cb3054c492ae8fb08105b2b9ee9c430b453bfc4c Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Fri, 5 Jan 2024 09:25:57 +0100 Subject: [PATCH 2/3] fmt --- src/common/tests.cairo | 1 - 1 file changed, 1 deletion(-) diff --git a/src/common/tests.cairo b/src/common/tests.cairo index 6ef483ee4..5d623fe1a 100644 --- a/src/common/tests.cairo +++ b/src/common/tests.cairo @@ -6,7 +6,6 @@ mod test_array_append; mod test_math; mod test_merge_sort; mod test_powers_array; - // notice: this test takes a lot of time and computation // uncomment it when making changes to blake2s // mod test_blake2s_big; From da4e0bfe81db341ef3a9698674a16282130f6409 Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Fri, 5 Jan 2024 16:39:16 +0100 Subject: [PATCH 3/3] param rename --- src/common/powers_array.cairo | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/powers_array.cairo b/src/common/powers_array.cairo index ef46fdb90..afc19a3f0 100644 --- a/src/common/powers_array.cairo +++ b/src/common/powers_array.cairo @@ -1,8 +1,8 @@ // Writes the following `n` values into array: -// cur, cur * alpha, cur * alpha^2, ..., cur * alpha^(n - 1). -fn powers_array(cur: felt252, alpha: felt252, n: u32) -> Array { +// initial, initial * alpha, initial * alpha^2, ..., initial * alpha^(n - 1). +fn powers_array(initial: felt252, alpha: felt252, n: u32) -> Array { let mut array = ArrayTrait::::new(); - let mut value = cur; + let mut value = initial; let mut i: u32 = 0; loop { if i == n {