Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
fmkra committed Sep 10, 2024
1 parent 0924ad9 commit 7695c8c
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions src/fact_registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ trait IFactRegistry<TContractState> {
settings: VerifierSettings,
);

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

fn get_verifier_address(self: @TContractState, settings: VerifierSettings) -> ContractAddress;
fn register_verifier(
ref self: TContractState, settings: VerifierSettings, address: ContractAddress
Expand All @@ -85,8 +87,12 @@ mod FactRegistry {
owner: ContractAddress,
verifiers: LegacyMap<felt252, ContractAddress>,
facts: LegacyMap<felt252, u32>, // fact_hash => number of verifications registered
fact_verifications: LegacyMap<(felt252, u32), felt252>, // fact_hash, index => verification_hash
verification_hashes: LegacyMap<felt252, Option<(felt252, u32, (felt252, felt252, felt252))>>, // verification_hash => (fact_hash, security_bits, settings)
fact_verifications: LegacyMap<
(felt252, u32), felt252
>, // fact_hash, index => verification_hash
verification_hashes: LegacyMap<
felt252, Option<(felt252, u32, (felt252, felt252, felt252))>
>, // verification_hash => (fact_hash, security_bits, settings)
}

#[event]
Expand Down Expand Up @@ -187,11 +193,12 @@ mod FactRegistry {
job_id, state_constant, state_variable, last_layer_coefficients
);


self._register_fact(fact_hash, verifier_address, security_bits, settings);
}

fn get_all_verifications_for_fact_hash(self: @ContractState, fact_hash: felt252) -> Array<(felt252, u32, VerifierSettings)> {
fn get_all_verifications_for_fact_hash(
self: @ContractState, fact_hash: felt252
) -> Array<(felt252, u32, VerifierSettings)> {
let n = self.facts.read(fact_hash);
let mut i = 0;
let mut arr = array![];
Expand All @@ -200,15 +207,20 @@ mod FactRegistry {
break;
}
let verification_hash = self.fact_verifications.read((fact_hash, i));
let (_, security_bits, settings_tuple) = self.verification_hashes.read(verification_hash).unwrap();
let (_, security_bits, settings_tuple) = self
.verification_hashes
.read(verification_hash)
.unwrap();
let settings = settings_to_struct(settings_tuple);
arr.append((verification_hash, security_bits, settings));
i += 1;
};
arr
}

fn is_verification_hash_registered(self: @ContractState, verification_hash: felt252) -> bool {
fn is_verification_hash_registered(
self: @ContractState, verification_hash: felt252
) -> bool {
self.verification_hashes.read(verification_hash).is_some()
}

Expand Down Expand Up @@ -271,15 +283,24 @@ mod FactRegistry {

self
.emit(
Event::FactRegistered(FactRegistered { fact_hash, verifier_address, security_bits, settings, verification_hash })
Event::FactRegistered(
FactRegistered {
fact_hash, verifier_address, security_bits, settings, verification_hash
}
)
);

if self.verification_hashes.read(verification_hash).is_some() {
return;
}
let next_index = self.facts.read(fact_hash);
self.fact_verifications.write((fact_hash, next_index), verification_hash);
self.verification_hashes.write(verification_hash, Option::Some((fact_hash, security_bits, settings_from_struct(settings))));
self
.verification_hashes
.write(
verification_hash,
Option::Some((fact_hash, security_bits, settings_from_struct(settings)))
);
self.facts.write(fact_hash, next_index + 1);
}
}
Expand Down

0 comments on commit 7695c8c

Please sign in to comment.