Skip to content

Commit

Permalink
audit: additional verifications (#78)
Browse files Browse the repository at this point in the history
Audit: adding more verifications to avoid undefined operations
  • Loading branch information
JordyRo1 authored Nov 14, 2023
1 parent df592e9 commit 558f78a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/operations/time_series/convert.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn div_decimals(a_price: u128, b_price: u128, output_decimals: u128) -> u128 {

assert(power <= MAX_POWER, 'Conversion overflow');
assert(a_price <= MAX_POWER, 'Conversion overflow');

assert(b_price > 0, 'Division by zero');
a_price * power / b_price
}

Expand Down
2 changes: 2 additions & 0 deletions src/operations/time_series/metrics.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ fn _sum_volatility(arr: Span<TickElem>) -> Fixed {
let prev_val = *arr.at(cur_idx - 1);
let cur_value = cur_val.value;
let prev_value = prev_val.value;
assert(prev_value.mag > 0, 'failed to compute vol');
let cur_timestamp = cur_val.tick;
let prev_timestamp = prev_val.tick;
assert(cur_timestamp > prev_timestamp, 'failed to compute vol');
if (prev_timestamp > cur_timestamp) {
//edge case
assert(1 == 1, 'failed to compute vol');
Expand Down
3 changes: 3 additions & 0 deletions src/operations/time_series/scaler.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use debug::PrintTrait;
use cubit::f128::types::fixed::{FixedTrait, Fixed, FixedPrint, ONE_u128};

fn calculate_slope(x1: Fixed, x2: Fixed, y1: Fixed, y2: Fixed) -> Fixed {
assert(x2 > x1, 'cannot compute slope(x2<x1)');
(y2 - y1) / (x2 - x1)
}

Expand All @@ -18,6 +19,8 @@ fn calculate_slope(x1: Fixed, x2: Fixed, y1: Fixed, y2: Fixed) -> Fixed {
fn scale_data(
start_tick: u64, end_tick: u64, tick_array: Span<TickElem>, num_intervals: u32
) -> Array<TickElem> {
assert(num_intervals > 1, 'intervals must be > than 1');
assert(start_tick <= end_tick, 'start_tick must be < end_tick');
let interval = (end_tick - start_tick) / (num_intervals.into() - 1);

let mut output: Array<TickElem> = ArrayTrait::new();
Expand Down

0 comments on commit 558f78a

Please sign in to comment.