From a9bab39452d9abddda1c474f9f76e2014c8365cf Mon Sep 17 00:00:00 2001 From: Filip Krawczyk Date: Wed, 11 Sep 2024 00:09:42 +0200 Subject: [PATCH] Add get_verification method --- src/fact_registry.cairo | 34 ++++++++++++++++++++++++---------- src/proxy.cairo | 19 ++++++++++--------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/fact_registry.cairo b/src/fact_registry.cairo index d56051ae..eac66340 100644 --- a/src/fact_registry.cairo +++ b/src/fact_registry.cairo @@ -22,12 +22,19 @@ fn settings_from_struct(settings: VerifierSettings) -> (felt252, felt252, felt25 } #[derive(Drop, Copy, Serde)] -struct Verification { +struct VerificationListElement { verification_hash: felt252, security_bits: u32, settings: VerifierSettings, } +#[derive(Drop, Copy, Serde)] +struct Verification { + fact_hash: felt252, + security_bits: u32, + settings: VerifierSettings, +} + #[derive(Drop, Copy, Serde, starknet::Event)] struct FactRegistered { #[key] @@ -79,8 +86,8 @@ trait IFactRegistry { fn get_all_verifications_for_fact_hash( self: @TContractState, fact_hash: felt252 - ) -> Array; - fn is_verification_hash_registered(self: @TContractState, verification_hash: felt252) -> bool; + ) -> Array; + fn get_verification(self: @TContractState, verification_hash: felt252) -> Option; fn get_verifier_address(self: @TContractState, settings: VerifierSettings) -> ContractAddress; fn register_verifier( @@ -102,8 +109,8 @@ mod FactRegistry { starknet::event::EventEmitter }; use super::{ - VerifierSettings, Verification, IFactRegistry, FactRegistered, settings_from_struct, - settings_to_struct + VerifierSettings, VerificationListElement, Verification, IFactRegistry, FactRegistered, + settings_from_struct, settings_to_struct }; #[storage] @@ -208,7 +215,7 @@ mod FactRegistry { fn get_all_verifications_for_fact_hash( self: @ContractState, fact_hash: felt252 - ) -> Array { + ) -> Array { let n = self.facts.read(fact_hash); let mut i = 0; let mut arr = array![]; @@ -222,16 +229,23 @@ mod FactRegistry { .read(verification_hash) .unwrap(); let settings = settings_to_struct(settings_tuple); - arr.append(Verification { verification_hash, security_bits, settings }); + arr.append(VerificationListElement { verification_hash, security_bits, settings }); i += 1; }; arr } - fn is_verification_hash_registered( + fn get_verification( self: @ContractState, verification_hash: felt252 - ) -> bool { - self.verification_hashes.read(verification_hash).is_some() + ) -> Option { + match self.verification_hashes.read(verification_hash) { + Option::Some(x) => { + let (fact_hash, security_bits, settings_tuple) = x; + let settings = settings_to_struct(settings_tuple); + Option::Some(Verification { fact_hash, security_bits, settings }) + }, + Option::None => { Option::None } + } } fn get_verifier_address( diff --git a/src/proxy.cairo b/src/proxy.cairo index da72b1e6..6fbfd93f 100644 --- a/src/proxy.cairo +++ b/src/proxy.cairo @@ -1,7 +1,8 @@ use cairo_verifier::{ StarkProofWithSerde, CairoVersion, fri::fri::{FriLayerWitness, FriVerificationStateConstant, FriVerificationStateVariable}, - verifier::InitResult, fact_registry::{FactRegistered, VerifierSettings, Verification}, + verifier::InitResult, + fact_registry::{FactRegistered, VerifierSettings, VerificationListElement, Verification}, }; use starknet::{ContractAddress, ClassHash}; @@ -51,8 +52,8 @@ trait IProxy { fn get_all_verifications_for_fact_hash( self: @TContractState, fact_hash: felt252 - ) -> Array; - fn is_verification_hash_registered(self: @TContractState, verification_hash: felt252) -> bool; + ) -> Array; + fn get_verification(self: @TContractState, verification_hash: felt252) -> Option; fn get_verifier_address(self: @TContractState, settings: VerifierSettings) -> ContractAddress; fn register_verifier( @@ -81,8 +82,8 @@ mod Proxy { starknet::event::EventEmitter }; use super::{ - VerifierSettings, Verification, IProxy, FactRegistered, settings_from_struct, - settings_to_struct + VerifierSettings, VerificationListElement, Verification, IProxy, FactRegistered, + settings_from_struct, settings_to_struct }; #[event] @@ -161,16 +162,16 @@ mod Proxy { fn get_all_verifications_for_fact_hash( self: @ContractState, fact_hash: felt252 - ) -> Array { + ) -> Array { IFactRegistryDispatcher { contract_address: self.fact_registry.read() } .get_all_verifications_for_fact_hash(fact_hash) } - fn is_verification_hash_registered( + fn get_verification( self: @ContractState, verification_hash: felt252 - ) -> bool { + ) -> Option { IFactRegistryDispatcher { contract_address: self.fact_registry.read() } - .is_verification_hash_registered(verification_hash) + .get_verification(verification_hash) } fn get_verifier_address(