Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/compute powers array #40

Merged
merged 3 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/common.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod array_extend;
mod array_split;
mod consts;
mod merge_sort;
mod powers_array;

#[cfg(test)]
mod tests;
19 changes: 19 additions & 0 deletions src/common/powers_array.cairo
Original file line number Diff line number Diff line change
@@ -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<felt252> {
fmkra marked this conversation as resolved.
Show resolved Hide resolved
let mut array = ArrayTrait::<felt252>::new();
let mut value = cur;
let mut i: u32 = 0;
loop {
if i == n {
break;
}

array.append(value);
value *= alpha;

i += 1;
};

array
}
1 change: 1 addition & 0 deletions src/common/tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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;
Expand Down
33 changes: 33 additions & 0 deletions src/common/tests/test_powers_array.cairo
Original file line number Diff line number Diff line change
@@ -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'
);
}