Skip to content

Commit

Permalink
Add get_verification method
Browse files Browse the repository at this point in the history
  • Loading branch information
fmkra committed Sep 10, 2024
1 parent 1681392 commit a9bab39
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
34 changes: 24 additions & 10 deletions src/fact_registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -79,8 +86,8 @@ trait IFactRegistry<TContractState> {

fn get_all_verifications_for_fact_hash(
self: @TContractState, fact_hash: felt252
) -> Array<Verification>;
fn is_verification_hash_registered(self: @TContractState, verification_hash: felt252) -> bool;
) -> Array<VerificationListElement>;
fn get_verification(self: @TContractState, verification_hash: felt252) -> Option<Verification>;

fn get_verifier_address(self: @TContractState, settings: VerifierSettings) -> ContractAddress;
fn register_verifier(
Expand All @@ -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]
Expand Down Expand Up @@ -208,7 +215,7 @@ mod FactRegistry {

fn get_all_verifications_for_fact_hash(
self: @ContractState, fact_hash: felt252
) -> Array<Verification> {
) -> Array<VerificationListElement> {
let n = self.facts.read(fact_hash);
let mut i = 0;
let mut arr = array![];
Expand All @@ -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<Verification> {
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(
Expand Down
19 changes: 10 additions & 9 deletions src/proxy.cairo
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -51,8 +52,8 @@ trait IProxy<TContractState> {

fn get_all_verifications_for_fact_hash(
self: @TContractState, fact_hash: felt252
) -> Array<Verification>;
fn is_verification_hash_registered(self: @TContractState, verification_hash: felt252) -> bool;
) -> Array<VerificationListElement>;
fn get_verification(self: @TContractState, verification_hash: felt252) -> Option<Verification>;

fn get_verifier_address(self: @TContractState, settings: VerifierSettings) -> ContractAddress;
fn register_verifier(
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -161,16 +162,16 @@ mod Proxy {

fn get_all_verifications_for_fact_hash(
self: @ContractState, fact_hash: felt252
) -> Array<Verification> {
) -> Array<VerificationListElement> {
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<Verification> {
IFactRegistryDispatcher { contract_address: self.fact_registry.read() }
.is_verification_hash_registered(verification_hash)
.get_verification(verification_hash)
}

fn get_verifier_address(
Expand Down

0 comments on commit a9bab39

Please sign in to comment.