-
Notifications
You must be signed in to change notification settings - Fork 11
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
how to compute my program hash? #58
Comments
Okay, I get it now: "execution": {
"begin_addr": 541,
"stop_ptr": 731
}, So 1 -> 541-2 (= 538, exclusive). I guess I need someone to explain to me what is |
If you don't mind I will factorize the logic to compute program hash and expose it as some utils method. |
The only relevant implementation in the ecosystem of pub mem validation for cairo0 python-vm |
Yeah the program is held between program start_ptr and execution start_ptr ( - 2 cells due to function stack of cairo cpu ) |
Yup I got this explanation from @LandauRaz |
After asking internally, it seems that there is no lib nor tool in the ecosystem that allows to compute a program hash. |
Can u tell more about |
3 actors: Bob, Alice and Charlie. In this design, Bob should be able to generate the program hash without knowing Alice's private inputs. So in this design, the input for the It would be better if Bob was able to compute the program hash without having to run it successfully, but as for now, it looks like it cannot get the full "proof mode" program hash, without executing it to the end. Edit: actually he doesn't need valid inputs, as long as his program doesn't panic and just returns an error (Sierra's provable failure). Afaik the program hash will be the same, regardless of the execution outcome. |
@Okm165 I think your implementation of the program hash computation is buggy. Here is the content of my public-input.json: {
...
"memory_segments": {
...
"program": {
"begin_addr": 1,
"stop_ptr": 56
},
...
"execution": {
"begin_addr": 541,
"stop_ptr": 731
},
...
},
"public_memory": [
{
"address": 1,
"value": "0x40780017fff7fff",
"page": 0
},
{
"address": 2,
"value": "0x3",
"page": 0
},
... contiguous memories cell
{
"address": 534,
"value": "0x208b7fff7fff7ffe",
"page": 0
},
{
"address": 535,
"value": "0x208b7fff7fff7ffe",
"page": 0
},
{
"address": 731,
"value": "0x0",
"page": 0
},
{
"address": 732,
"value": "0x1",
"page": 0
},
{
"address": 733,
"value": "0xbabecafe",
"page": 0
},
...
],
...
} The start of the program is at address 1, and we take With the current state of the program, those 3 values are included in the computation of the program hash. But the output could be input dependent. So not at all part of the program. Coz with two different private inputs you could end up with two different program hash. For the same program. Therefore the bug. I have no idea what is supposed to between |
That is correct this is a bug for sure to be fixed |
After much internal discussion, it seems that changing the logic to use from There is also some ongoing discussion about the use or not of the bootloader. |
Another issue is most likely there:
the |
Stark proof verification is valid for both cairo0 and cairo1 no matter bootloading. The issue here is cairo1-run introduces slightly different shape of memory, so these checks characteristic for cairo0 memory are not applicable, so anything that comes straight from cairo1-run is gonna cause issue in this checks after stark proof validation. |
The way you compute the program hash only takes into account the "program" segment. I can use the same "program" in two different ways if I use a different entry point, so, in order to be truly unique, the program hash should take the main_entrypoint into account |
In the case of Cairo1 contract bootloader the entrypoint is hardcoded to be a |
Yep, it works when using the bootloader. But, afaik, I am not required to use the bootloader. I could be fine with swiftness only supporting bootloaders-executed programs, but you have to specify it in the doc, and return an error if I'm not complying. |
Preparing update in docs that will mention how to prove Cairo1 with https://github.com/zksecurity/stone-cli and verify it |
swiftness
verify
returns the program's hash.Looking at the implementation:
It looks like it is building the based on the
program
segment present in the public inputs.When debugging,
program.len()
was set to538
.When I look to my
public-input.json
generated bycairo1-run
I find:So this doesn't match.
What part of the files generated during the proving of my program should I use to compute my program hash and check that it does match the one outputted by the verifier?
The text was updated successfully, but these errors were encountered: