You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Integrity is a STARK proof verifier written in cairo language and deployed on Starknet.
8
10
9
11
## Table of contents
10
12
11
13
-[Prerequisites](#prerequisites)
12
14
-[Using Verifier contracts on Starknet](#using-verifier-contracts-on-starknet)
15
+
-[FactRegistry and Proxy contract](#factregistry-and-proxy-contract)
16
+
-[Calls from Starknet contracts](#calls-from-starknet-contracts)
13
17
-[Running locally](#running-locally)
14
18
-[Creating a Proof](#creating-a-proof)
15
19
-[Deployment](#deployment)
@@ -21,10 +25,6 @@ To use the verifier with contracts deployed on Starknet, you need to have [Rust]
21
25
22
26
For running locally and development, you will need [scarb](https://docs.swmansion.com/scarb/) (we recommend using [asdf](https://asdf-vm.com/) version manager).
23
27
24
-
### Getting example proofs
25
-
26
-
Because of large size of proofs, we don't store example proofs directly in this repository, but rather in [Large File Storage](https://git-lfs.com/), so you need to have it installed and then run `git lfs pull` to get all example proofs.
27
-
28
28
## Using Verifier contracts on Starknet
29
29
30
30
Integrity verifier is deployed on Starknet and can be used for verifying proofs onchain. The intended way of using the verifier is through FactRegistry contract, which besides running the verification process, also stores data for all verified proofs. (For more information see [FactRegistry and Proxy contract](#factregistry-and-proxy-contract))
@@ -44,7 +44,7 @@ After that, you can use `verify-on-starknet.sh` script to send the transaction t
This bash script internally calls `verify_proof_full_and_register_fact` function on FactRegistry contract.
@@ -53,6 +53,101 @@ This bash script internally calls `verify_proof_full_and_register_fact` function
53
53
54
54
To generate split calldata, please refer to [Calldata Generator README](https://github.com/HerodotusDev/integrity-calldata-generator/blob/main/README.md). This repository also provides script for automatic transaction sending (proof verification is split into multiple transactions, for more information see [Split Verifier Architecture](#split-verifier-architecture)).
55
55
56
+
## FactRegistry and Proxy contract
57
+
58
+
Since verifier can be configured in many ways and some parts of the logic changes with new stone versions, a contract which routes calls to the correct verifier is needed. This task is handled by FactRegistry contract that also stores data for all verified proofs.
59
+
60
+
After proof is verified, `FactRegistered` event is emitted which contains `fact_hash`, `verification_hash`, `security_bits` and `settings`. `fact_hash` is a value that represents proven program and its output (formally `fact_hash = poseidon_hash(program_hash, output_hash)`). Remember that registration of some `fact_hash` doesn't necessary mean that it has been verified by someone with secure enough proof. You always need to check `security_bits` and `settings` which is part of `verification_hash` (formally `verification_hash = poseidon_hash(fact_hash, security_bits, settings)`).
61
+
62
+
For more detailed and visual representation of those hash calculations, check out [Integrity Hashes Calculator](https://integrity-hashes-calculator.vercel.app/) tool. It generates all mentioned hashes for arbitrary user input and even proof JSON file.
63
+
64
+
`FactRegistry` provides two methods for checking verified proofs:
65
+
66
+
-`get_verification(verification_hash)` - returns fact hash, security bits and settings for given `verification_hash`.
67
+
-`get_all_verifications_for_fact_hash(fact_hash)` - returns list of all verification hashes, security bits and settings for given `fact_hash`. This method is useful for checking if given program has been verified by someone with secure enough proof.
68
+
69
+
FactRegistry contract is trustless which means that the owner of the contract can't override or change any existing behavior, they can only add new verifiers. Proxy contract on the other hand is upgradable, so every function can be changed or removed. It has the advantage of having all future updates of the verifier logic without having to replace the address of FactRegistry contract. Proxy contract provides the same interface as FactRegistry with additional `get_fact_registry` method which returns address of FactRegistry contract.
70
+
71
+
## Calls from Starknet contracts
72
+
73
+
Since integrity is deployed on Starknet, other contracts can call FactRegistry to check whether certain proof has been verified. Integrity can be used as a dependency of your cairo1 project by including it in project's `Scarb.toml`:
The package provides many utility functions for interacting with the verifier. For contract calls, you can use `Integrity` struct which provides following methods:
81
+
82
+
-`new() -> Integrity` - creates new interface for interacting with official FactRegistry (contract address is set automatically).
83
+
-`new_proxy() -> Integrity` - creates new interface using official Proxy contract (contract address is set automatically).
84
+
-`from_address(address: ContractAddress) -> Integrity` - create new interface using custom FactRegistry deployment.
85
+
-`is_fact_hash_valid_with_security(self: Integrity, fact_hash: felt252, security_bits: u32) -> bool` - checks if given `fact_hash` has been verified with at least `security_bits` number of security bits.
86
+
-`is_verification_hash_valid(self: Integrity, verification_hash: felt252) -> bool` - checks if given `verification_hash` has been verified.
87
+
-`with_config(self: Integrity, verifier_config: VerifierConfiguration, security_bits: u32) -> IntegrityWithConfig` - returns new interface with custom verifier configuration.
88
+
-`with_hashed_config(self: Integrity, verifier_config_hash: felt252, security_bits: u32) -> IntegrityWithConfig` - returns new interface with custom verifier configuration given its hash.
89
+
90
+
On `IntegrityWithConfig` interface you can call:
91
+
92
+
-`is_fact_hash_valid(self: IntegrityWithConfig, fact_hash: felt252) -> bool` - checks if given `fact_hash` has been verified with selected config.
93
+
94
+
There are also few utility function for calculating hashes:
95
+
96
+
-`get_verifier_config_hash(verifier_config: VerifierConfiguration) -> felt252` - calculates hash for given verifier configuration, which is used necessary for calculating verification hash.
97
+
-`get_verification_hash(fact_hash: felt252, verifier_config_hash: felt252, security_bits: u32) -> felt252` - calculates verification hash for given `fact_hash`, `verifier_config_hash` and `security_bits`.
98
+
-`calculate_fact_hash(program_hash: felt256, output: Span<felt252>) -> felt252` - calculates fact hash for given `program_hash` and `output` array.
99
+
-`calculate_bootloaded_fact_hash(bootloader_program_hash: felt252, child_program_hash: felt252, child_output: Span<felt252>) -> felt252` - calculates fact hash for program that was bootloaded with standard bootloader.
100
+
101
+
Available constants are:
102
+
103
+
-`INTEGRITY_ADDRESS` - address of official FactRegistry contract deployed on Starknet Sepolia
104
+
-`PROXY_ADDRESS` - address of official Proxy contract deployed on Starknet Sepolia
105
+
-`SHARP_BOOTLOADER_PROGRAM_HASH` - program hash of the bootloader used by SHARP prover
106
+
-`STONE_BOOTLOADER_PROGRAM_HASH` - program hash of [TODO LINK]
107
+
108
+
Example:
109
+
110
+
```
111
+
use integrity::{Integrity, IntegrityWithConfig, calculate_bootloaded_fact_hash, SHARP_BOOTLOADER_PROGRAM_HASH, VerifierConfiguration};
Because of great complexity of the verifier compared to standard starknet contracts, we encounter some limitations enforced by starknet. The most important ones are:
160
273
161
274
- Contract classhash size limit
162
275
- Transaction calldata limit
163
276
- Transaction steps limit
164
277
165
278
To overcome these limitations, we split the verifier into multiple contracts and transactions. The biggest part of classhash size is autogenerated (e.g. [recursive autogenerated](/src/air/layouts/recursive/autogenerated.cairo)), so we extracted that part into separate contract (or many contracts in case of `starknet_with_keccak` layout), which is called automatically by the main verifier contract. On the other hand the biggest part of calldata is fri witness, so user can send subsequent chunks of fri witness in separate step transactions.
166
-
167
-
### FactRegistry and Proxy contract
168
-
169
-
Since verifier can be configured in many ways and some parts of the logic changes with new stone versions, a contract which routes calls to the correct verifier is needed. This task is handled by FactRegistry contract that also stores data for all verified proofs.
170
-
171
-
After proof is verified, `FactRegistered` event is emitted which contains `fact_hash`, `verification_hash`, `security_bits` and `settings`. `fact_hash` is a value that represents proven program and its output (formally `fact_hash = poseidon_hash(program_hash, output_hash)`). Remember that registration of some `fact_hash` doesn't necessary mean that it has been verified by someone with secure enough proof. You always need to check `security_bits` and `settings` which is part of `verification_hash` (formally `verification_hash = poseidon_hash(fact_hash, security_bits, settings)`).
172
-
173
-
`FactRegistry` provides two methods for checking verified proofs:
174
-
175
-
-`get_verification(verification_hash)` - returns fact hash, security bits and settings for given `verification_hash`.
176
-
-`get_all_verifications_for_fact_hash(fact_hash)` - returns list of all verification hashes, security bits and settings for given `fact_hash`. This method is useful for checking if given program has been verified by someone with secure enough proof.
177
-
178
-
FactRegistry contract is trustless which means that the owner of the contract can't override or change any existing behavior, they can only add new verifiers. Proxy contract on the other hand is upgradable, so every function can be changed or removed. It has the advantage of having all future updates of the verifier logic without having to replace the address of FactRegistry contract.
0 commit comments