Skip to content

Commit

Permalink
fixes & refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Dec 2, 2024
1 parent 0da071c commit 17adde9
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 208 deletions.
5 changes: 5 additions & 0 deletions cairo_vm_hints/src/hint_processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ impl CustomHintProcessor {
hints.insert(lib::decoder::evm::has_type_prefix::HINT_HAS_TYPE_PREFIX.into(), lib::decoder::evm::has_type_prefix::hint_has_type_prefix);
hints.insert(lib::decoder::evm::is_byzantium::HINT_IS_BYZANTIUM.into(), lib::decoder::evm::is_byzantium::hint_is_byzantium);
hints.insert(lib::decoder::evm::v_is_encoded::HINT_V_IS_ENCODED.into(), lib::decoder::evm::v_is_encoded::hint_v_is_encoded);
hints.insert(lib::rlp::divmod::HINT_DIVMOD_RLP.into(), lib::rlp::divmod::hint_divmod_rlp);
hints.insert(lib::rlp::divmod::HINT_DIVMOD_VALUE.into(), lib::rlp::divmod::hint_divmod_value);
hints.insert(lib::rlp::item_type::HINT_IS_LONG.into(), lib::rlp::item_type::hint_is_long);
hints.insert(lib::rlp::item_type::HINT_ITEM_TYPE.into(), lib::rlp::item_type::hint_item_type);
hints.insert(lib::rlp::processed_words::HINT_PROCESSED_WORDS.into(), lib::rlp::processed_words::hint_processed_words);
hints.insert(lib::print::PROGRAM_HASH.into(), lib::print::program_hash);
hints.insert(lib::segments::SEGMENTS_ADD.into(), lib::segments::segments_add);
hints.insert(lib::segments::SEGMENTS_ADD_EVM_MEMORIZER_SEGMENT_INDEX.into(), lib::segments::segments_add_evm_memorizer_segment_index);
Expand Down
34 changes: 0 additions & 34 deletions cairo_vm_hints/src/hints/lib/rlp/cur_processed_words.rs

This file was deleted.

122 changes: 122 additions & 0 deletions cairo_vm_hints/src/hints/lib/rlp/divmod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
use cairo_vm::{
hint_processor::builtin_hint_processor::{
builtin_hint_processor_definition::HintProcessorData,
hint_utils::{
get_integer_from_var_name, get_ptr_from_var_name, insert_value_from_var_name,
},
},
types::relocatable::MaybeRelocatable,
};
use cairo_vm::{
types::exec_scope::ExecutionScopes,
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
Felt252,
};
use starknet_types_core::felt::NonZeroFelt;
use std::collections::HashMap;

use crate::hints::vars;

pub const HINT_DIVMOD_RLP: &str = "ids.q, ids.r = divmod(memory[ids.rlp + ids.i], ids.devisor)";

pub fn hint_divmod_rlp(
vm: &mut VirtualMachine,
_exec_scope: &mut ExecutionScopes,
hint_data: &HintProcessorData,
_constants: &HashMap<String, Felt252>,
) -> Result<(), HintError> {
let rlp = get_ptr_from_var_name(
vars::ids::RLP,
vm,
&hint_data.ids_data,
&hint_data.ap_tracking,
)?;

let i: usize = get_integer_from_var_name(
vars::ids::I,
vm,
&hint_data.ids_data,
&hint_data.ap_tracking,
)?
.try_into()
.unwrap();

let devisor = get_integer_from_var_name(
vars::ids::DEVISOR,
vm,
&hint_data.ids_data,
&hint_data.ap_tracking,
)?;

let (q, r) = vm
.get_integer((rlp + i)?)?
.div_rem(&NonZeroFelt::try_from(devisor).unwrap());

insert_value_from_var_name(
vars::ids::Q,
MaybeRelocatable::Int(q),
vm,
&hint_data.ids_data,
&hint_data.ap_tracking,
)?;

insert_value_from_var_name(
vars::ids::R,
MaybeRelocatable::Int(r),
vm,
&hint_data.ids_data,
&hint_data.ap_tracking,
)
}

pub const HINT_DIVMOD_VALUE: &str = "ids.q, ids.r = divmod(memory[ids.value + ids.i], ids.devisor)";

pub fn hint_divmod_value(
vm: &mut VirtualMachine,
_exec_scope: &mut ExecutionScopes,
hint_data: &HintProcessorData,
_constants: &HashMap<String, Felt252>,
) -> Result<(), HintError> {
let value = get_ptr_from_var_name(
vars::ids::VALUE,
vm,
&hint_data.ids_data,
&hint_data.ap_tracking,
)?;

let i: usize = get_integer_from_var_name(
vars::ids::I,
vm,
&hint_data.ids_data,
&hint_data.ap_tracking,
)?
.try_into()
.unwrap();

let devisor = get_integer_from_var_name(
vars::ids::DEVISOR,
vm,
&hint_data.ids_data,
&hint_data.ap_tracking,
)?;

let (q, r) = vm
.get_integer((value + i)?)?
.div_rem(&NonZeroFelt::try_from(devisor).unwrap());

insert_value_from_var_name(
vars::ids::Q,
MaybeRelocatable::Int(q),
vm,
&hint_data.ids_data,
&hint_data.ap_tracking,
)?;

insert_value_from_var_name(
vars::ids::R,
MaybeRelocatable::Int(r),
vm,
&hint_data.ids_data,
&hint_data.ap_tracking,
)
}
50 changes: 0 additions & 50 deletions cairo_vm_hints/src/hints/lib/rlp/divmod_rlp.rs

This file was deleted.

50 changes: 0 additions & 50 deletions cairo_vm_hints/src/hints/lib/rlp/divmod_value.rs

This file was deleted.

50 changes: 0 additions & 50 deletions cairo_vm_hints/src/hints/lib/rlp/is_long.rs

This file was deleted.

Loading

0 comments on commit 17adde9

Please sign in to comment.