From 9a52c12cb9a945f3451a9727165b99d43248a922 Mon Sep 17 00:00:00 2001 From: Filip Krawczyk Date: Thu, 15 Aug 2024 10:13:52 +0200 Subject: [PATCH] Fixes --- deploy/starknet_with_keccak.toml | 4 +- fact_registry/src/lib.cairo | 154 +++++++++--------- .../starknet_with_keccak/contract.cairo | 14 +- 3 files changed, 86 insertions(+), 86 deletions(-) diff --git a/deploy/starknet_with_keccak.toml b/deploy/starknet_with_keccak.toml index 7c893afcf..3e9a0b6ac 100644 --- a/deploy/starknet_with_keccak.toml +++ b/deploy/starknet_with_keccak.toml @@ -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 @@ -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 diff --git a/fact_registry/src/lib.cairo b/fact_registry/src/lib.cairo index f1155b1c7..40e42761a 100644 --- a/fact_registry/src/lib.cairo +++ b/fact_registry/src/lib.cairo @@ -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 { - 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 { +// 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 { - fn get_proof(self: @TContractState) -> (Array, CairoVersion); -} +// #[starknet::interface] +// trait ISmartProof { +// fn get_proof(self: @TContractState) -> (Array, 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, - } +// #[storage] +// struct Storage { +// #[substorage(v0)] +// cairo_verifier: CairoVerifier::Storage, +// facts: LegacyMap, +// } - #[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 { - 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 { +// 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::::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::::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); +// } +// } +// } diff --git a/src/air/layouts/starknet_with_keccak/contract.cairo b/src/air/layouts/starknet_with_keccak/contract.cairo index 8d1266317..4fdf758d4 100644 --- a/src/air/layouts/starknet_with_keccak/contract.cairo +++ b/src/air/layouts/starknet_with_keccak/contract.cairo @@ -16,7 +16,7 @@ trait IStarknetWithKeccakLayoutContract1parts { #[starknet::interface] trait IStarknetWithKeccakLayoutContract1 { fn eval_composition_polynomial_inner( - self: @ContractState, + ref self: ContractState, mask_values: Span, constraint_coefficients: Span, point: felt252, @@ -50,7 +50,7 @@ trait IStarknetWithKeccakLayoutContract2parts { #[starknet::interface] trait IStarknetWithKeccakLayoutContract2 { fn eval_oods_polynomial_inner( - self: @ContractState, + ref self: ContractState, column_values: Span, oods_values: Span, constraint_coefficients: Span, @@ -152,7 +152,7 @@ mod StarknetWithKeccakLayoutContract1 { } fn eval_composition_polynomial_inner( - self: @ContractState, + ref self: ContractState, mask_values: Span, constraint_coefficients: Span, point: felt252, @@ -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() @@ -601,7 +601,7 @@ mod StarknetWithKeccakLayoutContract2 { } fn eval_oods_polynomial_inner( - self: @ContractState, + ref self: ContractState, column_values: Span, oods_values: Span, constraint_coefficients: Span, @@ -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() }