diff --git a/CHANGELOG.md b/CHANGELOG.md index e4e2f10302..7e2b25dec4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ #### Upcoming Changes +* refactor: remove static lifetime for name str parameter requirement for constant getter + * fix: add support for arrays shorter than 2 as arguments for cairo1-run [#1737](https://github.com/lambdaclass/cairo-vm/pull/1737) * bugfix: Fix BuiltinRunner::final_stack for SegmentArena[#1747](https://github.com/lambdaclass/cairo-vm/pull/1747) diff --git a/vm/src/hint_processor/builtin_hint_processor/cairo_keccak/keccak_hints.rs b/vm/src/hint_processor/builtin_hint_processor/cairo_keccak/keccak_hints.rs index 202cba60a0..545607669c 100644 --- a/vm/src/hint_processor/builtin_hint_processor/cairo_keccak/keccak_hints.rs +++ b/vm/src/hint_processor/builtin_hint_processor/cairo_keccak/keccak_hints.rs @@ -92,7 +92,7 @@ pub fn compare_bytes_in_word_nondet( // Felt252::from(BYTES_INTO_WORD) into a lazy_static! let bytes_in_word = constants .get(BYTES_IN_WORD) - .ok_or_else(|| HintError::MissingConstant(Box::new(BYTES_IN_WORD)))?; + .ok_or_else(|| HintError::MissingConstant(BYTES_IN_WORD.to_string().into_boxed_str()))?; let value = Felt252::from((n_bytes < bytes_in_word) as usize); insert_value_into_ap(vm, value) } @@ -117,7 +117,9 @@ pub fn compare_keccak_full_rate_in_bytes_nondet( let keccak_full_rate_in_bytes = constants .get(KECCAK_FULL_RATE_IN_BYTES_CAIRO_KECCAK) .or_else(|| constants.get(KECCAK_FULL_RATE_IN_BYTES_BUILTIN_KECCAK)) - .ok_or_else(|| HintError::MissingConstant(Box::new(KECCAK_FULL_RATE_IN_BYTES)))?; + .ok_or_else(|| { + HintError::MissingConstant(KECCAK_FULL_RATE_IN_BYTES.to_string().into_boxed_str()) + })?; let value = Felt252::from((n_bytes >= keccak_full_rate_in_bytes) as usize); insert_value_into_ap(vm, value) } @@ -149,9 +151,9 @@ pub(crate) fn block_permutation_v1( ap_tracking: &ApTracking, constants: &HashMap<String, Felt252>, ) -> Result<(), HintError> { - let keccak_state_size_felts = constants - .get(KECCAK_STATE_SIZE_FELTS) - .ok_or_else(|| HintError::MissingConstant(Box::new(KECCAK_STATE_SIZE_FELTS)))?; + let keccak_state_size_felts = constants.get(KECCAK_STATE_SIZE_FELTS).ok_or_else(|| { + HintError::MissingConstant(KECCAK_STATE_SIZE_FELTS.to_string().into_boxed_str()) + })?; if keccak_state_size_felts >= &Felt252::from(100_i32) { return Err(HintError::InvalidKeccakStateSizeFelt252s(Box::new( *keccak_state_size_felts, @@ -216,9 +218,9 @@ pub(crate) fn block_permutation_v2( ap_tracking: &ApTracking, constants: &HashMap<String, Felt252>, ) -> Result<(), HintError> { - let keccak_state_size_felts = constants - .get(KECCAK_STATE_SIZE_FELTS) - .ok_or_else(|| HintError::MissingConstant(Box::new(KECCAK_STATE_SIZE_FELTS)))?; + let keccak_state_size_felts = constants.get(KECCAK_STATE_SIZE_FELTS).ok_or_else(|| { + HintError::MissingConstant(KECCAK_STATE_SIZE_FELTS.to_string().into_boxed_str()) + })?; if keccak_state_size_felts >= &Felt252::from(100_i32) { return Err(HintError::InvalidKeccakStateSizeFelt252s(Box::new( *keccak_state_size_felts, @@ -253,12 +255,12 @@ fn cairo_keccak_finalize( constants: &HashMap<String, Felt252>, block_size_limit: usize, ) -> Result<(), HintError> { - let keccak_state_size_felts = constants - .get(KECCAK_STATE_SIZE_FELTS) - .ok_or_else(|| HintError::MissingConstant(Box::new(KECCAK_STATE_SIZE_FELTS)))?; + let keccak_state_size_felts = constants.get(KECCAK_STATE_SIZE_FELTS).ok_or_else(|| { + HintError::MissingConstant(KECCAK_STATE_SIZE_FELTS.to_string().into_boxed_str()) + })?; let block_size = constants .get(BLOCK_SIZE) - .ok_or_else(|| HintError::MissingConstant(Box::new(BLOCK_SIZE)))?; + .ok_or_else(|| HintError::MissingConstant(BLOCK_SIZE.to_string().into_boxed_str()))?; if keccak_state_size_felts >= &Felt252::from(100_i32) { return Err(HintError::InvalidKeccakStateSizeFelt252s(Box::new( diff --git a/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs b/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs index 6e0a0ee12f..7e09cc3760 100644 --- a/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs +++ b/vm/src/hint_processor/builtin_hint_processor/hint_utils.rs @@ -120,14 +120,14 @@ pub fn get_reference_from_var_name<'a>( } pub fn get_constant_from_var_name<'a>( - var_name: &'static str, + var_name: &str, constants: &'a HashMap<String, Felt252>, ) -> Result<&'a Felt252, HintError> { constants .iter() .find(|(k, _)| k.rsplit('.').next() == Some(var_name)) .map(|(_, n)| n) - .ok_or_else(|| HintError::MissingConstant(Box::new(var_name))) + .ok_or_else(|| HintError::MissingConstant(var_name.to_string().into_boxed_str())) } #[cfg(test)] diff --git a/vm/src/hint_processor/builtin_hint_processor/keccak_utils.rs b/vm/src/hint_processor/builtin_hint_processor/keccak_utils.rs index 69b593e36f..a23a267891 100644 --- a/vm/src/hint_processor/builtin_hint_processor/keccak_utils.rs +++ b/vm/src/hint_processor/builtin_hint_processor/keccak_utils.rs @@ -249,7 +249,7 @@ pub fn split_n_bytes( let bytes_in_word = constants .get(BYTES_IN_WORD) .and_then(|x| x.to_u64()) - .ok_or_else(|| HintError::MissingConstant(Box::new(BYTES_IN_WORD)))?; + .ok_or_else(|| HintError::MissingConstant(BYTES_IN_WORD.to_string().into_boxed_str()))?; let (high, low) = n_bytes.div_mod_floor(&bytes_in_word); insert_value_from_var_name( "n_words_to_copy", diff --git a/vm/src/hint_processor/builtin_hint_processor/math_utils.rs b/vm/src/hint_processor/builtin_hint_processor/math_utils.rs index ad2c5e0767..4f8c44b492 100644 --- a/vm/src/hint_processor/builtin_hint_processor/math_utils.rs +++ b/vm/src/hint_processor/builtin_hint_processor/math_utils.rs @@ -581,7 +581,7 @@ pub fn is_addr_bounded( ) -> Result<(), HintError> { let addr = get_integer_from_var_name("addr", vm, ids_data, ap_tracking)?; - let addr_bound = constants + let addr_bound = constants .get(ADDR_BOUND) .ok_or_else(|| HintError::MissingConstant(Box::new(ADDR_BOUND)))? .to_biguint(); @@ -2036,7 +2036,7 @@ mod tests { //Execute the hint assert_matches!( run_hint!(vm, ids_data, hint_code), - Err(HintError::MissingConstant(bx)) if *bx == ADDR_BOUND + Err(HintError::MissingConstant(bx)) if &*bx == ADDR_BOUND ); } @@ -2260,7 +2260,7 @@ mod tests { //Execute the hint assert_matches!( run_hint!(vm, ids_data, hint_code), - Err(HintError::MissingConstant(x)) if (*x) == "MAX_HIGH" + Err(HintError::MissingConstant(x)) if &*x == "MAX_HIGH" ); } diff --git a/vm/src/hint_processor/builtin_hint_processor/secp/bigint_utils.rs b/vm/src/hint_processor/builtin_hint_processor/secp/bigint_utils.rs index 5b32f4e691..9a4b3f8841 100644 --- a/vm/src/hint_processor/builtin_hint_processor/secp/bigint_utils.rs +++ b/vm/src/hint_processor/builtin_hint_processor/secp/bigint_utils.rs @@ -149,7 +149,7 @@ pub fn bigint_to_uint256( let d1 = d1.as_ref(); let base_86 = constants .get(BASE_86) - .ok_or_else(|| HintError::MissingConstant(Box::new(BASE_86)))?; + .ok_or_else(|| HintError::MissingConstant(BASE_86.to_string().into_boxed_str()))?; let mask = pow2_const_nz(128); let low = (d0 + (d1 * base_86)).mod_floor(mask); insert_value_from_var_name("low", low, vm, ids_data, ap_tracking) diff --git a/vm/src/hint_processor/builtin_hint_processor/uint384.rs b/vm/src/hint_processor/builtin_hint_processor/uint384.rs index a973fb9d3d..7658061996 100644 --- a/vm/src/hint_processor/builtin_hint_processor/uint384.rs +++ b/vm/src/hint_processor/builtin_hint_processor/uint384.rs @@ -542,7 +542,7 @@ mod tests { //Execute the hint assert_matches!( run_hint!(vm, ids_data, hint_code::ADD_NO_UINT384_CHECK), - Err(HintError::MissingConstant(bx)) if *bx == "SHIFT" + Err(HintError::MissingConstant(bx)) if &*bx == "SHIFT" ); } diff --git a/vm/src/vm/errors/hint_errors.rs b/vm/src/vm/errors/hint_errors.rs index 14d7a27ff7..eecc90eea2 100644 --- a/vm/src/vm/errors/hint_errors.rs +++ b/vm/src/vm/errors/hint_errors.rs @@ -45,7 +45,7 @@ pub enum HintError { #[error("Hint Error: {0}")] CustomHint(Box<str>), #[error("Missing constant: {0}")] - MissingConstant(Box<&'static str>), + MissingConstant(Box<str>), #[error("Fail to get constants for hint execution")] FailedToGetConstant, #[error("Arc too big, {} must be <= {} and {} <= {}", (*.0).0, (*.0).1, (*.0).2, (*.0).3)]