Skip to content
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

contract split refactor #147

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions fact_registry/src/fact_registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ trait IFactRegistry<TContractState> {
job_id: felt252,
state_constant: FriVerificationStateConstant,
state_variable: FriVerificationStateVariable,
last_layer_coefficients: Span<felt252>,
last_layer_coefficients: Span<felt252>,
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 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::{
Expand Down Expand Up @@ -124,7 +125,8 @@ trait IFactRegistry<TContractState> {
// contract_address: verifier_address
// }.verify_proof_full(stark_proof.into(), cairo_version);

// self.emit(Event::FactRegistered(FactRegistered { fact, verifier_address, security_bits }));
// self.emit(Event::FactRegistered(FactRegistered { fact, verifier_address,
// security_bits }));
// self.facts.write(fact, true);
// }

Expand Down Expand Up @@ -165,23 +167,27 @@ trait IFactRegistry<TContractState> {
// 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);
// }.verify_proof_final(job_id, state_constant, state_variable,
// last_layer_coefficients);

// self.emit(Event::FactRegistered(FactRegistered { fact, verifier_address, security_bits }));
// 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 {
// 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) {
// 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);
Expand Down Expand Up @@ -217,4 +223,6 @@ trait IFactRegistry<TContractState> {
// .finalize()
// }
// }
// }
// }


2 changes: 1 addition & 1 deletion fact_registry/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod fact_registry;
mod fact_registry;
4 changes: 2 additions & 2 deletions src/air/air.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trait AIRComposition<IE, PI> {
point: felt252,
trace_domain_size: felt252,
trace_generator: felt252,
contract_address_1: ContractAddress,
contract_address: ContractAddress,
) -> felt252;
}

Expand All @@ -21,6 +21,6 @@ trait AIROods {
point: felt252,
oods_point: felt252,
trace_generator: felt252,
contract_address_2: ContractAddress,
contract_address: ContractAddress,
) -> felt252;
}
74 changes: 42 additions & 32 deletions src/air/layouts/dex.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -24,78 +24,77 @@ 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<felt252>,
constraint_coefficients: Span<felt252>,
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<felt252>,
oods_values: Span<felt252>,
constraint_coefficients: Span<felt252>,
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<felt252>,
constraint_coefficients: Span<felt252>,
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<felt252>,
oods_values: Span<felt252>,
constraint_coefficients: Span<felt252>,
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<InteractionElements, PublicInput> {
Expand All @@ -107,7 +106,7 @@ impl DexAIRCompositionImpl of AIRComposition<InteractionElements, PublicInput> {
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;
Expand Down Expand Up @@ -166,7 +165,12 @@ impl DexAIRCompositionImpl of AIRComposition<InteractionElements, PublicInput> {
};

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,
)
}
}
Expand All @@ -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,
)
}
}
30 changes: 12 additions & 18 deletions src/air/layouts/dex/contract.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cairo_verifier::air::layouts::dex::global_values::GlobalValues;

#[starknet::interface]
trait IDexLayoutContract1<ContractState> {
trait ILayoutCompositionContract<ContractState> {
fn eval_composition_polynomial_inner(
self: @ContractState,
mask_values: Span<felt252>,
Expand All @@ -13,7 +13,7 @@ trait IDexLayoutContract1<ContractState> {
}

#[starknet::interface]
trait IDexLayoutContract2<ContractState> {
trait ILayoutOodsContract<ContractState> {
fn eval_oods_polynomial_inner(
self: @ContractState,
column_values: Span<felt252>,
Expand All @@ -26,18 +26,17 @@ trait IDexLayoutContract2<ContractState> {
}

#[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<ContractState> {
impl LayoutCompositionContract of ILayoutCompositionContract<ContractState> {
fn eval_composition_polynomial_inner(
self: @ContractState,
mask_values: Span<felt252>,
Expand All @@ -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<ContractState> {
impl LayoutOodsContract of ILayoutOodsContract<ContractState> {
fn eval_oods_polynomial_inner(
self: @ContractState,
column_values: Span<felt252>,
Expand All @@ -89,4 +83,4 @@ mod DexLayoutContract2 {
)
}
}
}
}
Loading
Loading