Skip to content

Commit

Permalink
Merge pull request #28 from zksecurity/add-program-input-hint
Browse files Browse the repository at this point in the history
Add hint implementation for Cairo 0 programs
  • Loading branch information
mellowcroc authored Feb 4, 2025
2 parents 92d2dda + a6bb079 commit cc3738d
Show file tree
Hide file tree
Showing 11 changed files with 3,404 additions and 25 deletions.
14 changes: 2 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Additional args for prover parameters. Most of them are related to optimizations
- `--use_extension_field`
- `--verifier_friendly_channel_updates`
- `--verifier_friendly_commitment_hash`
- `--bench_memory`: requires `heaptrack` to be installed

Additional args for prover config:

Expand All @@ -89,6 +90,7 @@ Additional args:
- `--prover_config_file`
- `--parameter_file`
- `--ignore_fact_topologies`
- `--bench_memory`: requires `heaptrack` to be installed

### Verify

Expand Down Expand Up @@ -151,10 +153,6 @@ Here are the specific steps for the above process:
- Only the `starknet` layout is supported for bootloader proofs
- Programs should use the `output` builtin--programs that do not can be proved, but won't verify on Ethereum

## Testing

Before running the tests, make sure to increase the Rust default stack size via `export RUST_MIN_STACK=4194304`. After that, you can run `cargo test` to run all the tests.

## Versioning guide

- Minor version changes should be made when the underlying `cairo1-run` binary built from [cairo-vm](https://github.com/lambdaclass/cairo-vm) is updated.
Expand Down Expand Up @@ -182,11 +180,3 @@ Error: Failed to run cairo1: cairo1-run failed with error: Error: VirtualMachine
```

This error occurs when the program uses a builtin that is not supported by the layout. Refer to the [List of supported builtins per layout](#list-of-supported-builtins-per-layout) to find the right layout for theprogram.

```bash
thread 'opt cgu.00' has overflowed its stack
fatal runtime error: stack overflow
error: could not compile `swiftness_air` (lib)
```

This error occurs when trying to run `cargo test`. This can be solved by increasing the Rust default stack size via `export RUST_MIN_STACK=4194304`.
39 changes: 39 additions & 0 deletions examples/cairo0/with_hint/fibonacci.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2023 StarkWare Industries Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License").
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.starkware.co/open-source-license/
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions
// and limitations under the License.

%builtins output
func main(output_ptr: felt*) -> (output_ptr: felt*) {
alloc_locals;
// Load fibonacci_claim_index and copy it to the output segment.
local fibonacci_claim_index;
%{ ids.fibonacci_claim_index = program_input['fibonacci_claim_index'] %}

assert output_ptr[0] = fibonacci_claim_index;
let res = fib(1, 1, fibonacci_claim_index);
assert output_ptr[1] = res;

// Return the updated output_ptr.
return (output_ptr=&output_ptr[2]);
}

func fib(first_element: felt, second_element: felt, n: felt) -> felt {
if (n == 0) {
return second_element;
}

return fib(
first_element=second_element, second_element=first_element + second_element, n=n - 1
);
}
Loading

0 comments on commit cc3738d

Please sign in to comment.