Skip to content
Open
Show file tree
Hide file tree
Changes from all 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,325 changes: 878 additions & 447 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ resolver = "2"

members = ["cairo_vm_hints"]


[workspace.dependencies]
bincode = { version = "2.0.1", default-features = false, features = ["serde"]}
cairo-vm = { git = "https://github.com/lambdaclass/cairo-vm", tag = "v2.0.1", features = ["extensive_hints", "clap", "cairo-1-hints", "mod_builtin"] }
clap = { version = "4.3.10", features = ["derive"] }
hex = "0.4.3"
num-bigint = "0.4.6"
num-traits = "0.2.19"
cairo-vm = { git = "https://github.com/lambdaclass/cairo-vm", rev = "b1a91f929b5fa29a1a2e9e6990a68a1220c0c673", features = ["extensive_hints", "clap", "cairo-1-hints", "mod_builtin"] }
clap = { version = "4.5", features = ["derive"] }
hex = "0.4"
num-bigint = { version = "0.4", features = ["rand"] }
num-traits = "0.2"
rand = "0.8"
sha3 = "0.10.8"
starknet-crypto = "0.7.2"
sha3 = "0.10"
starknet-crypto = "0.7.4"
starknet-types-core = "0.1.7"
thiserror = "1.0.64"
thiserror = "2.0"
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
23 changes: 13 additions & 10 deletions cairo_vm_hints/src/hint_processor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use crate::hints;
use std::{any::Any, collections::HashMap, rc::Rc};

use cairo_vm::{
hint_processor::{
builtin_hint_processor::builtin_hint_processor_definition::{BuiltinHintProcessor, HintFunc, HintProcessorData},
hint_processor_definition::HintExtension,
hint_processor_definition::HintProcessorLogic,
hint_processor_definition::{HintExtension, HintProcessorLogic},
},
types::exec_scope::ExecutionScopes,
vm::{errors::hint_errors::HintError, runners::cairo_runner::ResourceTracker, vm_core::VirtualMachine},
Felt252,
};
use starknet_types_core::felt::Felt;
use std::collections::HashMap;
use std::{any::Any, rc::Rc};

use crate::hints;

#[derive(Default)]
pub struct CustomHintProcessor;
Expand Down Expand Up @@ -68,7 +67,7 @@ impl HintProcessorLogic for ExtendedHintProcessor {
_vm: &mut VirtualMachine,
_exec_scopes: &mut ExecutionScopes,
_hint_data: &Box<dyn Any>,
_constants: &HashMap<String, Felt>,
_constants: &HashMap<String, Felt252>,
) -> Result<(), HintError> {
unreachable!();
}
Expand All @@ -78,16 +77,20 @@ impl HintProcessorLogic for ExtendedHintProcessor {
vm: &mut VirtualMachine,
exec_scopes: &mut ExecutionScopes,
hint_data: &Box<dyn Any>,
constants: &HashMap<String, Felt>,
constants: &HashMap<String, Felt252>,
) -> Result<HintExtension, HintError> {
match self.custom_hint_processor.execute_hint_extensive(vm, exec_scopes, hint_data, constants) {
match self
.custom_hint_processor
.execute_hint_extensive(vm, exec_scopes, hint_data, constants)
{
Err(HintError::UnknownHint(_)) => {}
result => {
return result;
}
}

self.builtin_hint_processor.execute_hint_extensive(vm, exec_scopes, hint_data, constants)
self.builtin_hint_processor
.execute_hint_extensive(vm, exec_scopes, hint_data, constants)
}
}

Expand Down
16 changes: 10 additions & 6 deletions cairo_vm_hints/src/hints/lib/bit_length.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::HintProcessorData;
use cairo_vm::hint_processor::builtin_hint_processor::hint_utils::{get_integer_from_var_name, insert_value_from_var_name};
use cairo_vm::types::exec_scope::ExecutionScopes;
use cairo_vm::types::relocatable::MaybeRelocatable;
use cairo_vm::vm::{errors::hint_errors::HintError, vm_core::VirtualMachine};
use cairo_vm::Felt252;
use std::collections::HashMap;

use cairo_vm::{
hint_processor::builtin_hint_processor::{
builtin_hint_processor_definition::HintProcessorData,
hint_utils::{get_integer_from_var_name, insert_value_from_var_name},
},
types::{exec_scope::ExecutionScopes, relocatable::MaybeRelocatable},
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
Felt252,
};

pub const HINT_BIT_LENGTH: &str = "ids.bit_length = ids.x.bit_length()";

