Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fmkra committed Aug 15, 2024
1 parent 8006068 commit 9a52c12
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 86 deletions.
4 changes: 2 additions & 2 deletions deploy/starknet_with_keccak.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ unique = false

[[call]]
call_type = "deploy"
class_hash = "0x07a34aa6757602c2aab48861849df5b9fb6be39e6a625e9fdefe1d470e1425aa"
class_hash = "0x60ed97da980fb6610abdc7117ff62b0156b02008fd8289bce76d5c3e2c045e3"
inputs = ["0x7", "contract_1_part_1", "contract_1_part_2", "contract_1_part_3", "contract_1_part_4", "contract_1_part_5", "contract_1_part_6", "contract_1_part_7"]
id = "contract_1"
unique = false
Expand All @@ -70,7 +70,7 @@ unique = false

[[call]]
call_type = "deploy"
class_hash = "0x14a87df70bd5abca9fb1c0483017dfe1c78e14144a9ccfa40acd916e9290dbb"
class_hash = "0x4e32e70b5dba55e305238b95f9b44e47930d742163dd689b08dd610a5b07694"
inputs = ["contract_2_part1", "contract_2_part2"]
id = "contract_2"
unique = false
Expand Down
154 changes: 77 additions & 77 deletions fact_registry/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,90 +1,90 @@
mod verifier;

use cairo_verifier::{StarkProofWithSerde, CairoVersion};
use starknet::ContractAddress;
// use cairo_verifier::{StarkProofWithSerde, CairoVersion};
// use starknet::ContractAddress;

#[starknet::interface]
trait IFactRegistry<TContractState> {
fn verify_and_register_fact(
ref self: TContractState, stark_proof: StarkProofWithSerde, cairo_version: CairoVersion
);
fn verify_and_register_fact_from_contract(
ref self: TContractState, contract_address: ContractAddress
);
fn is_valid(self: @TContractState, fact: felt252) -> bool;
}
// #[starknet::interface]
// trait IFactRegistry<TContractState> {
// fn verify_and_register_fact(
// ref self: TContractState, stark_proof: StarkProofWithSerde, cairo_version: CairoVersion
// );
// fn verify_and_register_fact_from_contract(
// ref self: TContractState, contract_address: ContractAddress
// );
// fn is_valid(self: @TContractState, fact: felt252) -> bool;
// }

#[starknet::interface]
trait ISmartProof<TContractState> {
fn get_proof(self: @TContractState) -> (Array<felt252>, CairoVersion);
}
// #[starknet::interface]
// trait ISmartProof<TContractState> {
// fn get_proof(self: @TContractState) -> (Array<felt252>, CairoVersion);
// }

#[starknet::contract]
mod FactRegistry {
use cairo_verifier::{StarkProofWithSerde, CairoVersion};
use starknet::ContractAddress;
use core::{
poseidon::{Poseidon, PoseidonImpl, HashStateImpl}, keccak::keccak_u256s_be_inputs,
starknet::event::EventEmitter
};
use fact_registry::{verifier::{CairoVerifier, ICairoVerifier, StarkProof}, IFactRegistry};
use super::{ISmartProofDispatcher, ISmartProofDispatcherTrait};
// #[starknet::contract]
// mod FactRegistry {
// use cairo_verifier::{StarkProofWithSerde, CairoVersion};
// use starknet::ContractAddress;
// use core::{
// poseidon::{Poseidon, PoseidonImpl, HashStateImpl}, keccak::keccak_u256s_be_inputs,
// starknet::event::EventEmitter
// };
// use fact_registry::{verifier::{CairoVerifier, ICairoVerifier, StarkProof}, IFactRegistry};
// use super::{ISmartProofDispatcher, ISmartProofDispatcherTrait};

component!(path: CairoVerifier, storage: cairo_verifier, event: CairoVerifierEvent);
// component!(path: CairoVerifier, storage: cairo_verifier, event: CairoVerifierEvent);

#[storage]
struct Storage {
#[substorage(v0)]
cairo_verifier: CairoVerifier::Storage,
facts: LegacyMap<felt252, bool>,
}
// #[storage]
// struct Storage {
// #[substorage(v0)]
// cairo_verifier: CairoVerifier::Storage,
// facts: LegacyMap<felt252, bool>,
// }

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
#[flat]
CairoVerifierEvent: CairoVerifier::Event,
FactRegistered: FactRegistered,
}
// #[event]
// #[derive(Drop, starknet::Event)]
// enum Event {
// #[flat]
// CairoVerifierEvent: CairoVerifier::Event,
// FactRegistered: FactRegistered,
// }

#[derive(Drop, starknet::Event)]
struct FactRegistered {
#[key]
fact: felt252,
}
// #[derive(Drop, starknet::Event)]
// struct FactRegistered {
// #[key]
// fact: felt252,
// }

