-
Notifications
You must be signed in to change notification settings - Fork 51
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
Docs: hints docs #409
Docs: hints docs #409
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, refrain from submitting anymore commits until you've studied the topic. Writing documentation is sometimes even more difficult than writing code because it requires an understanding of the subject.
We don't expect to have the best piece of written content, nobody here is a writer. We DO expect for that content to be correct, at the very least.
If your approach is to write things and get them fact checked by us, so you can fix them and then repeat the until completion, then that is not a very good approach. You are wasting the reviewers time and yours because you're not learning anything. I am seeing it here as well as in the recently closed #378
I don't know if this is intentional or not, if you keep this quality of work, we won't be interested in anymore contributions from you. If you're here to learn then please go read the Docs and come here when you feel ready. Otherwise, let's just close this PR now as unsolved.
### WHY HINTS RUN ON SEQUENCERS/ PROVERS AND NOT VERIFIERS | ||
|
||
Sequencers are the leads that produces blocks by executing transaction and updating the blockchain state. | ||
During the proof generation process, the prover uses hints to generate additional constraints or assumptions about the program's behavior, which makes part of the proof sent to the verifier for verification. In the Cairo Virtual Machine, hints are sorted out during different stages of the compilation and execution process by the sequencer. However, they are not directly involved in the verification stage. Hints are primarily for performance optimization. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
During proof generating, hints are not used at all. Hints are only used when generating the execution trace. This execution trace is then proven by the Prover but at this stage it doesn't care about hints. Again, please don't use information you're not certain of.
Let's remove this sentence.
|
||
Example: | ||
Let's consider a Cairo function that calculates the factorial of a given input *`n`*: | ||
|
||
```Cairo | ||
@public | ||
func factorial(n : felt) -> (result : felt): | ||
if n <= 1: | ||
result := 1 | ||
else: | ||
result := n * factorial(n - 1) | ||
``` | ||
|
||
In this code, the hint *@public* indicates that the *`n`* factorial should be publicly available in the Cairo program. | ||
The provers/sequencers will utilize the hint to generate a proof or sequence of instructions for the function to ensure maximum optimization. The verifier will check that the generated proof or sequence of instructions has correctly calculated the factorial of the input *`n`* or any other specification is satisfied. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very False. Please, I am hesitant to continue reviewing the PR if you are really not invested in it. Knowing this is false just requires reading the Cairo Docs. Also, writing this simple Cairo Program you'll notice this is untrue.
This kind of content seems AI hallucination, the least you could do is double check if what is being generated is true. Wasting the reviewers time is not a good practice.
``` cairo | ||
from starkware.cairo.common.hints import Hint | ||
|
||
class FactorialHint(Hint): | ||
def __init__(self, n): | ||
self.n = n | ||
|
||
def process(self, cairo_ctx): | ||
result = 1 | ||
for i in range(2, self.n + 1): | ||
result *= i | ||
return [result] | ||
|
||
//Usage | ||
[ap] = 5, ap++; | ||
%{ | ||
hint_processor = FactorialHint(memory[ap - 1]) | ||
memory[ap] = cairo_runner.run_from_entrypoint( | ||
entrypoint, | ||
[2, (2,0)], | ||
False, | ||
vm, | ||
hint_processor | ||
)[0]; | ||
%} | ||
[ap - 1] = [ap] * [ap], ap++; | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this Cairo? Don't you see it's different from the other examples?
## IMPLEMENTING HINTS IN CAIRO VIRTUAL MACHINE | ||
|
||
In Cairo Virtual Machine, hints are accepted and recognized by its code. | ||
Hints are implemented using the *%{...%}* syntax, which allows you to insert Python code that is only executed by the prover. When implementing hints, the *'variable naming convention'* should be considered. The method to handle specific hints should be outlined like this; *'create hintName Hinter'*. Hints should be grouped by functionality in Cairo programs. The structure returned should implement the interface. Implementing the hint means you have to write code in Go that has the same behavior as the code of the hint in Python. Unit tests are added to check if the behavior of your code is correct. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence is not true. Let's delete it.
Talked a bit more with @Iwueseiter on Telegram. We decided to close the PR for now. |
Implemented Hints Documentation.