From 88c082032d00dbf3e23869810a89ec59d9b5fc4a Mon Sep 17 00:00:00 2001 From: Olivier Desenfans Date: Fri, 12 Apr 2024 16:23:38 +0200 Subject: [PATCH] Feature: DATA_TO_HASH_NEW_SEGMENT hint --- src/hints/mod.rs | 3 ++- src/hints/transaction_hash.rs | 14 ++++++++++++++ src/hints/unimplemented.rs | 5 ----- src/hints/vars.rs | 1 + 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/hints/mod.rs b/src/hints/mod.rs index 71700fdc..bb74b1a5 100644 --- a/src/hints/mod.rs +++ b/src/hints/mod.rs @@ -50,7 +50,7 @@ pub type HintImpl = fn( ) -> Result<(), HintError>; #[rustfmt::skip] -static HINTS: [(&str, HintImpl); 162] = [ +static HINTS: [(&str, HintImpl); 164] = [ (BREAKPOINT, breakpoint), (INITIALIZE_CLASS_HASHES, initialize_class_hashes), (INITIALIZE_STATE_CHANGES, initialize_state_changes), @@ -214,6 +214,7 @@ static HINTS: [(&str, HintImpl); 162] = [ (syscalls::STORAGE_READ, syscalls::storage_read), (syscalls::STORAGE_WRITE, syscalls::storage_write), (transaction_hash::ADDITIONAL_DATA_NEW_SEGMENT, transaction_hash::additional_data_new_segment), + (transaction_hash::DATA_TO_HASH_NEW_SEGMENT, transaction_hash::data_to_hash_new_segment), ]; /// Hint Extensions extend the current map of hints used by the VM. diff --git a/src/hints/transaction_hash.rs b/src/hints/transaction_hash.rs index 1cecf297..dfada4b4 100644 --- a/src/hints/transaction_hash.rs +++ b/src/hints/transaction_hash.rs @@ -24,3 +24,17 @@ pub fn additional_data_new_segment( ) -> Result<(), HintError> { insert_value_from_var_name(vars::ids::ADDITIONAL_DATA, vm.add_memory_segment(), vm, ids_data, ap_tracking) } + +pub const DATA_TO_HASH_NEW_SEGMENT: &str = indoc! {r#" + ids.data_to_hash = segments.add()"# +}; + +pub fn data_to_hash_new_segment( + vm: &mut VirtualMachine, + _exec_scopes: &mut ExecutionScopes, + ids_data: &HashMap, + ap_tracking: &ApTracking, + _constants: &HashMap, +) -> Result<(), HintError> { + insert_value_from_var_name(vars::ids::DATA_TO_HASH, vm.segments.add(), vm, ids_data, ap_tracking) +} diff --git a/src/hints/unimplemented.rs b/src/hints/unimplemented.rs index 25511a7e..858a634e 100644 --- a/src/hints/unimplemented.rs +++ b/src/hints/unimplemented.rs @@ -73,11 +73,6 @@ pub const COMPUTE_VALUE_DIV_MOD: &str = indoc! {r#" value = div_mod(1, x, SECP256R1_P)"# }; -#[allow(unused)] -pub const DATA_TO_HASH_NEW_SEGMENT: &str = indoc! {r#" - ids.data_to_hash = segments.add()"# -}; - #[allow(unused)] pub const ASSERT_END_OF_BYTECODE_SEGMENTS: &str = indoc! {r#" assert next(bytecode_segments, None) is None"# diff --git a/src/hints/vars.rs b/src/hints/vars.rs index c1dbd5c4..b22bf5f8 100644 --- a/src/hints/vars.rs +++ b/src/hints/vars.rs @@ -37,6 +37,7 @@ pub mod ids { pub const CURRENT_BLOCK_NUMBER: &str = "current_block_number"; pub const CURRENT_HASH: &str = "current_hash"; pub const DA_START: &str = "da_start"; + pub const DATA_TO_HASH: &str = "data_to_hash"; pub const DEPRECATED_TX_INFO: &str = "deprecated_tx_info"; pub const DESCEND: &str = "descend"; pub const DEST_PTR: &str = "dest_ptr";