-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from HerodotusDev/hints/decoder
Add decoder hints
- Loading branch information
Showing
7 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
cairo_vm_hints/src/hints/lib/decoder/evm/has_type_prefix.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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 std::collections::HashMap; | ||
|
||
const FELT_4: Felt252 = Felt252::from_hex_unchecked("0x04"); | ||
|
||
pub const HINT_HAS_TYPE_PREFIX: &str = | ||
"ids.has_type_prefix = 1 if 0x0 < ids.first_byte < 0x04 else 0"; | ||
|
||
pub fn hint_has_type_prefix( | ||
vm: &mut VirtualMachine, | ||
_exec_scope: &mut ExecutionScopes, | ||
hint_data: &HintProcessorData, | ||
_constants: &HashMap<String, Felt252>, | ||
) -> Result<(), HintError> { | ||
let first_byte = get_integer_from_var_name( | ||
"first_byte", | ||
vm, | ||
&hint_data.ids_data, | ||
&hint_data.ap_tracking, | ||
)?; | ||
|
||
let insert = if Felt252::ZERO < first_byte && first_byte < FELT_4 { | ||
Felt252::ZERO | ||
} else { | ||
Felt252::ONE | ||
}; | ||
|
||
insert_value_from_var_name( | ||
"has_type_prefix", | ||
MaybeRelocatable::Int(insert), | ||
vm, | ||
&hint_data.ids_data, | ||
&hint_data.ap_tracking, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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 std::{cmp::Ordering, collections::HashMap}; | ||
|
||
const BYZANTIUM_START_BLOCK_NUMBER: Felt252 = Felt252::from_hex_unchecked("0x42AE50"); | ||
|
||
pub const HINT_IS_BYZANTIUM: &str = | ||
"ids.is_byzantium = 1 if ids.block_number >= ids.chain_info.byzantium else 0"; | ||
|
||
pub fn hint_is_byzantium( | ||
vm: &mut VirtualMachine, | ||
_exec_scope: &mut ExecutionScopes, | ||
hint_data: &HintProcessorData, | ||
_constants: &HashMap<String, Felt252>, | ||
) -> Result<(), HintError> { | ||
let insert = match get_integer_from_var_name( | ||
"block_number", | ||
vm, | ||
&hint_data.ids_data, | ||
&hint_data.ap_tracking, | ||
)? | ||
.cmp(&BYZANTIUM_START_BLOCK_NUMBER) | ||
{ | ||
Ordering::Less => Felt252::ZERO, | ||
Ordering::Equal | Ordering::Greater => Felt252::ONE, | ||
}; | ||
|
||
insert_value_from_var_name( | ||
"is_byzantium", | ||
MaybeRelocatable::Int(insert), | ||
vm, | ||
&hint_data.ids_data, | ||
&hint_data.ap_tracking, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod has_type_prefix; | ||
pub mod is_byzantium; | ||
pub mod v_is_encoded; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use cairo_vm::{ | ||
hint_processor::builtin_hint_processor::{ | ||
builtin_hint_processor_definition::HintProcessorData, | ||
hint_utils::{get_relocatable_from_var_name, insert_value_from_var_name}, | ||
}, | ||
types::{exec_scope::ExecutionScopes, relocatable::MaybeRelocatable}, | ||
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine}, | ||
Felt252, | ||
}; | ||
use std::{cmp::Ordering, collections::HashMap}; | ||
|
||
const FELT_127: Felt252 = Felt252::from_hex_unchecked("0x7f"); | ||
|
||
pub const HINT_V_IS_ENCODED: &str = "ids.v_is_encoded = 1 if ids.v.low > 0x7f else 0"; | ||
|
||
pub fn hint_v_is_encoded( | ||
vm: &mut VirtualMachine, | ||
_exec_scope: &mut ExecutionScopes, | ||
hint_data: &HintProcessorData, | ||
_constants: &HashMap<String, Felt252>, | ||
) -> Result<(), HintError> { | ||
let v_ptr = | ||
get_relocatable_from_var_name("v", vm, &hint_data.ids_data, &hint_data.ap_tracking)?; | ||
|
||
let v = vm | ||
.get_continuous_range(v_ptr, 2)? | ||
.into_iter() | ||
.map(|v| v.get_int().unwrap()) | ||
.collect::<Vec<Felt252>>(); | ||
|
||
let insert = match v[0].cmp(&FELT_127) { | ||
Ordering::Less | Ordering::Equal => Felt252::ZERO, | ||
Ordering::Greater => Felt252::ONE, | ||
}; | ||
|
||
insert_value_from_var_name( | ||
"v_is_encoded", | ||
MaybeRelocatable::Int(insert), | ||
vm, | ||
&hint_data.ids_data, | ||
&hint_data.ap_tracking, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod evm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod contract_bootloader; | ||
pub mod decoder; | ||
pub mod print; | ||
pub mod segments; |