-
Notifications
You must be signed in to change notification settings - Fork 198
Update README of hint processor section #2202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DiegoCivi
wants to merge
4
commits into
main
Choose a base branch
from
update-hint-docu
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -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]". | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.