pub fn hint_bit_length(
Expand Down
19 changes: 11 additions & 8 deletions cairo_vm_hints/src/hints/lib/block_header/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::HintProcessorData;
use cairo_vm::hint_processor::builtin_hint_processor::hint_utils::{get_integer_from_var_name, insert_value_into_ap};
use cairo_vm::types::exec_scope::ExecutionScopes;
use cairo_vm::types::relocatable::MaybeRelocatable;
use cairo_vm::vm::{errors::hint_errors::HintError, vm_core::VirtualMachine};
use cairo_vm::Felt252;
use std::cmp::Ordering;
use std::collections::HashMap;
use std::{cmp::Ordering, collections::HashMap};

use cairo_vm::{
hint_processor::builtin_hint_processor::{
builtin_hint_processor_definition::HintProcessorData,
hint_utils::{get_integer_from_var_name, insert_value_into_ap},
},
types::{exec_scope::ExecutionScopes, relocatable::MaybeRelocatable},
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
Felt252,
};

const HINT_RLP_BIGINT_SIZE: &str = "memory[ap] = 1 if ids.byte <= 127 else 0";

Expand Down
16 changes: 10 additions & 6 deletions cairo_vm_hints/src/hints/lib/mmr/bit_length.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::HintProcessorData;
use cairo_vm::hint_processor::builtin_hint_processor::hint_utils::{get_integer_from_var_name, insert_value_from_var_name};
use cairo_vm::types::exec_scope::ExecutionScopes;
use cairo_vm::types::relocatable::MaybeRelocatable;
use cairo_vm::vm::{errors::hint_errors::HintError, vm_core::VirtualMachine};
use cairo_vm::Felt252;
use std::collections::HashMap;

use cairo_vm::{
hint_processor::builtin_hint_processor::{
builtin_hint_processor_definition::HintProcessorData,
hint_utils::{get_integer_from_var_name, insert_value_from_var_name},
},
types::{exec_scope::ExecutionScopes, relocatable::MaybeRelocatable},
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
Felt252,
};

pub const MMR_BIT_LENGTH: &str = "ids.bit_length = ids.mmr_len.bit_length()";

pub fn mmr_bit_length(
Expand Down
26 changes: 18 additions & 8 deletions cairo_vm_hints/src/hints/lib/mmr/left_child.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::HintProcessorData;
use cairo_vm::hint_processor::builtin_hint_processor::hint_utils::{get_integer_from_var_name, insert_value_from_var_name};
use cairo_vm::types::exec_scope::ExecutionScopes;
use cairo_vm::types::relocatable::MaybeRelocatable;
use cairo_vm::vm::{errors::hint_errors::HintError, vm_core::VirtualMachine};
use cairo_vm::Felt252;
use starknet_types_core::felt::Felt;
use std::collections::HashMap;

use cairo_vm::{
hint_processor::builtin_hint_processor::{
builtin_hint_processor_definition::HintProcessorData,
hint_utils::{get_integer_from_var_name, insert_value_from_var_name},
},
types::{exec_scope::ExecutionScopes, relocatable::MaybeRelocatable},
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
Felt252,
};
use starknet_types_core::felt::Felt;

pub const MMR_LEFT_CHILD: &str = "ids.in_mmr = 1 if ids.left_child <= ids.mmr_len else 0";

pub fn mmr_left_child(
Expand All @@ -19,7 +23,13 @@ pub fn mmr_left_child(
let mmr_len = get_integer_from_var_name("mmr_len", vm, &hint_data.ids_data, &hint_data.ap_tracking)?;

let in_mmr = if left_child <= mmr_len { Felt::ONE } else { Felt::ZERO };
insert_value_from_var_name("in_mmr", MaybeRelocatable::Int(in_mmr), vm, &hint_data.ids_data, &hint_data.ap_tracking)?;
insert_value_from_var_name(
"in_mmr",
MaybeRelocatable::Int(in_mmr),
vm,
&hint_data.ids_data,
&hint_data.ap_tracking,
)?;

Ok(())
}
3 changes: 2 additions & 1 deletion cairo_vm_hints/src/hints/lib/mmr/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::collections::HashMap;

use cairo_vm::{
hint_processor::builtin_hint_processor::builtin_hint_processor_definition::HintProcessorData,
types::exec_scope::ExecutionScopes,
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
Felt252,
};
use std::collections::HashMap;

pub mod bit_length;
pub mod left_child;
Expand Down
18 changes: 11 additions & 7 deletions cairo_vm_hints/src/hints/lib/mmr/peak_values.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::HintProcessorData;
use cairo_vm::hint_processor::builtin_hint_processor::hint_utils::{get_integer_from_var_name, insert_value_from_var_name};
use cairo_vm::types::exec_scope::ExecutionScopes;
use cairo_vm::types::relocatable::MaybeRelocatable;
use cairo_vm::vm::{errors::hint_errors::HintError, vm_core::VirtualMachine};
use cairo_vm::Felt252;
use starknet_types_core::felt::Felt;
use std::collections::HashMap;

use cairo_vm::{
hint_processor::builtin_hint_processor::{
builtin_hint_processor_definition::HintProcessorData,
hint_utils::{get_integer_from_var_name, insert_value_from_var_name},
},
types::{exec_scope::ExecutionScopes, relocatable::MaybeRelocatable},
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
Felt252,
};
use starknet_types_core::felt::Felt;

pub const HINT_IS_POSITION_IN_MMR_ARRAY: &str = "ids.is_position_in_mmr_array= 1 if ids.position > ids.mmr_offset else 0";

pub fn hint_is_position_in_mmr_array(
Expand Down
3 changes: 2 additions & 1 deletion cairo_vm_hints/src/hints/lib/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::collections::HashMap;

use cairo_vm::{
hint_processor::builtin_hint_processor::builtin_hint_processor_definition::HintProcessorData,
types::exec_scope::ExecutionScopes,
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
Felt252,
};
use std::collections::HashMap;

pub mod bit_length;
pub mod block_header;
Expand Down
22 changes: 15 additions & 7 deletions cairo_vm_hints/src/hints/lib/mpt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ fn is_long_list(value: Felt252) -> bool {
FELT_248 <= value && value <= FELT_255
}

use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::HintProcessorData;
use cairo_vm::hint_processor::builtin_hint_processor::hint_utils::{get_integer_from_var_name, insert_value_from_var_name};
use cairo_vm::types::exec_scope::ExecutionScopes;
use cairo_vm::types::relocatable::MaybeRelocatable;
use cairo_vm::vm::{errors::hint_errors::HintError, vm_core::VirtualMachine};
use cairo_vm::Felt252;
use std::collections::HashMap;

use cairo_vm::{
hint_processor::builtin_hint_processor::{
builtin_hint_processor_definition::HintProcessorData,
hint_utils::{get_integer_from_var_name, insert_value_from_var_name},
},
types::{exec_scope::ExecutionScopes, relocatable::MaybeRelocatable},
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
Felt252,
};

pub const HINT_LONG_SHORT_LIST: &str = "from tools.py.hints import is_short_list, is_long_list\nif is_short_list(ids.list_prefix):\n ids.long_short_list = 0\nelif is_long_list(ids.list_prefix):\n ids.long_short_list = 1\nelse:\n raise ValueError(f\"Invalid list prefix: {hex(ids.list_prefix)}. Not a recognized list type.\")";

pub fn hint_long_short_list(
Expand Down Expand Up @@ -100,7 +104,11 @@ pub fn hint_first_item_type(
&hint_data.ids_data,
&hint_data.ap_tracking,
),
value => Err(HintError::InvalidValue(Box::new(("Unsupported first item prefix", value, Felt252::ZERO)))),
value => Err(HintError::InvalidValue(Box::new((
"Unsupported first item prefix",
value,
Felt252::ZERO,
)))),
}
}

Expand Down
18 changes: 11 additions & 7 deletions cairo_vm_hints/src/hints/lib/rlp_little/assert.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use crate::utils;
use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::HintProcessorData;
use cairo_vm::types::exec_scope::ExecutionScopes;
use cairo_vm::types::relocatable::MaybeRelocatable;
use cairo_vm::vm::{errors::hint_errors::HintError, vm_core::VirtualMachine};
use cairo_vm::Felt252;
use std::collections::HashMap;

pub const HINT_EXPECTED_LEADING_ZEROES: &str = "assert ids.res == expected_leading_zeroes, f\"Expected {expected_leading_zeroes} but got {ids.res}\"";
use cairo_vm::{
hint_processor::builtin_hint_processor::builtin_hint_processor_definition::HintProcessorData,
types::{exec_scope::ExecutionScopes, relocatable::MaybeRelocatable},
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
Felt252,
};

use crate::utils;

pub const HINT_EXPECTED_LEADING_ZEROES: &str =
"assert ids.res == expected_leading_zeroes, f\"Expected {expected_leading_zeroes} but got {ids.res}\"";

pub fn hint_expected_leading_zeroes(
vm: &mut VirtualMachine,
Expand Down
18 changes: 11 additions & 7 deletions cairo_vm_hints/src/hints/lib/rlp_little/divmod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::HintProcessorData;
use cairo_vm::hint_processor::builtin_hint_processor::hint_utils::{get_integer_from_var_name, get_ptr_from_var_name, insert_value_from_var_name};
use cairo_vm::types::exec_scope::ExecutionScopes;
use cairo_vm::types::relocatable::MaybeRelocatable;
use cairo_vm::vm::{errors::hint_errors::HintError, vm_core::VirtualMachine};
use cairo_vm::Felt252;
use starknet_types_core::felt::NonZeroFelt;
use std::collections::HashMap;

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::{exec_scope::ExecutionScopes, relocatable::MaybeRelocatable},
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
Felt252,
};
use starknet_types_core::felt::NonZeroFelt;

pub const HINT_POW_CUT: &str = "ids.q, ids.r = divmod(memory[ids.array + ids.start_word + ids.i], ids.pow_cut)";

pub fn hint_pow_cut(
Expand Down
Loading
Loading