From e1e39607415cbf08d5787ef4b6a4fc759049b464 Mon Sep 17 00:00:00 2001 From: Diego Civini Date: Thu, 18 Sep 2025 14:44:22 -0300 Subject: [PATCH 1/3] Update README of hint processor section --- .../builtin_hint_processor/README.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/hint_processor/builtin_hint_processor/README.md b/docs/hint_processor/builtin_hint_processor/README.md index 4bd3fff48b..6506a98784 100644 --- a/docs/hint_processor/builtin_hint_processor/README.md +++ b/docs/hint_processor/builtin_hint_processor/README.md @@ -82,7 +82,7 @@ cairo_run( .expect("Couldn't run program"); ``` #### Final notes: -The example used in this guide can be found [here](../../../custom_hint_example/). +The example used in this guide can be found [here](../../../examples/custom_hint/). The example can be ran using `make example` ### How to code your hint implementation: @@ -99,11 +99,14 @@ In order to code your custom hints you need to take into account the accessible These last two structures are used by helper functions to manage variables from the Cairo scope, and can be overlooked when coding your custom hint implementations. Just note that will have to be passed as arguments to some helper functions. ### Helper functions -There are many helper functions available [here](../../../src/hint_processor/builtin_hint_processor/hint_utils.rs), that will allow you to easily manage cairo variables: +There are many helper functions available [here](../../../vm/src/hint_processor/builtin_hint_processor/hint_utils.rs), that will allow you to easily manage cairo variables: * **get_integer_from_var_name**: gets the value from memory of a integer variable. * **get_ptr_from_var_name**: gets the value from memory of a pointer variable. -* **compute_addr_from_var_name**: gets the address of a given variable. +* **get_address_from_var_name**: gets the address of a given variable as a MaybeRelocatable. +* **get_relocatable_from_var_name**: gets the address of a given variable as a Relocatable. +* **get_maybe_relocatable_from_var_name**: gets the value from memorya of a variable as a MaybeRelocatable. +* **get_constant_from_var_name**: gets the value of a constant. * **insert_value_from_var_name**: assigns a value to a Cairo variable. * **insert_value_into_ap**: inserts a value to the memory cell pointed to by the ap register. @@ -113,13 +116,13 @@ Note: When handling pointer type variables, computing the address and using it t Note: Cairo's memory is write-once, read-only, so when using `insert_value_from_var_name` its important to first make sure that the variable doesnt contain any value (for example, it may be defined as local but never written) to avoid inconsistent memory errors. -There are also some helpers that dont depend on the hint processor used that can also be used to simplify coding hints [here](../../../src/hint_processor/hint_processor_utils.rs): +There are also some helpers that dont depend on the hint processor used that can also be used to simplify coding hints [here](../../../vm/src/hint_processor/hint_processor_utils.rs): -* get_range_check_builtin -* bigint_to_usize -* bigint_to_u32 +* get_offset_value +* felt_to_usize +* felt_to_u32 -You can also find plenty of example implementations in the [builtin hint processor folder](../../../src/hint_processor/builtin_hint_processor). +You can also find plenty of example implementations in the [builtin hint processor folder](../../../vm/src/hint_processor/builtin_hint_processor). ### Error Handling This API uses VirtualMachineError as error return type for hint functions, while its not possible to add error types to VirtualMachineError, you can use VirtualMachineError::CustomHint which receives a string and prints an error message with the format: "Hint Error: [your message]". From 792d4f041c222c725b258b835377c72dfc7c4d72 Mon Sep 17 00:00:00 2001 From: Diego Civini Date: Wed, 24 Sep 2025 09:09:29 -0300 Subject: [PATCH 2/3] Remove private func --- docs/hint_processor/builtin_hint_processor/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/hint_processor/builtin_hint_processor/README.md b/docs/hint_processor/builtin_hint_processor/README.md index 6506a98784..caae207bcb 100644 --- a/docs/hint_processor/builtin_hint_processor/README.md +++ b/docs/hint_processor/builtin_hint_processor/README.md @@ -118,7 +118,6 @@ Note: Cairo's memory is write-once, read-only, so when using `insert_value_from_ There are also some helpers that dont depend on the hint processor used that can also be used to simplify coding hints [here](../../../vm/src/hint_processor/hint_processor_utils.rs): -* get_offset_value * felt_to_usize * felt_to_u32 From 5b36acc71486e0bf11dd6d6f3f5ada534ab5ae56 Mon Sep 17 00:00:00 2001 From: Diego Civini Date: Mon, 29 Sep 2025 08:59:37 -0300 Subject: [PATCH 3/3] Add helper function --- docs/hint_processor/builtin_hint_processor/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/hint_processor/builtin_hint_processor/README.md b/docs/hint_processor/builtin_hint_processor/README.md index caae207bcb..93c47865e3 100644 --- a/docs/hint_processor/builtin_hint_processor/README.md +++ b/docs/hint_processor/builtin_hint_processor/README.md @@ -107,7 +107,8 @@ There are many helper functions available [here](../../../vm/src/hint_processor/ * **get_relocatable_from_var_name**: gets the address of a given variable as a Relocatable. * **get_maybe_relocatable_from_var_name**: gets the value from memorya of a variable as a MaybeRelocatable. * **get_constant_from_var_name**: gets the value of a constant. -* **insert_value_from_var_name**: assigns a value to a Cairo variable. +* **get_reference_from_var_name**: gets the value of a var name as a HintReference. +* **insert_value_from_var_name**: assigns a value to a Cairo variable. * **insert_value_into_ap**: inserts a value to the memory cell pointed to by the ap register. These methods take the name of the ids variable along with vm, ids_data and ap_tracking.