-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/proxy_contract' into autogenerat…
…ed_split
- Loading branch information
Showing
27 changed files
with
609 additions
and
523 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
scarb 2.6.3 | ||
scarb nightly-2024-04-20 | ||
starknet-foundry 0.24.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,129 @@ | ||
mod verifier; | ||
mod fact_registry; | ||
use cairo_verifier::{StarkProofWithSerde, CairoVersion}; | ||
use starknet::ContractAddress; | ||
|
||
|
||
#[derive(Drop, Copy, Serde)] | ||
struct VerifierSettings { | ||
layout: felt252, | ||
hasher: felt252, | ||
security_bits: felt252, | ||
version: felt252, | ||
} | ||
|
||
#[starknet::interface] | ||
trait IFactRegistry<TContractState> { | ||
fn verify_and_register_fact( | ||
ref self: TContractState, | ||
stark_proof: StarkProofWithSerde, | ||
cairo_version: CairoVersion, | ||
settings: VerifierSettings, | ||
); | ||
fn is_valid(self: @TContractState, fact: felt252) -> bool; | ||
fn register_verifier(ref self: TContractState, settings: VerifierSettings, address: ContractAddress); | ||
fn transfer_ownership(ref self: TContractState, new_owner: ContractAddress); | ||
} | ||
|
||
#[starknet::contract] | ||
mod FactRegistry { | ||
use cairo_verifier::{StarkProofWithSerde, CairoVersion}; | ||
use starknet::{ContractAddress, get_caller_address}; | ||
use core::{ | ||
poseidon::{Poseidon, PoseidonImpl, HashStateImpl}, keccak::keccak_u256s_be_inputs, | ||
starknet::event::EventEmitter | ||
}; | ||
use cairo_verifier::verifier::{ICairoVerifierDispatcher, ICairoVerifierDispatcherTrait, StarkProof}; | ||
use super::{VerifierSettings, IFactRegistry}; | ||
|
||
#[storage] | ||
struct Storage { | ||
owner: ContractAddress, | ||
verifiers: LegacyMap<felt252, ContractAddress>, | ||
facts: LegacyMap<felt252, bool>, | ||
} | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event { | ||
// #[flat] | ||
// CairoVerifierEvent: CairoVerifier::Event, | ||
FactRegistered: FactRegistered, | ||
OwnershipTransferred: OwnershipTransferred, | ||
} | ||
|
||
#[derive(Drop, starknet::Event)] | ||
struct FactRegistered { | ||
#[key] | ||
fact: felt252, | ||
} | ||
|
||
#[derive(Drop, starknet::Event)] | ||
struct OwnershipTransferred { | ||
previous_owner: ContractAddress, | ||
new_owner: ContractAddress | ||
} | ||
|
||
#[constructor] | ||
fn constructor(ref self: ContractState, owner: ContractAddress) { | ||
self.owner.write(owner); | ||
} | ||
|
||
#[abi(embed_v0)] | ||
impl FactRegistryImpl of IFactRegistry<ContractState> { | ||
fn verify_and_register_fact( | ||
ref self: ContractState, | ||
stark_proof: StarkProofWithSerde, | ||
cairo_version: CairoVersion, | ||
settings: VerifierSettings, | ||
) { | ||
let verifier_address = self.verifiers.read(self._hash_settings(settings)); | ||
assert(verifier_address.into() != 0, 'VERIFIER_NOT_FOUND'); | ||
let (program_hash, output_hash) = ICairoVerifierDispatcher { | ||
contract_address: verifier_address | ||
}.verify_proof(stark_proof.into(), cairo_version); | ||
self._register_fact(program_hash, output_hash); | ||
} | ||
|
||
fn is_valid(self: @ContractState, fact: felt252) -> bool { | ||
self.facts.read(fact) | ||
} | ||
|
||
fn register_verifier(ref self: ContractState, settings: VerifierSettings, address: ContractAddress) { | ||
assert(self.owner.read() == get_caller_address(), 'ONLY_OWNER'); | ||
assert(address.into() != 0, 'INVALID_VERIFIER_ADDRESS'); | ||
let settings_hash = self._hash_settings(settings); | ||
assert(self.verifiers.read(settings_hash).into() == 0, 'VERIFIER_ALREADY_EXISTS'); | ||
self.verifiers.write(settings_hash, address); | ||
} | ||
|
||
fn transfer_ownership(ref self: ContractState, new_owner: ContractAddress) { | ||
let caller = get_caller_address(); | ||
assert(self.owner.read() == caller, 'ONLY_OWNER'); | ||
self.owner.write(new_owner); | ||
|
||
self | ||
.emit( | ||
Event::OwnershipTransferred( | ||
OwnershipTransferred { previous_owner: caller, new_owner } | ||
) | ||
); | ||
} | ||
} | ||
|
||
#[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); | ||
} | ||
|
||
fn _hash_settings(self: @ContractState, settings: VerifierSettings) -> felt252 { | ||
PoseidonImpl::new() | ||
.update(settings.layout) | ||
.update(settings.hasher) | ||
.update(settings.security_bits) | ||
.update(settings.version) | ||
.finalize() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[[call]] | ||
call_type = "deploy" | ||
class_hash = "0x79b972400cbbbc9afe4056a377366773bc069e292e1b9657bec2e48b4353ad3" | ||
inputs = ["REPLACE WITH YOUR ACCOUNT ADDRESS"] | ||
unique = false | ||
id = "fact_registry" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[[call]] | ||
call_type = "deploy" | ||
class_hash = "VERIFIER CLASS HASH" | ||
inputs = [] | ||
unique = false | ||
id = "verifier" | ||
|
||
[[call]] | ||
call_type = "invoke" | ||
contract_address = "REPLACE WITH FACT REGISTRY ADDRESS" | ||
function = "register_verifier" | ||
inputs = [ | ||
"SETTINGS.LAYOUT", | ||
"SETTINGS.HASHER", | ||
"SETTINGS.SECURITY_BITS", | ||
"SETTINGS.VERSION", | ||
"verifier" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,12 @@ | ||
// === DEX BEGIN === | ||
// mod dex; | ||
// === DEX END === | ||
// === RECURSIVE BEGIN === | ||
#[cfg(feature: 'dex')] | ||
mod dex; | ||
#[cfg(feature: 'recursive')] | ||
mod recursive; | ||
// === RECURSIVE END === | ||
// === RECURSIVE_WITH_POSEIDON BEGIN === | ||
// mod recursive_with_poseidon; | ||
// === RECURSIVE_WITH_POSEIDON END === | ||
// === SMALL BEGIN === | ||
// mod small; | ||
// === SMALL END === | ||
// === STARKNET BEGIN === | ||
// mod starknet; | ||
// === STARKNET END === | ||
// === STARKNET_WITH_KECCAK BEGIN === | ||
// mod starknet_with_keccak; | ||
// === STARKNET_WITH_KECCAK END === | ||
|
||
|
||
#[cfg(feature: 'recursive_with_poseidon')] | ||
mod recursive_with_poseidon; | ||
#[cfg(feature: 'small')] | ||
mod small; | ||
#[cfg(feature: 'starknet')] | ||
mod starknet; | ||
#[cfg(feature: 'starknet_with_keccak')] | ||
mod starknet_with_keccak; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.