#[abi(embed_v0)]
impl FactRegistryImpl of IFactRegistry<ContractState> {
fn verify_and_register_fact(
ref self: ContractState, stark_proof: StarkProofWithSerde, cairo_version: CairoVersion
) {
let (program_hash, output_hash) = self
.cairo_verifier
.verify_proof(stark_proof.into(), cairo_version);
self._register_fact(program_hash, output_hash);
}
// #[abi(embed_v0)]
// impl FactRegistryImpl of IFactRegistry<ContractState> {
// fn verify_and_register_fact(
// ref self: ContractState, stark_proof: StarkProofWithSerde, cairo_version: CairoVersion
// ) {
// let (program_hash, output_hash) = self
// .cairo_verifier
// .verify_proof(stark_proof.into(), cairo_version);
// self._register_fact(program_hash, output_hash);
// }

fn verify_and_register_fact_from_contract(
ref self: ContractState, contract_address: ContractAddress
) {
let (proof_array, cairo_version) = ISmartProofDispatcher { contract_address }
.get_proof();
let mut proof_array = proof_array.span();
let proof = Serde::<StarkProofWithSerde>::deserialize(ref proof_array).unwrap();
self.verify_and_register_fact(proof, cairo_version);
}
// fn verify_and_register_fact_from_contract(
// ref self: ContractState, contract_address: ContractAddress
// ) {
// let (proof_array, cairo_version) = ISmartProofDispatcher { contract_address }
// .get_proof();
// let mut proof_array = proof_array.span();
// let proof = Serde::<StarkProofWithSerde>::deserialize(ref proof_array).unwrap();
// self.verify_and_register_fact(proof, cairo_version);
// }

fn is_valid(self: @ContractState, fact: felt252) -> bool {
self.facts.read(fact)
}
}
// fn is_valid(self: @ContractState, fact: felt252) -> bool {
// self.facts.read(fact)
// }
// }

#[generate_trait]
impl InternalFactRegistry of InternalFactRegistryTrait {
fn _register_fact(ref self: ContractState, program_hash: felt252, output_hash: felt252,) {
let fact = PoseidonImpl::new().update(program_hash).update(output_hash).finalize();
self.emit(Event::FactRegistered(FactRegistered { fact }));
self.facts.write(fact, true);
}
}
}
// #[generate_trait]
// impl InternalFactRegistry of InternalFactRegistryTrait {
// fn _register_fact(ref self: ContractState, program_hash: felt252, output_hash: felt252,) {
// let fact = PoseidonImpl::new().update(program_hash).update(output_hash).finalize();
// self.emit(Event::FactRegistered(FactRegistered { fact }));
// self.facts.write(fact, true);
// }
// }
// }
14 changes: 7 additions & 7 deletions src/air/layouts/starknet_with_keccak/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ trait IStarknetWithKeccakLayoutContract1parts<ContractState> {
#[starknet::interface]
trait IStarknetWithKeccakLayoutContract1<ContractState> {
fn eval_composition_polynomial_inner(
self: @ContractState,
ref self: ContractState,
mask_values: Span<felt252>,
constraint_coefficients: Span<felt252>,
point: felt252,
Expand Down Expand Up @@ -50,7 +50,7 @@ trait IStarknetWithKeccakLayoutContract2parts<ContractState> {
#[starknet::interface]
trait IStarknetWithKeccakLayoutContract2<ContractState> {
fn eval_oods_polynomial_inner(
self: @ContractState,
ref self: ContractState,
column_values: Span<felt252>,
oods_values: Span<felt252>,
constraint_coefficients: Span<felt252>,
Expand Down Expand Up @@ -152,7 +152,7 @@ mod StarknetWithKeccakLayoutContract1 {
}

fn eval_composition_polynomial_inner(
self: @ContractState,
ref self: ContractState,
mask_values: Span<felt252>,
constraint_coefficients: Span<felt252>,
point: felt252,
Expand All @@ -162,7 +162,7 @@ mod StarknetWithKeccakLayoutContract1 {
let hash = self._hash(mask_values, constraint_coefficients, point, trace_generator, global_values);
let mut result = self.registered.read(hash);
if result.is_none() {
register_evaluation(mask_values, constraint_coefficients, point, trace_generator, global_values);
self.register_evaluation(mask_values, constraint_coefficients, point, trace_generator, global_values);
result = self.registered.read(hash);
}
result.unwrap()
Expand Down Expand Up @@ -601,7 +601,7 @@ mod StarknetWithKeccakLayoutContract2 {
}

fn eval_oods_polynomial_inner(
self: @ContractState,
ref self: ContractState,
column_values: Span<felt252>,
oods_values: Span<felt252>,
constraint_coefficients: Span<felt252>,
Expand All @@ -612,8 +612,8 @@ mod StarknetWithKeccakLayoutContract2 {
let hash = self._hash(column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator);
let mut result = self.registered.read(hash);
if result.is_none() {
register_evaluation(column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator);
result = self.registered.read(hash);
self.register_evaluation(column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator);
result = self.registered.read(hash);
}
result.unwrap()
}
Expand Down

0 comments on commit 9a52c12

Please sign in to comment.