Skip to content

Commit

Permalink
Make get_all_verifications_for_fact_hash return type a struct
Browse files Browse the repository at this point in the history
  • Loading branch information
fmkra committed Sep 10, 2024
1 parent 0ad6813 commit 15d5569
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
17 changes: 13 additions & 4 deletions src/fact_registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ fn settings_from_struct(settings: VerifierSettings) -> (felt252, felt252, felt25
(settings.layout, settings.hasher, settings.version)
}

#[derive(Drop, Copy, Serde)]
struct Verification {
verification_hash: felt252,
security_bits: u32,
settings: VerifierSettings,
}

#[derive(Drop, Copy, Serde, starknet::Event)]
struct FactRegistered {
#[key]
Expand Down Expand Up @@ -72,7 +79,7 @@ trait IFactRegistry<TContractState> {

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

fn get_verifier_address(self: @TContractState, settings: VerifierSettings) -> ContractAddress;
Expand All @@ -95,7 +102,7 @@ mod FactRegistry {
starknet::event::EventEmitter
};
use super::{
VerifierSettings, IFactRegistry, FactRegistered, settings_from_struct, settings_to_struct
VerifierSettings, Verification, IFactRegistry, FactRegistered, settings_from_struct, settings_to_struct
};

#[storage]
Expand Down Expand Up @@ -200,7 +207,7 @@ mod FactRegistry {

fn get_all_verifications_for_fact_hash(
self: @ContractState, fact_hash: felt252
) -> Array<(felt252, u32, VerifierSettings)> {
) -> Array<Verification> {
let n = self.facts.read(fact_hash);
let mut i = 0;
let mut arr = array![];
Expand All @@ -214,7 +221,9 @@ mod FactRegistry {
.read(verification_hash)
.unwrap();
let settings = settings_to_struct(settings_tuple);
arr.append((verification_hash, security_bits, settings));
arr.append(Verification {
verification_hash, security_bits, settings
});
i += 1;
};
arr
Expand Down
8 changes: 4 additions & 4 deletions src/proxy.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cairo_verifier::{
StarkProofWithSerde, CairoVersion,
fri::fri::{FriLayerWitness, FriVerificationStateConstant, FriVerificationStateVariable},
verifier::InitResult, fact_registry::{FactRegistered, VerifierSettings},
verifier::InitResult, fact_registry::{FactRegistered, VerifierSettings, Verification},
};
use starknet::{ContractAddress, ClassHash};

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

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

fn get_verifier_address(self: @TContractState, settings: VerifierSettings) -> ContractAddress;
Expand Down Expand Up @@ -80,7 +80,7 @@ mod Proxy {
poseidon::{Poseidon, PoseidonImpl, HashStateImpl}, keccak::keccak_u256s_be_inputs,
starknet::event::EventEmitter
};
use super::{VerifierSettings, IProxy, FactRegistered, settings_from_struct, settings_to_struct};
use super::{VerifierSettings, Verification, IProxy, FactRegistered, settings_from_struct, settings_to_struct};

#[event]
#[derive(Drop, starknet::Event)]
Expand Down Expand Up @@ -158,7 +158,7 @@ mod Proxy {

fn get_all_verifications_for_fact_hash(
self: @ContractState, fact_hash: felt252
) -> Array<(felt252, u32, VerifierSettings)> {
) -> Array<Verification> {
IFactRegistryDispatcher { contract_address: self.fact_registry.read() }
.get_all_verifications_for_fact_hash(fact_hash)
}
Expand Down

0 comments on commit 15d5569

Please sign in to comment.