diff --git a/calc.py b/calc.py deleted file mode 100644 index 242e6604b..000000000 --- a/calc.py +++ /dev/null @@ -1,3 +0,0 @@ -DEFAULT_PRIME = 2**251 + 17 * 2**192 + 1 - -print((pow(3, DEFAULT_PRIME-2, DEFAULT_PRIME))) \ No newline at end of file diff --git a/src/common.cairo b/src/common.cairo index 0e28c54fc..cf165c02e 100644 --- a/src/common.cairo +++ b/src/common.cairo @@ -6,6 +6,7 @@ mod array_append; mod math; mod array_print; mod array_extend; +mod consts; #[cfg(test)] mod tests; diff --git a/src/common/array_extend.cairo b/src/common/array_extend.cairo index d8cc703c6..08fbe6607 100644 --- a/src/common/array_extend.cairo +++ b/src/common/array_extend.cairo @@ -1,7 +1,4 @@ -trait ArrayExtendTrait { - fn extend(ref self: Array, span: Span); -} - +#[generate_trait] impl ArrayExtend, +Drop> of ArrayExtendTrait { fn extend(ref self: Array, span: Span) { let mut i = 0; diff --git a/src/common/consts.cairo b/src/common/consts.cairo new file mode 100644 index 000000000..195fba4cd --- /dev/null +++ b/src/common/consts.cairo @@ -0,0 +1,2 @@ +const STARK_PRIME_MINUS_TWO: felt252 = + 3618502788666131213697322783095070105623107215331596699973092056135872020479; diff --git a/src/common/math.cairo b/src/common/math.cairo index a7725c167..978aacc95 100644 --- a/src/common/math.cairo +++ b/src/common/math.cairo @@ -1,3 +1,5 @@ +use cairo_verifier::common::consts::STARK_PRIME_MINUS_TWO; + fn pow(base: felt252, exp: felt252) -> felt252 { if exp == 0 { return 1; @@ -23,5 +25,5 @@ fn pow(base: felt252, exp: felt252) -> felt252 { fn mul_inverse(x: felt252) -> felt252 { // From Fermat's little theorem, a ^ (p - 1) = 1 when p is prime and a != 0. Since a ^ (p - 1) = a ยท a ^ (p - 2) we have that // a ^ (p - 2) is the multiplicative inverse of a modulo p. - pow(x, 3618502788666131213697322783095070105623107215331596699973092056135872020479) + pow(x, STARK_PRIME_MINUS_TWO) } diff --git a/src/fri/fri_config.cairo b/src/fri/fri_config.cairo index 63fb9d379..02ff63a0c 100644 --- a/src/fri/fri_config.cairo +++ b/src/fri/fri_config.cairo @@ -27,10 +27,9 @@ struct FriConfig { fn fri_config_validate( config: FriConfig, log_n_cosets: felt252, n_verifier_friendly_commitment_layers: felt252 ) -> felt252 { - let n_layers = config.n_layers.try_into().unwrap(); - let log_last_layer_degree_bound = config.log_last_layer_degree_bound.try_into().unwrap(); + let n_layers: u32 = config.n_layers.try_into().unwrap(); + let log_last_layer_degree_bound: u32 = config.log_last_layer_degree_bound.try_into().unwrap(); - assert(log_last_layer_degree_bound >= 0, 'Must be non negative value'); assert(log_last_layer_degree_bound <= MAX_LAST_LAYER_LOG_DEGREE_BOUND, 'Value too big'); assert(*config.fri_step_sizes.at(0) == 0, 'Invalid value'); diff --git a/src/fri/fri_layer.cairo b/src/fri/fri_layer.cairo index 2136b27de..74842a20e 100644 --- a/src/fri/fri_layer.cairo +++ b/src/fri/fri_layer.cairo @@ -101,7 +101,6 @@ fn compute_next_layer( let coset_size_u256: u256 = coset_size.into(); let coset_index = (index_u256 / coset_size_u256).low.into(); - assert(coset_index.into() >= 0_u256, 'Must be non negative value'); verify_indices.append(coset_index); @@ -116,7 +115,7 @@ fn compute_next_layer( // Verify that at least one query was consumed. let coset_elements_len = coset_elements.len(); - assert(coset_elements_len >= 0, 'Must be non negative value'); + assert(coset_elements_len > 0, 'Must be non negative value'); let coset_elements_span = coset_elements.span();