From 6414a956b28a15fb9c46e144a3f640396472a4d7 Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Tue, 10 Sep 2024 12:11:05 +0200 Subject: [PATCH 1/2] refactor --- src/air/air.cairo | 4 +- src/air/layouts/dex.cairo | 74 +++++++------ src/air/layouts/dex/contract.cairo | 30 +++--- src/air/layouts/dex/public_input.cairo | 2 +- src/air/layouts/generator.py | 100 ------------------ src/air/layouts/recursive.cairo | 74 +++++++------ src/air/layouts/recursive/contract.cairo | 30 +++--- src/air/layouts/recursive/public_input.cairo | 2 +- src/air/layouts/recursive_with_poseidon.cairo | 74 +++++++------ .../recursive_with_poseidon/contract.cairo | 30 +++--- .../public_input.cairo | 2 +- src/air/layouts/small.cairo | 74 +++++++------ src/air/layouts/small/contract.cairo | 30 +++--- src/air/layouts/small/public_input.cairo | 2 +- src/air/layouts/starknet.cairo | 4 +- src/air/layouts/starknet/public_input.cairo | 2 +- src/air/layouts/starknet_with_keccak.cairo | 4 +- .../starknet_with_keccak/public_input.cairo | 2 +- src/air/public_input.cairo | 7 +- src/air/public_memory.cairo | 2 +- src/benches/fri/verify.cairo | 2 +- src/benches/stark/commit.cairo | 9 +- src/benches/stark/verify.cairo | 8 +- src/common/blake2s.cairo | 2 +- src/common/blake2s_u8.cairo | 2 +- src/deserialization/traces.cairo | 2 +- src/fri/fri.cairo | 63 +++++------ src/fri/fri_formula.cairo | 3 +- src/fri/fri_layer.cairo | 3 +- src/fri/tests/test_fri_verify.cairo | 4 +- src/lib.cairo | 3 +- src/oods.cairo | 21 ++-- src/stark.cairo | 49 ++++++--- src/stark/stark_verify.cairo | 9 +- src/stark/tests/test_stark_commit.cairo | 14 ++- src/stark/tests/test_stark_proof_verify.cairo | 2 +- src/stark/tests/test_stark_verify.cairo | 18 +++- src/vector_commitment/vector_commitment.cairo | 4 +- src/verifier.cairo | 97 +++++++++-------- 39 files changed, 418 insertions(+), 446 deletions(-) delete mode 100644 src/air/layouts/generator.py diff --git a/src/air/air.cairo b/src/air/air.cairo index 1b38e47b3..e4f455ec4 100644 --- a/src/air/air.cairo +++ b/src/air/air.cairo @@ -9,7 +9,7 @@ trait AIRComposition { point: felt252, trace_domain_size: felt252, trace_generator: felt252, - contract_address_1: ContractAddress, + contract_address: ContractAddress, ) -> felt252; } @@ -21,6 +21,6 @@ trait AIROods { point: felt252, oods_point: felt252, trace_generator: felt252, - contract_address_2: ContractAddress, + contract_address: ContractAddress, ) -> felt252; } diff --git a/src/air/layouts/dex.cairo b/src/air/layouts/dex.cairo index 8bd9b4771..43f5589c7 100644 --- a/src/air/layouts/dex.cairo +++ b/src/air/layouts/dex.cairo @@ -24,31 +24,28 @@ use cairo_verifier::{ common::{math::{Felt252Div, Felt252PartialOrd, pow}, asserts::assert_range_u128} }; use starknet::ContractAddress; -#[cfg(feature: 'split')] -use cairo_verifier::air::layouts::dex::contract::{ - IDexLayoutContract1Dispatcher, - IDexLayoutContract1DispatcherTrait, - IDexLayoutContract2Dispatcher, - IDexLayoutContract2DispatcherTrait, + +#[cfg(feature: 'monolit')] +use cairo_verifier::air::layouts::dex::autogenerated::{ + eval_composition_polynomial_inner as eval_composition_polynomial_inner_, + eval_oods_polynomial_inner as eval_oods_polynomial_inner_, }; -#[cfg(feature: 'split')] +#[cfg(feature: 'monolit')] fn eval_composition_polynomial_inner( mask_values: Span, constraint_coefficients: Span, point: felt252, trace_generator: felt252, global_values: GlobalValues, - contract_address_1: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { - IDexLayoutContract1Dispatcher { - contract_address: contract_address_1 - }.eval_composition_polynomial_inner( + eval_composition_polynomial_inner_( mask_values, constraint_coefficients, point, trace_generator, global_values ) } -#[cfg(feature: 'split')] +#[cfg(feature: 'monolit')] fn eval_oods_polynomial_inner( column_values: Span, oods_values: Span, @@ -56,34 +53,35 @@ fn eval_oods_polynomial_inner( point: felt252, oods_point: felt252, trace_generator: felt252, - contract_address_2: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { - IDexLayoutContract2Dispatcher { - contract_address: contract_address_2 - }.eval_oods_polynomial_inner( + eval_oods_polynomial_inner_( column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, ) } -#[cfg(feature: 'monolit')] -use cairo_verifier::air::layouts::dex::autogenerated::{ - eval_composition_polynomial_inner as eval_composition_polynomial_inner_, - eval_oods_polynomial_inner as eval_oods_polynomial_inner_, +#[cfg(feature: 'split')] +use cairo_verifier::air::layouts::dex::contract::{ + ILayoutCompositionContractDispatcher, ILayoutCompositionContractDispatcherTrait, + ILayoutOodsContractDispatcher, ILayoutOodsContractDispatcherTrait, }; -#[cfg(feature: 'monolit')] +#[cfg(feature: 'split')] fn eval_composition_polynomial_inner( mask_values: Span, constraint_coefficients: Span, point: felt252, trace_generator: felt252, global_values: GlobalValues, - contract_address_1: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { - eval_composition_polynomial_inner_(mask_values, constraint_coefficients, point, trace_generator, global_values) + ILayoutCompositionContractDispatcher { contract_address } + .eval_composition_polynomial_inner( + mask_values, constraint_coefficients, point, trace_generator, global_values + ) } -#[cfg(feature: 'monolit')] +#[cfg(feature: 'split')] fn eval_oods_polynomial_inner( column_values: Span, oods_values: Span, @@ -91,11 +89,12 @@ fn eval_oods_polynomial_inner( point: felt252, oods_point: felt252, trace_generator: felt252, - contract_address_2: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { - eval_oods_polynomial_inner_( - column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, - ) + ILayoutOodsContractDispatcher { contract_address } + .eval_oods_polynomial_inner( + column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, + ) } impl DexAIRCompositionImpl of AIRComposition { @@ -107,7 +106,7 @@ impl DexAIRCompositionImpl of AIRComposition { point: felt252, trace_domain_size: felt252, trace_generator: felt252, - contract_address_1: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { let memory_z = interaction_elements.memory_multi_column_perm_perm_interaction_elm; let memory_alpha = interaction_elements.memory_multi_column_perm_hash_interaction_elm0; @@ -166,7 +165,12 @@ impl DexAIRCompositionImpl of AIRComposition { }; eval_composition_polynomial_inner( - mask_values, constraint_coefficients, point, trace_generator, global_values, contract_address_1, + mask_values, + constraint_coefficients, + point, + trace_generator, + global_values, + contract_address, ) } } @@ -179,10 +183,16 @@ impl DexAIROodsImpl of AIROods { point: felt252, oods_point: felt252, trace_generator: felt252, - contract_address_2: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { eval_oods_polynomial_inner( - column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, contract_address_2, + column_values, + oods_values, + constraint_coefficients, + point, + oods_point, + trace_generator, + contract_address, ) } } diff --git a/src/air/layouts/dex/contract.cairo b/src/air/layouts/dex/contract.cairo index 188b1ba4b..70721d64a 100644 --- a/src/air/layouts/dex/contract.cairo +++ b/src/air/layouts/dex/contract.cairo @@ -1,7 +1,7 @@ use cairo_verifier::air::layouts::dex::global_values::GlobalValues; #[starknet::interface] -trait IDexLayoutContract1 { +trait ILayoutCompositionContract { fn eval_composition_polynomial_inner( self: @ContractState, mask_values: Span, @@ -13,7 +13,7 @@ trait IDexLayoutContract1 { } #[starknet::interface] -trait IDexLayoutContract2 { +trait ILayoutOodsContract { fn eval_oods_polynomial_inner( self: @ContractState, column_values: Span, @@ -26,18 +26,17 @@ trait IDexLayoutContract2 { } #[starknet::contract] -mod DexLayoutContract1 { - use super::IDexLayoutContract1; +mod LayoutCompositionContract { + use super::ILayoutCompositionContract; use cairo_verifier::air::layouts::dex::{ - global_values::GlobalValues, - autogenerated::eval_composition_polynomial_inner, + global_values::GlobalValues, autogenerated::eval_composition_polynomial_inner, }; #[storage] struct Storage {} #[abi(embed_v0)] - impl DexLayoutContract1 of IDexLayoutContract1 { + impl LayoutCompositionContract of ILayoutCompositionContract { fn eval_composition_polynomial_inner( self: @ContractState, mask_values: Span, @@ -47,29 +46,24 @@ mod DexLayoutContract1 { global_values: GlobalValues ) -> felt252 { eval_composition_polynomial_inner( - mask_values, - constraint_coefficients, - point, - trace_generator, - global_values + mask_values, constraint_coefficients, point, trace_generator, global_values ) } } } #[starknet::contract] -mod DexLayoutContract2 { - use super::IDexLayoutContract2; +mod LayoutOodsContract { + use super::ILayoutOodsContract; use cairo_verifier::air::layouts::dex::{ - global_values::GlobalValues, - autogenerated::eval_oods_polynomial_inner, + global_values::GlobalValues, autogenerated::eval_oods_polynomial_inner, }; #[storage] struct Storage {} #[abi(embed_v0)] - impl DexLayoutContract2 of IDexLayoutContract2 { + impl LayoutOodsContract of ILayoutOodsContract { fn eval_oods_polynomial_inner( self: @ContractState, column_values: Span, @@ -89,4 +83,4 @@ mod DexLayoutContract2 { ) } } -} \ No newline at end of file +} diff --git a/src/air/layouts/dex/public_input.cairo b/src/air/layouts/dex/public_input.cairo index 616ab8437..772fe53e9 100644 --- a/src/air/layouts/dex/public_input.cairo +++ b/src/air/layouts/dex/public_input.cairo @@ -97,7 +97,7 @@ impl DexPublicInputImpl of PublicInputTrait { ref memory_index ); - // 3. Output segment + // 3. Output segment let output_len = output_stop - output_start; let output = memory .extract_range( diff --git a/src/air/layouts/generator.py b/src/air/layouts/generator.py deleted file mode 100644 index 9f4105128..000000000 --- a/src/air/layouts/generator.py +++ /dev/null @@ -1,100 +0,0 @@ -import re -from random import random -import sys - -sys.setrecursionlimit(10**6) - -all_vars = {} -extern = {} -last_override = {} -code = [] -comment_before = [] - -def get_visited(vertex, excluded): - visited = set() - def dfs(v): - visited.add(v) - for u in all_vars[v]: - if u not in visited and u not in excluded: - dfs(u) - dfs(vertex) - return visited - -def get_renamed(varname): - if varname not in all_vars: - return varname - i = 1 - while True: - new_varname = varname + '__' + str(i) - if new_varname not in all_vars: - return new_varname - i += 1 - - -def get_code(set): - s = "" - pop_count = 0 - for (var, line), comment in zip(code, comment_before): - if var in set: - if pop_count > 0: - s += f'mask_values = mask_values.slice({pop_count}, mask_values.len() - {pop_count});\n ' - pop_count = 0 - s += comment - s += line - elif line.find('mask_values.pop_front().unwrap()') != -1: - s += comment - pop_count += 1 - if pop_count > 0: - s += f'mask_values = mask_values.slice({pop_count}, mask_values.len() - {pop_count});\n ' - return s - - -with open('starknet_with_keccak.txt') as f: - vars = f.read().split('let') - comment_before.append(' // ' + vars[0].split('// ')[1]) - for var in vars[1:]: - # print('========') - s = var.split(' // ') - if len(s) > 1: - var = s[0] + ' ' - comment_before.append('// ' + s[1]) - else: - var = s[0] - comment_before.append('') - - varname, assign = ' '.join([x.strip() for x in var.strip().split('\n')]).split(' = ') - renamed_var = get_renamed(varname) - dependencies = re.findall(r"([a-zA-Z_][a-zA-Z0-9_]*)", assign) - all_vars[renamed_var] = [] - extern[renamed_var] = [] - for d in dependencies: - if d in last_override: - all_vars[renamed_var].append(last_override[d]) - else: - extern[renamed_var].append(d) - last_override[varname] = renamed_var - code.append((renamed_var, 'let' + var)) - # print(renamed_var) - # print(all_vars[renamed_var], extern[renamed_var]) - - # print(all_vars.keys()) - split_points = [ - 'total_sum__95', - 'total_sum__195', - 'total_sum__229', - 'total_sum__260', - 'total_sum__285', - 'total_sum__310', - 'total_sum__347', - ] - prev = set() - parts = [] - for s in split_points: - parts.append(get_visited(s, prev)) - prev = {s} - # print(len(part4)) - # part2 = get_visited('total_sum__198', {'total_sum__99'}) - - with open('starknet_with_keccak_2.out', 'w') as f: - f.write(get_code(parts[2])) - # print(get_code(part2)) \ No newline at end of file diff --git a/src/air/layouts/recursive.cairo b/src/air/layouts/recursive.cairo index 5f7552f8a..4978cebd3 100644 --- a/src/air/layouts/recursive.cairo +++ b/src/air/layouts/recursive.cairo @@ -24,31 +24,28 @@ use cairo_verifier::{ common::{math::{Felt252Div, Felt252PartialOrd, pow}, asserts::assert_range_u128} }; use starknet::ContractAddress; -#[cfg(feature: 'split')] -use cairo_verifier::air::layouts::recursive::contract::{ - IRecursiveLayoutContract1Dispatcher, - IRecursiveLayoutContract1DispatcherTrait, - IRecursiveLayoutContract2Dispatcher, - IRecursiveLayoutContract2DispatcherTrait, + +#[cfg(feature: 'monolit')] +use cairo_verifier::air::layouts::recursive::autogenerated::{ + eval_composition_polynomial_inner as eval_composition_polynomial_inner_, + eval_oods_polynomial_inner as eval_oods_polynomial_inner_, }; -#[cfg(feature: 'split')] +#[cfg(feature: 'monolit')] fn eval_composition_polynomial_inner( mask_values: Span, constraint_coefficients: Span, point: felt252, trace_generator: felt252, global_values: GlobalValues, - contract_address_1: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { - IRecursiveLayoutContract1Dispatcher { - contract_address: contract_address_1 - }.eval_composition_polynomial_inner( + eval_composition_polynomial_inner_( mask_values, constraint_coefficients, point, trace_generator, global_values ) } -#[cfg(feature: 'split')] +#[cfg(feature: 'monolit')] fn eval_oods_polynomial_inner( column_values: Span, oods_values: Span, @@ -56,34 +53,35 @@ fn eval_oods_polynomial_inner( point: felt252, oods_point: felt252, trace_generator: felt252, - contract_address_2: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { - IRecursiveLayoutContract2Dispatcher { - contract_address: contract_address_2 - }.eval_oods_polynomial_inner( + eval_oods_polynomial_inner_( column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, ) } -#[cfg(feature: 'monolit')] -use cairo_verifier::air::layouts::recursive::autogenerated::{ - eval_composition_polynomial_inner as eval_composition_polynomial_inner_, - eval_oods_polynomial_inner as eval_oods_polynomial_inner_, +#[cfg(feature: 'split')] +use cairo_verifier::air::layouts::recursive::contract::{ + ILayoutCompositionContractDispatcher, ILayoutCompositionContractDispatcherTrait, + ILayoutOodsContractDispatcher, ILayoutOodsContractDispatcherTrait, }; -#[cfg(feature: 'monolit')] +#[cfg(feature: 'split')] fn eval_composition_polynomial_inner( mask_values: Span, constraint_coefficients: Span, point: felt252, trace_generator: felt252, global_values: GlobalValues, - contract_address_1: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { - eval_composition_polynomial_inner_(mask_values, constraint_coefficients, point, trace_generator, global_values) + ILayoutCompositionContractDispatcherTrait { contract_address } + .eval_composition_polynomial_inner( + mask_values, constraint_coefficients, point, trace_generator, global_values + ) } -#[cfg(feature: 'monolit')] +#[cfg(feature: 'split')] fn eval_oods_polynomial_inner( column_values: Span, oods_values: Span, @@ -91,11 +89,12 @@ fn eval_oods_polynomial_inner( point: felt252, oods_point: felt252, trace_generator: felt252, - contract_address_2: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { - eval_oods_polynomial_inner_( - column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, - ) + ILayoutOodsContractDispatcher { contract_address } + .eval_oods_polynomial_inner( + column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, + ) } impl RecursiveAIRCompositionImpl of AIRComposition { @@ -107,7 +106,7 @@ impl RecursiveAIRCompositionImpl of AIRComposition felt252 { let memory_z = interaction_elements.memory_multi_column_perm_perm_interaction_elm; let memory_alpha = interaction_elements.memory_multi_column_perm_hash_interaction_elm0; @@ -167,7 +166,12 @@ impl RecursiveAIRCompositionImpl of AIRComposition felt252 { eval_oods_polynomial_inner( - column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, contract_address_2, + column_values, + oods_values, + constraint_coefficients, + point, + oods_point, + trace_generator, + contract_address, ) } } diff --git a/src/air/layouts/recursive/contract.cairo b/src/air/layouts/recursive/contract.cairo index 9fd009bc5..57ec58d23 100644 --- a/src/air/layouts/recursive/contract.cairo +++ b/src/air/layouts/recursive/contract.cairo @@ -1,7 +1,7 @@ use cairo_verifier::air::layouts::recursive::global_values::GlobalValues; #[starknet::interface] -trait IRecursiveLayoutContract1 { +trait ILayoutCompositionContract { fn eval_composition_polynomial_inner( self: @ContractState, mask_values: Span, @@ -13,7 +13,7 @@ trait IRecursiveLayoutContract1 { } #[starknet::interface] -trait IRecursiveLayoutContract2 { +trait ILayoutOodsContract { fn eval_oods_polynomial_inner( self: @ContractState, column_values: Span, @@ -26,18 +26,17 @@ trait IRecursiveLayoutContract2 { } #[starknet::contract] -mod RecursiveLayoutContract1 { - use super::IRecursiveLayoutContract1; +mod LayoutCompositionContract { + use super::ILayoutCompositionContract; use cairo_verifier::air::layouts::recursive::{ - global_values::GlobalValues, - autogenerated::eval_composition_polynomial_inner, + global_values::GlobalValues, autogenerated::eval_composition_polynomial_inner, }; #[storage] struct Storage {} #[abi(embed_v0)] - impl RecursiveLayoutContract1 of IRecursiveLayoutContract1 { + impl LayoutCompositionContract of ILayoutCompositionContract { fn eval_composition_polynomial_inner( self: @ContractState, mask_values: Span, @@ -47,29 +46,24 @@ mod RecursiveLayoutContract1 { global_values: GlobalValues ) -> felt252 { eval_composition_polynomial_inner( - mask_values, - constraint_coefficients, - point, - trace_generator, - global_values + mask_values, constraint_coefficients, point, trace_generator, global_values ) } } } #[starknet::contract] -mod RecursiveLayoutContract2 { - use super::IRecursiveLayoutContract2; +mod LayoutOodsContract { + use super::ILayoutOodsContract; use cairo_verifier::air::layouts::recursive::{ - global_values::GlobalValues, - autogenerated::eval_oods_polynomial_inner, + global_values::GlobalValues, autogenerated::eval_oods_polynomial_inner, }; #[storage] struct Storage {} #[abi(embed_v0)] - impl RecursiveLayoutContract2 of IRecursiveLayoutContract2 { + impl LayoutOodsContract of ILayoutOodsContract { fn eval_oods_polynomial_inner( self: @ContractState, column_values: Span, @@ -89,4 +83,4 @@ mod RecursiveLayoutContract2 { ) } } -} \ No newline at end of file +} diff --git a/src/air/layouts/recursive/public_input.cairo b/src/air/layouts/recursive/public_input.cairo index ab73b9456..5a997cf31 100644 --- a/src/air/layouts/recursive/public_input.cairo +++ b/src/air/layouts/recursive/public_input.cairo @@ -97,7 +97,7 @@ impl RecursivePublicInputImpl of PublicInputTrait { ref memory_index ); - // 3. Output segment + // 3. Output segment let output_len = output_stop - output_start; let output = memory .extract_range( diff --git a/src/air/layouts/recursive_with_poseidon.cairo b/src/air/layouts/recursive_with_poseidon.cairo index 8dfae689e..d88cf076d 100644 --- a/src/air/layouts/recursive_with_poseidon.cairo +++ b/src/air/layouts/recursive_with_poseidon.cairo @@ -28,31 +28,28 @@ use cairo_verifier::{ common::{math::{Felt252Div, Felt252PartialOrd, pow}, asserts::assert_range_u128} }; use starknet::ContractAddress; -#[cfg(feature: 'split')] -use cairo_verifier::air::layouts::recursive_with_poseidon::contract::{ - IRecursiveWithPoseidonLayoutContract1Dispatcher, - IRecursiveWithPoseidonLayoutContract1DispatcherTrait, - IRecursiveWithPoseidonLayoutContract2Dispatcher, - IRecursiveWithPoseidonLayoutContract2DispatcherTrait, + +#[cfg(feature: 'monolit')] +use cairo_verifier::air::layouts::recursive_with_poseidon::autogenerated::{ + eval_composition_polynomial_inner as eval_composition_polynomial_inner_, + eval_oods_polynomial_inner as eval_oods_polynomial_inner_, }; -#[cfg(feature: 'split')] +#[cfg(feature: 'monolit')] fn eval_composition_polynomial_inner( mask_values: Span, constraint_coefficients: Span, point: felt252, trace_generator: felt252, global_values: GlobalValues, - contract_address_1: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { - IRecursiveWithPoseidonLayoutContract1Dispatcher { - contract_address: contract_address_1 - }.eval_composition_polynomial_inner( + eval_composition_polynomial_inner_( mask_values, constraint_coefficients, point, trace_generator, global_values ) } -#[cfg(feature: 'split')] +#[cfg(feature: 'monolit')] fn eval_oods_polynomial_inner( column_values: Span, oods_values: Span, @@ -60,34 +57,35 @@ fn eval_oods_polynomial_inner( point: felt252, oods_point: felt252, trace_generator: felt252, - contract_address_2: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { - IRecursiveWithPoseidonLayoutContract2Dispatcher { - contract_address: contract_address_2 - }.eval_oods_polynomial_inner( + eval_oods_polynomial_inner_( column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, ) } -#[cfg(feature: 'monolit')] -use cairo_verifier::air::layouts::recursive_with_poseidon::autogenerated::{ - eval_composition_polynomial_inner as eval_composition_polynomial_inner_, - eval_oods_polynomial_inner as eval_oods_polynomial_inner_, +#[cfg(feature: 'split')] +use cairo_verifier::air::layouts::recursive_with_poseidon::contract::{ + ILayoutCompositionContractDispatcher, ILayoutCompositionContractDispatcherTrait, + ILayoutOodsContractDispatcher, ILayoutOodsContractDispatcherTrait, }; -#[cfg(feature: 'monolit')] +#[cfg(feature: 'split')] fn eval_composition_polynomial_inner( mask_values: Span, constraint_coefficients: Span, point: felt252, trace_generator: felt252, global_values: GlobalValues, - contract_address_1: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { - eval_composition_polynomial_inner_(mask_values, constraint_coefficients, point, trace_generator, global_values) + ILayoutCompositionContractDispatcher { contract_address } + .eval_composition_polynomial_inner( + mask_values, constraint_coefficients, point, trace_generator, global_values + ) } -#[cfg(feature: 'monolit')] +#[cfg(feature: 'split')] fn eval_oods_polynomial_inner( column_values: Span, oods_values: Span, @@ -95,11 +93,12 @@ fn eval_oods_polynomial_inner( point: felt252, oods_point: felt252, trace_generator: felt252, - contract_address_2: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { - eval_oods_polynomial_inner_( - column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, - ) + ILayoutOodsContractDispatcher { contract_address } + .eval_oods_polynomial_inner( + column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, + ) } impl RecursiveWithPoseidonAIRCompositionImpl of AIRComposition { @@ -111,7 +110,7 @@ impl RecursiveWithPoseidonAIRCompositionImpl of AIRComposition felt252 { let memory_z = interaction_elements.memory_multi_column_perm_perm_interaction_elm; let memory_alpha = interaction_elements.memory_multi_column_perm_hash_interaction_elm0; @@ -196,7 +195,12 @@ impl RecursiveWithPoseidonAIRCompositionImpl of AIRComposition felt252 { eval_oods_polynomial_inner( - column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, contract_address_2, + column_values, + oods_values, + constraint_coefficients, + point, + oods_point, + trace_generator, + contract_address, ) } } diff --git a/src/air/layouts/recursive_with_poseidon/contract.cairo b/src/air/layouts/recursive_with_poseidon/contract.cairo index 757fd2597..25bde171b 100644 --- a/src/air/layouts/recursive_with_poseidon/contract.cairo +++ b/src/air/layouts/recursive_with_poseidon/contract.cairo @@ -1,7 +1,7 @@ use cairo_verifier::air::layouts::recursive_with_poseidon::global_values::GlobalValues; #[starknet::interface] -trait IRecursiveWithPoseidonLayoutContract1 { +trait ILayoutCompositionContract { fn eval_composition_polynomial_inner( self: @ContractState, mask_values: Span, @@ -13,7 +13,7 @@ trait IRecursiveWithPoseidonLayoutContract1 { } #[starknet::interface] -trait IRecursiveWithPoseidonLayoutContract2 { +trait ILayoutOodsContract { fn eval_oods_polynomial_inner( self: @ContractState, column_values: Span, @@ -26,18 +26,17 @@ trait IRecursiveWithPoseidonLayoutContract2 { } #[starknet::contract] -mod RecursiveWithPoseidonLayoutContract1 { - use super::IRecursiveWithPoseidonLayoutContract1; +mod LayoutCompositionContract { + use super::ILayoutCompositionContract; use cairo_verifier::air::layouts::recursive_with_poseidon::{ - global_values::GlobalValues, - autogenerated::eval_composition_polynomial_inner, + global_values::GlobalValues, autogenerated::eval_composition_polynomial_inner, }; #[storage] struct Storage {} #[abi(embed_v0)] - impl RecursiveWithPoseidonLayoutContract1 of IRecursiveWithPoseidonLayoutContract1 { + impl LayoutCompositionContract of ILayoutCompositionContract { fn eval_composition_polynomial_inner( self: @ContractState, mask_values: Span, @@ -47,29 +46,24 @@ mod RecursiveWithPoseidonLayoutContract1 { global_values: GlobalValues ) -> felt252 { eval_composition_polynomial_inner( - mask_values, - constraint_coefficients, - point, - trace_generator, - global_values + mask_values, constraint_coefficients, point, trace_generator, global_values ) } } } #[starknet::contract] -mod RecursiveWithPoseidonLayoutContract2 { - use super::IRecursiveWithPoseidonLayoutContract2; +mod LayoutOodsContract { + use super::ILayoutOodsContract; use cairo_verifier::air::layouts::recursive_with_poseidon::{ - global_values::GlobalValues, - autogenerated::eval_oods_polynomial_inner, + global_values::GlobalValues, autogenerated::eval_oods_polynomial_inner, }; #[storage] struct Storage {} #[abi(embed_v0)] - impl RecursiveWithPoseidonLayoutContract2 of IRecursiveWithPoseidonLayoutContract2 { + impl LayoutOodsContract of ILayoutOodsContract { fn eval_oods_polynomial_inner( self: @ContractState, column_values: Span, @@ -89,4 +83,4 @@ mod RecursiveWithPoseidonLayoutContract2 { ) } } -} \ No newline at end of file +} diff --git a/src/air/layouts/recursive_with_poseidon/public_input.cairo b/src/air/layouts/recursive_with_poseidon/public_input.cairo index 7f53bfa84..b33b8879a 100644 --- a/src/air/layouts/recursive_with_poseidon/public_input.cairo +++ b/src/air/layouts/recursive_with_poseidon/public_input.cairo @@ -98,7 +98,7 @@ impl RecursiveWithPoseidonPublicInputImpl of PublicInputTrait { ref memory_index ); - // 3. Output segment + // 3. Output segment let output_len = output_stop - output_start; let output = memory .extract_range( diff --git a/src/air/layouts/small.cairo b/src/air/layouts/small.cairo index f5ff07afb..e0191781e 100644 --- a/src/air/layouts/small.cairo +++ b/src/air/layouts/small.cairo @@ -24,31 +24,28 @@ use cairo_verifier::{ common::{math::{Felt252Div, Felt252PartialOrd, pow}, asserts::assert_range_u128} }; use starknet::ContractAddress; -#[cfg(feature: 'split')] -use cairo_verifier::air::layouts::small::contract::{ - ISmallLayoutContract1Dispatcher, - ISmallLayoutContract1DispatcherTrait, - ISmallLayoutContract2Dispatcher, - ISmallLayoutContract2DispatcherTrait, + +#[cfg(feature: 'monolit')] +use cairo_verifier::air::layouts::small::autogenerated::{ + eval_composition_polynomial_inner as eval_composition_polynomial_inner_, + eval_oods_polynomial_inner as eval_oods_polynomial_inner_, }; -#[cfg(feature: 'split')] +#[cfg(feature: 'monolit')] fn eval_composition_polynomial_inner( mask_values: Span, constraint_coefficients: Span, point: felt252, trace_generator: felt252, global_values: GlobalValues, - contract_address_1: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { - ISmallLayoutContract1Dispatcher { - contract_address: contract_address_1 - }.eval_composition_polynomial_inner( + eval_composition_polynomial_inner_( mask_values, constraint_coefficients, point, trace_generator, global_values ) } -#[cfg(feature: 'split')] +#[cfg(feature: 'monolit')] fn eval_oods_polynomial_inner( column_values: Span, oods_values: Span, @@ -56,34 +53,35 @@ fn eval_oods_polynomial_inner( point: felt252, oods_point: felt252, trace_generator: felt252, - contract_address_2: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { - ISmallLayoutContract2Dispatcher { - contract_address: contract_address_2 - }.eval_oods_polynomial_inner( + eval_oods_polynomial_inner_( column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, ) } -#[cfg(feature: 'monolit')] -use cairo_verifier::air::layouts::small::autogenerated::{ - eval_composition_polynomial_inner as eval_composition_polynomial_inner_, - eval_oods_polynomial_inner as eval_oods_polynomial_inner_, +#[cfg(feature: 'split')] +use cairo_verifier::air::layouts::small::contract::{ + ILayoutCompositionContractDispatcher, ILayoutCompositionContractDispatcherTrait, + ILayoutOodsContractDispatcher, ILayoutOodsContractDispatcherTrait, }; -#[cfg(feature: 'monolit')] +#[cfg(feature: 'split')] fn eval_composition_polynomial_inner( mask_values: Span, constraint_coefficients: Span, point: felt252, trace_generator: felt252, global_values: GlobalValues, - contract_address_1: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { - eval_composition_polynomial_inner_(mask_values, constraint_coefficients, point, trace_generator, global_values) + ILayoutCompositionContractDispatcher { contract_address } + .eval_composition_polynomial_inner( + mask_values, constraint_coefficients, point, trace_generator, global_values + ) } -#[cfg(feature: 'monolit')] +#[cfg(feature: 'split')] fn eval_oods_polynomial_inner( column_values: Span, oods_values: Span, @@ -91,11 +89,12 @@ fn eval_oods_polynomial_inner( point: felt252, oods_point: felt252, trace_generator: felt252, - contract_address_2: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { - eval_oods_polynomial_inner_( - column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, - ) + ILayoutOodsContractDispatcher { contract_address } + .eval_oods_polynomial_inner( + column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, + ) } impl SmallAIRCompositionImpl of AIRComposition { @@ -107,7 +106,7 @@ impl SmallAIRCompositionImpl of AIRComposition point: felt252, trace_domain_size: felt252, trace_generator: felt252, - contract_address_1: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { let memory_z = interaction_elements.memory_multi_column_perm_perm_interaction_elm; let memory_alpha = interaction_elements.memory_multi_column_perm_hash_interaction_elm0; @@ -166,7 +165,12 @@ impl SmallAIRCompositionImpl of AIRComposition }; eval_composition_polynomial_inner( - mask_values, constraint_coefficients, point, trace_generator, global_values, contract_address_1, + mask_values, + constraint_coefficients, + point, + trace_generator, + global_values, + contract_address, ) } } @@ -179,10 +183,16 @@ impl SmallAIROodsImpl of AIROods { point: felt252, oods_point: felt252, trace_generator: felt252, - contract_address_2: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { eval_oods_polynomial_inner( - column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, contract_address_2, + column_values, + oods_values, + constraint_coefficients, + point, + oods_point, + trace_generator, + contract_address, ) } } diff --git a/src/air/layouts/small/contract.cairo b/src/air/layouts/small/contract.cairo index 8548f35bb..2e52617a0 100644 --- a/src/air/layouts/small/contract.cairo +++ b/src/air/layouts/small/contract.cairo @@ -1,7 +1,7 @@ use cairo_verifier::air::layouts::small::global_values::GlobalValues; #[starknet::interface] -trait ISmallLayoutContract1 { +trait ILayoutCompositionContract { fn eval_composition_polynomial_inner( self: @ContractState, mask_values: Span, @@ -13,7 +13,7 @@ trait ISmallLayoutContract1 { } #[starknet::interface] -trait ISmallLayoutContract2 { +trait ILayoutOodsContract { fn eval_oods_polynomial_inner( self: @ContractState, column_values: Span, @@ -26,18 +26,17 @@ trait ISmallLayoutContract2 { } #[starknet::contract] -mod SmallLayoutContract1 { - use super::ISmallLayoutContract1; +mod LayoutCompositionContract { + use super::ILayoutCompositionContract; use cairo_verifier::air::layouts::small::{ - global_values::GlobalValues, - autogenerated::eval_composition_polynomial_inner, + global_values::GlobalValues, autogenerated::eval_composition_polynomial_inner, }; #[storage] struct Storage {} #[abi(embed_v0)] - impl SmallLayoutContract1 of ISmallLayoutContract1 { + impl LayoutCompositionContract of ILayoutCompositionContract { fn eval_composition_polynomial_inner( self: @ContractState, mask_values: Span, @@ -47,29 +46,24 @@ mod SmallLayoutContract1 { global_values: GlobalValues ) -> felt252 { eval_composition_polynomial_inner( - mask_values, - constraint_coefficients, - point, - trace_generator, - global_values + mask_values, constraint_coefficients, point, trace_generator, global_values ) } } } #[starknet::contract] -mod SmallLayoutContract2 { - use super::ISmallLayoutContract2; +mod LayoutOodsContract { + use super::ILayoutOodsContract; use cairo_verifier::air::layouts::small::{ - global_values::GlobalValues, - autogenerated::eval_oods_polynomial_inner, + global_values::GlobalValues, autogenerated::eval_oods_polynomial_inner, }; #[storage] struct Storage {} #[abi(embed_v0)] - impl SmallLayoutContract2 of ISmallLayoutContract2 { + impl LayoutOodsContract of ILayoutOodsContract { fn eval_oods_polynomial_inner( self: @ContractState, column_values: Span, @@ -89,4 +83,4 @@ mod SmallLayoutContract2 { ) } } -} \ No newline at end of file +} diff --git a/src/air/layouts/small/public_input.cairo b/src/air/layouts/small/public_input.cairo index 06dba89e7..677536c87 100644 --- a/src/air/layouts/small/public_input.cairo +++ b/src/air/layouts/small/public_input.cairo @@ -97,7 +97,7 @@ impl SmallPublicInputImpl of PublicInputTrait { ref memory_index ); - // 3. Output segment + // 3. Output segment let output_len = output_stop - output_start; let output = memory .extract_range( diff --git a/src/air/layouts/starknet.cairo b/src/air/layouts/starknet.cairo index 8fe18aabe..49b85f989 100644 --- a/src/air/layouts/starknet.cairo +++ b/src/air/layouts/starknet.cairo @@ -41,7 +41,7 @@ impl StarknetAIRCompositionImpl of AIRComposition felt252 { let memory_z = interaction_elements.memory_multi_column_perm_perm_interaction_elm; let memory_alpha = interaction_elements.memory_multi_column_perm_hash_interaction_elm0; @@ -155,7 +155,7 @@ impl StarknetAIROodsImpl of AIROods { point: felt252, oods_point: felt252, trace_generator: felt252, - contract_address_2: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { eval_oods_polynomial_inner( column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, diff --git a/src/air/layouts/starknet/public_input.cairo b/src/air/layouts/starknet/public_input.cairo index edfb424ec..a82997643 100644 --- a/src/air/layouts/starknet/public_input.cairo +++ b/src/air/layouts/starknet/public_input.cairo @@ -98,7 +98,7 @@ impl StarknetPublicInputImpl of PublicInputTrait { ref memory_index ); - // 3. Output segment + // 3. Output segment let output_len = output_stop - output_start; let output = memory .extract_range( diff --git a/src/air/layouts/starknet_with_keccak.cairo b/src/air/layouts/starknet_with_keccak.cairo index 453865bcf..c9354988f 100644 --- a/src/air/layouts/starknet_with_keccak.cairo +++ b/src/air/layouts/starknet_with_keccak.cairo @@ -43,7 +43,7 @@ impl StarknetWithKeccakAIRCompositionImpl of AIRComposition felt252 { let memory_z = interaction_elements.memory_multi_column_perm_perm_interaction_elm; let memory_alpha = interaction_elements.memory_multi_column_perm_hash_interaction_elm0; @@ -177,7 +177,7 @@ impl StarknetWithKeccakAIROodsImpl of AIROods { point: felt252, oods_point: felt252, trace_generator: felt252, - contract_address_2: ContractAddress, + contract_address: ContractAddress, ) -> felt252 { eval_oods_polynomial_inner( column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, diff --git a/src/air/layouts/starknet_with_keccak/public_input.cairo b/src/air/layouts/starknet_with_keccak/public_input.cairo index 9b477ddeb..0a730575e 100644 --- a/src/air/layouts/starknet_with_keccak/public_input.cairo +++ b/src/air/layouts/starknet_with_keccak/public_input.cairo @@ -98,7 +98,7 @@ impl StarknetWithKeccakPublicInputImpl of PublicInputTrait { ref memory_index ); - // 3. Output segment + // 3. Output segment let output_len = output_stop - output_start; let output = memory .extract_range( diff --git a/src/air/public_input.cairo b/src/air/public_input.cairo index dba5f5c7c..7fac99dc9 100644 --- a/src/air/public_input.cairo +++ b/src/air/public_input.cairo @@ -58,7 +58,8 @@ trait PublicInputTrait { fn validate(self: @PublicInput, stark_domains: @StarkDomains); } -// Computes the hash of the public input, which is used as the initial seed for the Fiat-Shamir heuristic. +// Computes the hash of the public input, which is used as the initial seed for the Fiat-Shamir +// heuristic. fn get_public_input_hash(public_input: @PublicInput) -> felt252 { // Main page hash. let mut main_page_hash_state = PedersenTrait::new(0); @@ -172,7 +173,7 @@ fn verify_cairo1_public_input(public_input: @PublicInput) -> (felt252, felt252) .extract_range_unchecked(initial_pc.try_into().unwrap(), memory.len() - output_len); let program_hash = poseidon_hash_span(program); - // 2. Output segment + // 2. Output segment let output = memory.extract_range_unchecked(memory.len() - output_len, output_len); let output_hash = poseidon_hash_span(output); (program_hash, output_hash) @@ -195,3 +196,5 @@ mod tests { } } // === RECURSIVE END === + + diff --git a/src/air/public_memory.cairo b/src/air/public_memory.cairo index af58c1e28..55f3a2427 100644 --- a/src/air/public_memory.cairo +++ b/src/air/public_memory.cairo @@ -56,7 +56,7 @@ impl PageImpl of PageTrait { let current = *self.at(offset); - // TODO is this needed? If not we can just use slice directly + // TODO is this needed? If not we can just use slice directly assert(current.address == (addr + i).into(), 'Invalid address'); arr.append(current.value); i += 1; diff --git a/src/benches/fri/verify.cairo b/src/benches/fri/verify.cairo index b71e57ffd..d549537c6 100644 --- a/src/benches/fri/verify.cairo +++ b/src/benches/fri/verify.cairo @@ -7,6 +7,6 @@ fn bench_fri_verify() { let _witness = stone_proof_fibonacci_keccak::fri::witness::get(); fri_verify_initial(queries, commitment, decommitment); - // TODO: add next steps +// TODO: add next steps } diff --git a/src/benches/stark/commit.cairo b/src/benches/stark/commit.cairo index 09d515dce..86184e351 100644 --- a/src/benches/stark/commit.cairo +++ b/src/benches/stark/commit.cairo @@ -13,5 +13,12 @@ fn bench_stark_commit() { let config = stone_proof_fibonacci_keccak::stark::config::get(); let stark_domains = stone_proof_fibonacci_keccak::stark::domains::get(); - stark_commit(ref channel, @public_input, @unsent_commitment, @config, @stark_domains, 0.try_into().unwrap()); + stark_commit( + ref channel, + @public_input, + @unsent_commitment, + @config, + @stark_domains, + 0.try_into().unwrap() + ); } diff --git a/src/benches/stark/verify.cairo b/src/benches/stark/verify.cairo index 0e0bf66ce..b117610b6 100644 --- a/src/benches/stark/verify.cairo +++ b/src/benches/stark/verify.cairo @@ -11,6 +11,12 @@ fn bench_stark_verify() { let stark_domains = stone_proof_fibonacci_keccak::stark::domains::get(); stark_verify( - NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND, queries, commitment, witness, stark_domains, 0.try_into().unwrap() + NUM_COLUMNS_FIRST, + NUM_COLUMNS_SECOND, + queries, + commitment, + witness, + stark_domains, + 0.try_into().unwrap() ); } diff --git a/src/common/blake2s.cairo b/src/common/blake2s.cairo index d4174f236..f9926e2a8 100644 --- a/src/common/blake2s.cairo +++ b/src/common/blake2s.cairo @@ -324,7 +324,7 @@ fn blake2s_update(mut s: blake2s_state, in: Array) -> blake2s_state { fn blake2s_final(mut s: blake2s_state) -> u256 { assert(s.f0 == 0, 'blake2s_is_lastblock'); - // blake2s_increment_counter + // blake2s_increment_counter s.t0 = u32_wrapping_add(s.t0, s.buflen * 4); if s.t0 < s.buflen { s.t1 = u32_wrapping_add(s.t1, 1); diff --git a/src/common/blake2s_u8.cairo b/src/common/blake2s_u8.cairo index 71be4cf98..e896c9180 100644 --- a/src/common/blake2s_u8.cairo +++ b/src/common/blake2s_u8.cairo @@ -338,7 +338,7 @@ fn blake2s_update(mut s: blake2s_state, in: Array) -> blake2s_state { fn blake2s_final(mut s: blake2s_state) -> u256 { assert(s.f0 == 0, 'blake2s_is_lastblock'); - // blake2s_increment_counter + // blake2s_increment_counter s.t0 = u32_wrapping_add(s.t0, s.buflen); if s.t0 < s.buflen { s.t1 = u32_wrapping_add(s.t1, 1); diff --git a/src/deserialization/traces.cairo b/src/deserialization/traces.cairo index 00ca33766..2fc865c36 100644 --- a/src/deserialization/traces.cairo +++ b/src/deserialization/traces.cairo @@ -19,7 +19,7 @@ use cairo_verifier::air::layouts::dex::{ }; #[cfg(feature: 'recursive')] use cairo_verifier::air::layouts::recursive::{ - traces::TracesConfig, traces::{TracesUnsentCommitment, TracesDecommitment, TracesWitness} + traces::TracesConfig, traces::{TracesUnsentCommitment, TracesDecommitment, TracesWitness} }; #[cfg(feature: 'recursive_with_poseidon')] use cairo_verifier::air::layouts::recursive_with_poseidon::{ diff --git a/src/fri/fri.cairo b/src/fri/fri.cairo index 32e4f7b26..cdd998a33 100644 --- a/src/fri/fri.cairo +++ b/src/fri/fri.cairo @@ -151,9 +151,7 @@ fn fri_verify_layer_step( // Params. let coset_size = pow(2, step_size); - let params = FriLayerComputationParams { - coset_size, fri_group, eval_point: eval_point - }; + let params = FriLayerComputationParams { coset_size, fri_group, eval_point: eval_point }; // Compute next layer queries. let (next_queries, verify_indices, verify_y_values) = compute_next_layer( @@ -173,9 +171,7 @@ fn fri_verify_layer_step( // FRI protocol component decommitment. fn fri_verify_initial( - queries: Span, - commitment: FriCommitment, - decommitment: FriDecommitment, + queries: Span, commitment: FriCommitment, decommitment: FriDecommitment, ) -> (FriVerificationStateConstant, FriVerificationStateVariable) { assert(queries.len() == decommitment.values.len(), 'Invalid value'); @@ -198,13 +194,13 @@ fn fri_verify_initial( n_layers: (commitment.config.n_layers - 1).try_into().unwrap(), commitment: commitment.inner_layers, eval_points: commitment.eval_points, - step_sizes: commitment.config.fri_step_sizes.slice(1, commitment.config.fri_step_sizes.len() - 1), + step_sizes: commitment + .config + .fri_step_sizes + .slice(1, commitment.config.fri_step_sizes.len() - 1), last_layer_coefficients_hash: hash_array(commitment.last_layer_coefficients), }, - FriVerificationStateVariable { - iter: 0, - queries: fri_queries.span(), - } + FriVerificationStateVariable { iter: 0, queries: fri_queries.span(), } ) } @@ -224,10 +220,10 @@ fn fri_verify_step( witness, ); - (stateConstant, FriVerificationStateVariable { - iter: stateVariable.iter + 1, - queries: queries.span(), - }) + ( + stateConstant, + FriVerificationStateVariable { iter: stateVariable.iter + 1, queries: queries.span(), } + ) } fn fri_verify_final( @@ -236,31 +232,31 @@ fn fri_verify_final( last_layer_coefficients: Span, ) -> (FriVerificationStateConstant, FriVerificationStateVariable) { assert(stateVariable.iter == stateConstant.n_layers, 'Fri final called at wrong time'); - assert(hash_array(last_layer_coefficients) == stateConstant.last_layer_coefficients_hash, 'Invalid last_layer_coefficients'); + assert( + hash_array(last_layer_coefficients) == stateConstant.last_layer_coefficients_hash, + 'Invalid last_layer_coefficients' + ); verify_last_layer(stateVariable.queries, last_layer_coefficients); - (stateConstant, FriVerificationStateVariable { - iter: stateVariable.iter + 1, - queries: array![].span(), - }) + ( + stateConstant, + FriVerificationStateVariable { iter: stateVariable.iter + 1, queries: array![].span(), } + ) } fn hash_array(mut array: Span) -> felt252 { let mut hash = PoseidonImpl::new(); loop { match array.pop_front() { - Option::Some(value) => { - hash = hash.update(*value); - }, - Option::None => { - break hash.finalize(); - } + Option::Some(value) => { hash = hash.update(*value); }, + Option::None => { break hash.finalize(); } } } } -// TODO: probably commitment can be moved to separate struct StateFinalize together with last_layer_coefficients +// TODO: probably commitment can be moved to separate struct StateFinalize together with +// last_layer_coefficients #[derive(Drop, Serde)] struct FriVerificationStateConstant { @@ -285,12 +281,11 @@ fn hash_constant(state: @FriVerificationStateConstant) -> felt252 { hash = hash.update(*value.config.vector.height); hash = hash.update(*value.config.vector.n_verifier_friendly_commitment_layers); hash = hash.update(*value.vector_commitment.config.height); - hash = hash.update(*value.vector_commitment.config.n_verifier_friendly_commitment_layers); + hash = hash + .update(*value.vector_commitment.config.n_verifier_friendly_commitment_layers); hash = hash.update(*value.vector_commitment.commitment_hash); }, - Option::None => { - break hash.finalize(); - } + Option::None => { break hash.finalize(); } } } } @@ -311,9 +306,7 @@ fn hash_variable(state: @FriVerificationStateVariable) -> felt252 { hash = hash.update(*query.y_value); hash = hash.update(*query.x_inv_value); }, - Option::None => { - break hash.finalize(); - } + Option::None => { break hash.finalize(); } } } -} \ No newline at end of file +} diff --git a/src/fri/fri_formula.cairo b/src/fri/fri_formula.cairo index 8ecbea891..03db68982 100644 --- a/src/fri/fri_formula.cairo +++ b/src/fri/fri_formula.cairo @@ -5,7 +5,8 @@ const OMEGA_8: felt252 = 0x446ed3ce295dda2b5ea677394813e6eab8bfbc55397aacac8e6df const OMEGA_4: felt252 = 0x1dafdc6d65d66b5accedf99bcd607383ad971a9537cdf25d59e99d90becc81e; const OMEGA_2: felt252 = 0x800000000000011000000000000000000000000000000000000000000000000; -// Function to fold 2 elements into one using one layer of FRI (Fast Reed-Solomon Interactive Oracle Proofs). +// Function to fold 2 elements into one using one layer of FRI (Fast Reed-Solomon Interactive Oracle +// Proofs). fn fri_formula2(f_x: felt252, f_minus_x: felt252, eval_point: felt252, x_inv: felt252) -> felt252 { f_x + f_minus_x + eval_point * x_inv * (f_x - f_minus_x) } diff --git a/src/fri/fri_layer.cairo b/src/fri/fri_layer.cairo index 3dfec4866..350dfe640 100644 --- a/src/fri/fri_layer.cairo +++ b/src/fri/fri_layer.cairo @@ -51,7 +51,8 @@ fn compute_coset_elements( coset_elements.append(query.y_value); coset_x_inv = query.x_inv_value * (*fri_group.at(i)); } else { - coset_elements.append(*sibling_witness.pop_front().expect('invalid sibling_withness length')); + coset_elements + .append(*sibling_witness.pop_front().expect('invalid sibling_withness length')); } i += 1; diff --git a/src/fri/tests/test_fri_verify.cairo b/src/fri/tests/test_fri_verify.cairo index 7db0df10f..0377399d2 100644 --- a/src/fri/tests/test_fri_verify.cairo +++ b/src/fri/tests/test_fri_verify.cairo @@ -12,7 +12,7 @@ fn test_fri_verify() { let _witness = stone_proof_fibonacci::fri::witness::get(); fri_verify_initial(queries, commitment, decommitment); - // TODO: next steps +// TODO: next steps } #[cfg(feature: 'keccak')] @@ -25,5 +25,5 @@ fn test_fri_verify() { let _witness = stone_proof_fibonacci_keccak::fri::witness::get(); fri_verify_initial(queries, commitment, decommitment); - // TODO: next steps +// TODO: next steps } diff --git a/src/lib.cairo b/src/lib.cairo index a41b745c3..57186ddec 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -21,6 +21,7 @@ use cairo_verifier::{ air::public_input::CairoVersion, deserialization::stark::StarkProofWithSerde, stark::{StarkProof, StarkProofImpl}, }; +use starknet::contract_address::ContractAddressZero; #[cfg(feature: 'dex')] use cairo_verifier::air::layouts::dex::public_input::DexPublicInputImpl as PublicInputImpl; @@ -43,7 +44,7 @@ fn main(mut serialized: Span, cairo_version: CairoVersion) -> (felt252, let stark_proof_serde = Serde::::deserialize(ref serialized).unwrap(); let stark_proof: StarkProof = stark_proof_serde.into(); - stark_proof.verify_full(SECURITY_BITS, 0.try_into().unwrap(), 0.try_into().unwrap()); + stark_proof.verify(SECURITY_BITS, ContractAddressZero::zero(), ContractAddressZero::zero()); let (program_hash, output_hash) = match cairo_version { CairoVersion::Cairo0 => stark_proof.public_input.verify_cairo0(), CairoVersion::Cairo1 => stark_proof.public_input.verify_cairo1(), diff --git a/src/oods.cairo b/src/oods.cairo index ef49a3c6b..2cbdaea38 100644 --- a/src/oods.cairo +++ b/src/oods.cairo @@ -1,6 +1,5 @@ use cairo_verifier::{ - common::array_extend::ArrayExtendTrait, - table_commitment::table_commitment::TableDecommitment + common::array_extend::ArrayExtendTrait, table_commitment::table_commitment::TableDecommitment }; use starknet::ContractAddress; #[cfg(feature: 'dex')] @@ -18,8 +17,8 @@ use cairo_verifier::air::layouts::recursive::{ #[cfg(feature: 'recursive_with_poseidon')] use cairo_verifier::air::layouts::recursive_with_poseidon::{ AIRComposition, AIROods, RecursiveWithPoseidonAIRCompositionImpl, - RecursiveWithPoseidonAIROodsImpl, global_values::InteractionElements, - public_input::PublicInput, traces::TracesDecommitment, constants::CONSTRAINT_DEGREE, + RecursiveWithPoseidonAIROodsImpl, global_values::InteractionElements, public_input::PublicInput, + traces::TracesDecommitment, constants::CONSTRAINT_DEGREE, }; #[cfg(feature: 'small')] use cairo_verifier::air::layouts::small::{ @@ -35,9 +34,9 @@ use cairo_verifier::air::layouts::starknet::{ }; #[cfg(feature: 'starknet_with_keccak')] use cairo_verifier::air::layouts::starknet_with_keccak::{ - AIRComposition, AIROods, StarknetWithKeccakAIRCompositionImpl, - StarknetWithKeccakAIROodsImpl, global_values::InteractionElements, - public_input::PublicInput, traces::TracesDecommitment, constants::CONSTRAINT_DEGREE, + AIRComposition, AIROods, StarknetWithKeccakAIRCompositionImpl, StarknetWithKeccakAIROodsImpl, + global_values::InteractionElements, public_input::PublicInput, traces::TracesDecommitment, + constants::CONSTRAINT_DEGREE, }; #[derive(Drop)] @@ -58,7 +57,7 @@ fn verify_oods( oods_point: felt252, trace_domain_size: felt252, trace_generator: felt252, - contract_address_1: ContractAddress, + contract_address: ContractAddress, ) { let composition_from_trace = AIRComposition::eval_composition_polynomial( interaction_elements, @@ -68,7 +67,7 @@ fn verify_oods( oods_point, trace_domain_size, trace_generator, - contract_address_1, + contract_address, ); // TODO support degree > 2? @@ -84,7 +83,7 @@ fn eval_oods_boundary_poly_at_points( points: Span, decommitment: TracesDecommitment, composition_decommitment: TableDecommitment, - contract_address_2: ContractAddress, + contract_address: ContractAddress, ) -> Array { assert( decommitment.original.values.len() == points.len() * n_original_columns, 'Invalid value' @@ -130,7 +129,7 @@ fn eval_oods_boundary_poly_at_points( *points.at(i), eval_info.oods_point, eval_info.trace_generator, - contract_address_2, + contract_address, ) ); diff --git a/src/stark.cairo b/src/stark.cairo index 1b81387ac..35b1e4d14 100644 --- a/src/stark.cairo +++ b/src/stark.cairo @@ -5,13 +5,14 @@ mod stark_verify; mod tests; use cairo_verifier::{ - air::{ - public_input::{PublicInput, get_public_input_hash}, - }, + air::{public_input::{PublicInput, get_public_input_hash},}, channel::channel::{Channel, ChannelImpl}, fri::{ fri_config::{FriConfig, FriConfigTrait}, - fri::{FriUnsentCommitment, FriWitness, FriCommitment, FriVerificationStateConstant, FriVerificationStateVariable, FriLayerWitness, fri_verify_step, fri_verify_final} + fri::{ + FriUnsentCommitment, FriWitness, FriCommitment, FriVerificationStateConstant, + FriVerificationStateVariable, FriLayerWitness, fri_verify_step, fri_verify_final + } }, queries::queries, domains::StarkDomainsImpl, table_commitment::table_commitment::{ @@ -38,8 +39,7 @@ use cairo_verifier::air::layouts::recursive::{ }; #[cfg(feature: 'recursive_with_poseidon')] use cairo_verifier::air::layouts::recursive_with_poseidon::{ - traces::{TracesConfig, TracesConfigTrait}, - public_input::RecursiveWithPoseidonPublicInputImpl, + traces::{TracesConfig, TracesConfigTrait}, public_input::RecursiveWithPoseidonPublicInputImpl, traces::{TracesUnsentCommitment, TracesCommitment, TracesDecommitment, TracesWitness}, constants::{NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND} }; @@ -57,8 +57,7 @@ use cairo_verifier::air::layouts::starknet::{ }; #[cfg(feature: 'starknet_with_keccak')] use cairo_verifier::air::layouts::starknet_with_keccak::{ - traces::{TracesConfig, TracesConfigTrait}, - public_input::StarknetWithKeccakPublicInputImpl, + traces::{TracesConfig, TracesConfigTrait}, public_input::StarknetWithKeccakPublicInputImpl, traces::{TracesUnsentCommitment, TracesCommitment, TracesDecommitment, TracesWitness}, constants::{NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND} }; @@ -73,7 +72,12 @@ struct StarkProof { #[generate_trait] impl StarkProofImpl of StarkProofTrait { - fn verify_initial(self: @StarkProof, security_bits: felt252, contract_address_1: ContractAddress, contract_address_2: ContractAddress) -> (FriVerificationStateConstant, FriVerificationStateVariable, Span) { + fn verify_initial( + self: @StarkProof, + security_bits: felt252, + composition_contract_address: ContractAddress, + oods_contract_address: ContractAddress + ) -> (FriVerificationStateConstant, FriVerificationStateVariable, Span) { // Validate config. self.config.validate(security_bits); @@ -90,7 +94,12 @@ impl StarkProofImpl of StarkProofTrait { // STARK commitment phase. let stark_commitment = stark_commit::stark_commit( - ref channel, self.public_input, self.unsent_commitment, self.config, @stark_domains, contract_address_1 + ref channel, + self.public_input, + self.unsent_commitment, + self.config, + @stark_domains, + composition_contract_address ); let last_layer_coefficients = stark_commitment.fri.last_layer_coefficients; @@ -110,7 +119,7 @@ impl StarkProofImpl of StarkProofTrait { stark_commitment, *self.witness, stark_domains, - contract_address_2 + oods_contract_address ); (con, var, last_layer_coefficients) } @@ -131,17 +140,25 @@ impl StarkProofImpl of StarkProofTrait { fri_verify_final(stateConstant, stateVariable, last_layer_coefficients) } - fn verify_full(self: @StarkProof, security_bits: felt252, contract_address_1: ContractAddress, contract_address_2: ContractAddress) { - let (mut con, mut var, last_layer_coefficients) = self.verify_initial(security_bits, contract_address_1, contract_address_2); - + fn verify( + self: @StarkProof, + security_bits: felt252, + composition_contract_address: ContractAddress, + oods_contract_address: ContractAddress + ) { + let (mut con, mut var, last_layer_coefficients) = self + .verify_initial(security_bits, composition_contract_address, oods_contract_address); + let n = con.n_layers; let mut i = 0; loop { if i == n { break; } - - let (new_con, new_var) = StarkProofTrait::verify_step(con, var, *(*self.witness.fri_witness.layers).at(i)); + + let (new_con, new_var) = StarkProofTrait::verify_step( + con, var, *(*self.witness.fri_witness.layers).at(i) + ); var = new_var; con = new_con; diff --git a/src/stark/stark_verify.cairo b/src/stark/stark_verify.cairo index 402ee03d6..223da6644 100644 --- a/src/stark/stark_verify.cairo +++ b/src/stark/stark_verify.cairo @@ -1,6 +1,9 @@ use cairo_verifier::{ queries::queries::queries_to_points, domains::StarkDomains, - fri::fri::{FriDecommitment, fri_verify_initial, FriVerificationStateConstant, FriVerificationStateVariable}, + fri::fri::{ + FriDecommitment, fri_verify_initial, FriVerificationStateConstant, + FriVerificationStateVariable + }, stark::{StarkUnsentCommitment, StarkWitness, StarkCommitment}, table_commitment::table_commitment::table_decommit, oods::{OodsEvaluationInfo, eval_oods_boundary_poly_at_points}, @@ -67,8 +70,6 @@ fn stark_verify( values: oods_poly_evals.span(), points: points.span(), }; fri_verify_initial( - queries: queries, - commitment: commitment.fri, - decommitment: fri_decommitment, + queries: queries, commitment: commitment.fri, decommitment: fri_decommitment, ) } diff --git a/src/stark/tests/test_stark_commit.cairo b/src/stark/tests/test_stark_commit.cairo index 2cf800a73..972960e85 100644 --- a/src/stark/tests/test_stark_commit.cairo +++ b/src/stark/tests/test_stark_commit.cairo @@ -18,7 +18,12 @@ fn test_stark_commit() { assert( stark_commit( - ref channel, @public_input, @unsent_commitment, @config, @stark_domains, 0.try_into().unwrap() + ref channel, + @public_input, + @unsent_commitment, + @config, + @stark_domains, + 0.try_into().unwrap() ) == stone_proof_fibonacci::stark::commitment::get(), 'Invalid value' ); @@ -45,7 +50,12 @@ fn test_stark_commit() { assert( stark_commit( - ref channel, @public_input, @unsent_commitment, @config, @stark_domains, 0.try_into().unwrap() + ref channel, + @public_input, + @unsent_commitment, + @config, + @stark_domains, + 0.try_into().unwrap() ) == stone_proof_fibonacci_keccak::stark::commitment::get(), 'Invalid value' ); diff --git a/src/stark/tests/test_stark_proof_verify.cairo b/src/stark/tests/test_stark_proof_verify.cairo index 7cec1fde2..22dc01a4d 100644 --- a/src/stark/tests/test_stark_proof_verify.cairo +++ b/src/stark/tests/test_stark_proof_verify.cairo @@ -33,5 +33,5 @@ fn test_stark_proof_fibonacci_verify() { }; stark_proof.verify_initial(security_bits, 0.try_into().unwrap(), 0.try_into().unwrap()); - // TODO: next steps +// TODO: next steps } diff --git a/src/stark/tests/test_stark_verify.cairo b/src/stark/tests/test_stark_verify.cairo index 911208e28..b95366fab 100644 --- a/src/stark/tests/test_stark_verify.cairo +++ b/src/stark/tests/test_stark_verify.cairo @@ -14,7 +14,13 @@ fn test_stark_verify() { let stark_domains = stone_proof_fibonacci::stark::domains::get(); stark_verify( - NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND, queries, commitment, witness, stark_domains, 0.try_into().unwrap() + NUM_COLUMNS_FIRST, + NUM_COLUMNS_SECOND, + queries, + commitment, + witness, + stark_domains, + 0.try_into().unwrap() ); } @@ -28,7 +34,13 @@ fn test_stark_verify() { let stark_domains = stone_proof_fibonacci_keccak::stark::domains::get(); stark_verify( - NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND, queries, commitment, witness, stark_domains, 0.try_into().unwrap() + NUM_COLUMNS_FIRST, + NUM_COLUMNS_SECOND, + queries, + commitment, + witness, + stark_domains, + 0.try_into().unwrap() ); - // TODO: next steps +// TODO: next steps } diff --git a/src/vector_commitment/vector_commitment.cairo b/src/vector_commitment/vector_commitment.cairo index 9d32485b5..5e1b9b7b1 100644 --- a/src/vector_commitment/vector_commitment.cairo +++ b/src/vector_commitment/vector_commitment.cairo @@ -28,8 +28,8 @@ impl VectorCommitmentConfigImpl of VectorCommitmentConfigTrait { n_verifier_friendly_commitment_layers: felt252, ) { assert(*self.height == expected_height, 'height mismatch'); - // Note that n_verifier_friendly_commitment_layers can be greater than height (in such a case, - // all Merkle layers use the verifier-friendly hash). + // Note that n_verifier_friendly_commitment_layers can be greater than height (in such a + // case, all Merkle layers use the verifier-friendly hash). assert( *self.n_verifier_friendly_commitment_layers == n_verifier_friendly_commitment_layers, 'n_verifier_friendly mismatch' diff --git a/src/verifier.cairo b/src/verifier.cairo index 30a81d345..fcbec15f6 100644 --- a/src/verifier.cairo +++ b/src/verifier.cairo @@ -1,4 +1,7 @@ -use cairo_verifier::{StarkProof, CairoVersion, StarkProofWithSerde, fri::fri::{FriLayerWitness, FriVerificationStateConstant, FriVerificationStateVariable}}; +use cairo_verifier::{ + StarkProof, CairoVersion, StarkProofWithSerde, + fri::fri::{FriLayerWitness, FriVerificationStateConstant, FriVerificationStateVariable} +}; #[derive(Drop, Serde)] struct InitResult { @@ -33,13 +36,7 @@ trait ICairoVerifier { job_id: felt252, state_constant: FriVerificationStateConstant, state_variable: FriVerificationStateVariable, - last_layer_coefficients: Span, - ) -> felt252; - - fn verify_proof_full( - ref self: TContractState, - stark_proof_serde: StarkProofWithSerde, - cairo_version: CairoVersion, + last_layer_coefficients: Span, ) -> felt252; } @@ -47,27 +44,32 @@ trait ICairoVerifier { mod CairoVerifier { use starknet::ContractAddress; use cairo_verifier::{ - CairoVersion, PublicInputImpl, StarkProofWithSerde, - stark::{StarkProof, StarkProofImpl}, - fri::fri::{FriLayerWitness, FriVerificationStateConstant, FriVerificationStateVariable, hash_constant, hash_variable}, + CairoVersion, PublicInputImpl, StarkProofWithSerde, stark::{StarkProof, StarkProofImpl}, + fri::fri::{ + FriLayerWitness, FriVerificationStateConstant, FriVerificationStateVariable, + hash_constant, hash_variable + }, }; use core::poseidon::{Poseidon, PoseidonImpl, HashStateImpl}; use super::{InitResult, ICairoVerifier}; #[storage] struct Storage { - contract_address_1: ContractAddress, - contract_address_2: ContractAddress, - + composition_contract_address: ContractAddress, + oods_contract_address: ContractAddress, state_constant: LegacyMap>, // job_id => hash(constant state) state_variable: LegacyMap>, // job_id => hash(variable state) - state_fact: LegacyMap>, // job_id => fact_hash + state_fact: LegacyMap>, // job_id => fact_hash } #[constructor] - fn constructor(ref self: ContractState, contract_address_1: ContractAddress, contract_address_2: ContractAddress) { - self.contract_address_1.write(contract_address_1); - self.contract_address_2.write(contract_address_2); + fn constructor( + ref self: ContractState, + composition_contract_address: ContractAddress, + oods_contract_address: ContractAddress + ) { + self.composition_contract_address.write(composition_contract_address); + self.oods_contract_address.write(oods_contract_address); } #[event] @@ -104,9 +106,12 @@ mod CairoVerifier { let fact = PoseidonImpl::new().update(program_hash).update(output_hash).finalize(); - let (con, var, last_layer_coefficients) = stark_proof.verify_initial( - SECURITY_BITS, self.contract_address_1.read(), self.contract_address_2.read() - ); + let (con, var, last_layer_coefficients) = stark_proof + .verify_initial( + SECURITY_BITS, + self.composition_contract_address.read(), + self.oods_contract_address.read() + ); self.state_constant.write(job_id, Option::Some(hash_constant(@con))); self.state_variable.write(job_id, Option::Some(hash_variable(@var))); self.state_fact.write(job_id, Option::Some(fact)); @@ -131,8 +136,20 @@ mod CairoVerifier { state_variable: FriVerificationStateVariable, witness: FriLayerWitness, ) -> (FriVerificationStateVariable, u32) { - assert(hash_constant(@state_constant) == self.state_constant.read(job_id).expect('No state (constant) saved'), 'Invalid state (constant)'); - assert(hash_variable(@state_variable) == self.state_variable.read(job_id).expect('No state (variable) saved'), 'Invalid state (variable)'); + assert( + hash_constant(@state_constant) == self + .state_constant + .read(job_id) + .expect('No state (constant) saved'), + 'Invalid state (constant)' + ); + assert( + hash_variable(@state_variable) == self + .state_variable + .read(job_id) + .expect('No state (variable) saved'), + 'Invalid state (variable)' + ); let (con, var) = StarkProofImpl::verify_step(state_constant, state_variable, witness); self.state_variable.write(job_id, Option::Some(hash_variable(@var))); @@ -149,11 +166,19 @@ mod CairoVerifier { state_variable: FriVerificationStateVariable, last_layer_coefficients: Span, ) -> felt252 { - assert(hash_constant(@state_constant) == self.state_constant.read(job_id).unwrap(), 'Invalid state (constant)'); - assert(hash_variable(@state_variable) == self.state_variable.read(job_id).unwrap(), 'Invalid state (variable)'); + assert( + hash_constant(@state_constant) == self.state_constant.read(job_id).unwrap(), + 'Invalid state (constant)' + ); + assert( + hash_variable(@state_variable) == self.state_variable.read(job_id).unwrap(), + 'Invalid state (variable)' + ); let fact = self.state_fact.read(job_id).expect('No fact saved'); - let (new_con, new_var) = StarkProofImpl::verify_final(state_constant, state_variable, last_layer_coefficients); + let (new_con, new_var) = StarkProofImpl::verify_final( + state_constant, state_variable, last_layer_coefficients + ); assert(new_var.iter.into() == new_con.n_layers + 1, 'Verification not finalized'); self.state_variable.write(job_id, Option::None); @@ -163,25 +188,5 @@ mod CairoVerifier { self.emit(ProofVerified { job_id, fact }); fact } - - fn verify_proof_full( - ref self: ContractState, - stark_proof_serde: StarkProofWithSerde, - cairo_version: CairoVersion, - ) -> felt252 { - let stark_proof: StarkProof = stark_proof_serde.into(); - let (program_hash, output_hash) = match cairo_version { - CairoVersion::Cairo0 => stark_proof.public_input.verify_cairo0(), - CairoVersion::Cairo1 => stark_proof.public_input.verify_cairo1(), - }; - stark_proof.verify_full( - SECURITY_BITS, self.contract_address_1.read(), self.contract_address_2.read() - ); - - let fact = PoseidonImpl::new().update(program_hash).update(output_hash).finalize(); - - self.emit(ProofVerified { job_id: 0, fact }); - fact - } } } From c36fa389848326882ed4495f12db7c6045f24ba7 Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Tue, 10 Sep 2024 12:44:07 +0200 Subject: [PATCH 2/2] rm old fact registry --- fact_registry/.gitignore | 2 - fact_registry/Scarb.toml | 13 -- fact_registry/snfoundry.toml | 4 - fact_registry/src/fact_registry.cairo | 228 -------------------------- fact_registry/src/lib.cairo | 1 - 5 files changed, 248 deletions(-) delete mode 100644 fact_registry/.gitignore delete mode 100644 fact_registry/Scarb.toml delete mode 100644 fact_registry/snfoundry.toml delete mode 100644 fact_registry/src/fact_registry.cairo delete mode 100644 fact_registry/src/lib.cairo diff --git a/fact_registry/.gitignore b/fact_registry/.gitignore deleted file mode 100644 index 73aa31e60..000000000 --- a/fact_registry/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -target -.snfoundry_cache/ diff --git a/fact_registry/Scarb.toml b/fact_registry/Scarb.toml deleted file mode 100644 index 8745f2bf5..000000000 --- a/fact_registry/Scarb.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "fact_registry" -version = "0.1.0" -edition = "2023_10" - -# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html - -[dependencies] -cairo_verifier = { path = ".." } -snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.24.0" } - -[[target.starknet-contract]] -casm = true \ No newline at end of file diff --git a/fact_registry/snfoundry.toml b/fact_registry/snfoundry.toml deleted file mode 100644 index 96b5143d4..000000000 --- a/fact_registry/snfoundry.toml +++ /dev/null @@ -1,4 +0,0 @@ -[sncast.testnet] -account = "testnet-sepolia" -accounts-file = "~/.starknet_accounts/starknet_open_zeppelin_accounts.json" -url = "https://free-rpc.nethermind.io/sepolia-juno/v0_7" \ No newline at end of file diff --git a/fact_registry/src/fact_registry.cairo b/fact_registry/src/fact_registry.cairo deleted file mode 100644 index d573d34ed..000000000 --- a/fact_registry/src/fact_registry.cairo +++ /dev/null @@ -1,228 +0,0 @@ -use cairo_verifier::{ - StarkProofWithSerde, CairoVersion, - fri::fri::{FriLayerWitness, FriVerificationStateConstant, FriVerificationStateVariable}, - verifier::InitResult, -}; -use starknet::ContractAddress; - -#[derive(Drop, Copy, Serde)] -struct VerifierSettings { - layout: felt252, - hasher: felt252, - version: felt252, -} - -#[starknet::interface] -trait IFactRegistry { - fn verify_proof_full_and_register_fact( - ref self: TContractState, - stark_proof: StarkProofWithSerde, - cairo_version: CairoVersion, - settings: VerifierSettings, - ); - - fn verify_proof_initial( - self: @TContractState, - job_id: felt252, - stark_proof_serde: StarkProofWithSerde, - cairo_version: CairoVersion, - settings: VerifierSettings, - ) -> InitResult; - - fn verify_proof_step( - self: @TContractState, - job_id: felt252, - state_constant: FriVerificationStateConstant, - state_variable: FriVerificationStateVariable, - witness: FriLayerWitness, - settings: VerifierSettings, - ) -> (FriVerificationStateVariable, u32); - - fn verify_proof_final_and_register_fact( - ref self: TContractState, - job_id: felt252, - state_constant: FriVerificationStateConstant, - state_variable: FriVerificationStateVariable, - last_layer_coefficients: Span, - settings: VerifierSettings, - ); - - fn is_valid(self: @TContractState, fact: felt252) -> bool; - fn get_verifier_address(self: @TContractState, settings: VerifierSettings) -> ContractAddress; - fn register_verifier( - ref self: TContractState, settings: VerifierSettings, address: ContractAddress - ); - fn transfer_ownership(ref self: TContractState, new_owner: ContractAddress); -} -// #[starknet::contract] -// mod FactRegistry { -// use cairo_verifier::{ -// StarkProofWithSerde, StarkProof, CairoVersion, -// fri::fri::{FriLayerWitness, FriVerificationStateConstant, FriVerificationStateVariable}, -// }; -// use starknet::{ContractAddress, get_caller_address}; -// use core::{ -// poseidon::{Poseidon, PoseidonImpl, HashStateImpl}, keccak::keccak_u256s_be_inputs, -// starknet::event::EventEmitter -// }; -// use fact_registry::verifier::{ -// InitResult, ICairoVerifierDispatcher, ICairoVerifierDispatcherTrait -// }; -// use super::{VerifierSettings, IFactRegistry}; - -// #[storage] -// struct Storage { -// owner: ContractAddress, -// verifiers: LegacyMap, -// facts: LegacyMap, -// } - -// #[event] -// #[derive(Drop, starknet::Event)] -// enum Event { -// FactRegistered: FactRegistered, -// OwnershipTransferred: OwnershipTransferred, -// VerifierRegistered: VerifierRegistered, -// } - -// #[derive(Drop, starknet::Event)] -// struct FactRegistered { -// #[key] -// fact: felt252, -// #[key] -// verifier_address: ContractAddress, -// } - -// #[derive(Drop, starknet::Event)] -// struct VerifierRegistered { -// #[key] -// settings: VerifierSettings, -// #[key] -// address: ContractAddress, -// } - -// #[derive(Drop, starknet::Event)] -// struct OwnershipTransferred { -// previous_owner: ContractAddress, -// new_owner: ContractAddress -// } - -// #[constructor] -// fn constructor(ref self: ContractState, owner: ContractAddress) { -// self.owner.write(owner); -// } - -// #[abi(embed_v0)] -// impl FactRegistryImpl of IFactRegistry { -// fn verify_proof_full_and_register_fact( -// ref self: ContractState, -// stark_proof: StarkProofWithSerde, -// cairo_version: CairoVersion, -// settings: VerifierSettings, -// ) { -// let verifier_address = self.get_verifier_address(settings); -// let (fact, security_bits) = ICairoVerifierDispatcher { -// contract_address: verifier_address -// }.verify_proof_full(stark_proof.into(), cairo_version); - -// self.emit(Event::FactRegistered(FactRegistered { fact, verifier_address, -// security_bits })); -// self.facts.write(fact, true); -// } - -// fn verify_proof_initial( -// self: @ContractState, -// job_id: felt252, -// stark_proof_serde: StarkProofWithSerde, -// cairo_version: CairoVersion, -// settings: VerifierSettings, -// ) -> InitResult { -// ICairoVerifierDispatcher { -// contract_address: self.get_verifier_address(settings) -// }.verify_proof_initial(job_id, stark_proof_serde, cairo_version) -// } - -// fn verify_proof_step( -// self: @ContractState, -// job_id: felt252, -// state_constant: FriVerificationStateConstant, -// state_variable: FriVerificationStateVariable, -// witness: FriLayerWitness, -// settings: VerifierSettings, -// ) -> (FriVerificationStateVariable, u32) { -// ICairoVerifierDispatcher { -// contract_address: self.get_verifier_address(settings) -// }.verify_proof_step(job_id, state_constant, state_variable, witness) -// } - -// fn verify_proof_final_and_register_fact( -// ref self: ContractState, -// job_id: felt252, -// state_constant: FriVerificationStateConstant, -// state_variable: FriVerificationStateVariable, -// last_layer_coefficients: Span, -// settings: VerifierSettings, -// ) { -// let verifier_address = self.get_verifier_address(settings); -// assert(verifier_address.into() != 0, 'VERIFIER_NOT_FOUND'); -// let (fact, security_bits) = ICairoVerifierDispatcher { -// contract_address: verifier_address -// }.verify_proof_final(job_id, state_constant, state_variable, -// last_layer_coefficients); - -// self.emit(Event::FactRegistered(FactRegistered { fact, verifier_address, -// security_bits })); -// self.facts.write(fact, true); -// } - -// fn is_valid(self: @ContractState, fact: felt252) -> bool { -// self.facts.read(fact) -// } - -// fn get_verifier_address(self: @ContractState, settings: VerifierSettings) -> -// ContractAddress { -// let verifier_address = self.verifiers.read(self._hash_settings(settings)); -// assert(verifier_address.into() != 0, 'VERIFIER_NOT_FOUND'); -// verifier_address -// } - -// fn register_verifier(ref self: ContractState, settings: VerifierSettings, address: -// ContractAddress) { -// assert(self.owner.read() == get_caller_address(), 'ONLY_OWNER'); -// assert(address.into() != 0, 'INVALID_VERIFIER_ADDRESS'); -// let settings_hash = self._hash_settings(settings); -// assert(self.verifiers.read(settings_hash).into() == 0, 'VERIFIER_ALREADY_EXISTS'); -// self.verifiers.write(settings_hash, address); -// self.emit(Event::VerifierRegistered(VerifierRegistered { -// settings, address -// })); -// } - -// fn transfer_ownership(ref self: ContractState, new_owner: ContractAddress) { -// let caller = get_caller_address(); -// assert(self.owner.read() == caller, 'ONLY_OWNER'); -// self.owner.write(new_owner); - -// self -// .emit( -// Event::OwnershipTransferred( -// OwnershipTransferred { previous_owner: caller, new_owner } -// ) -// ); -// } -// } - -// #[generate_trait] -// impl InternalFactRegistry of InternalFactRegistryTrait { -// fn _hash_settings(self: @ContractState, settings: VerifierSettings) -> felt252 { -// PoseidonImpl::new() -// .update(settings.layout) -// .update(settings.hasher) -// .update(settings.security_bits) -// .update(settings.version) -// .finalize() -// } -// } -// } - - diff --git a/fact_registry/src/lib.cairo b/fact_registry/src/lib.cairo deleted file mode 100644 index 60fc0ac05..000000000 --- a/fact_registry/src/lib.cairo +++ /dev/null @@ -1 +0,0 @@ -mod fact_registry;