Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: stark tx auth #477

Merged
merged 3 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions starknet/src/authenticators.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ mod vanilla;
mod eth_tx;

mod eth_sig;

mod stark_tx;
108 changes: 108 additions & 0 deletions starknet/src/authenticators/stark_tx.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
use starknet::{ContractAddress};
use sx::types::{Strategy, IndexedStrategy, Choice};

#[starknet::interface]
trait IStarkTxAuthenticator<TContractState> {
fn authenticate_propose(
ref self: TContractState,
space: ContractAddress,
author: ContractAddress,
execution_strategy: Strategy,
user_proposal_validation_params: Array<felt252>,
metadata_URI: Array<felt252>
);
fn authenticate_vote(
ref self: TContractState,
space: ContractAddress,
voter: ContractAddress,
proposal_id: u256,
choice: Choice,
user_voting_strategies: Array<IndexedStrategy>,
metadata_URI: Array<felt252>
);
fn authenticate_update_proposal(
ref self: TContractState,
space: ContractAddress,
author: ContractAddress,
proposal_id: u256,
execution_strategy: Strategy,
metadata_URI: Array<felt252>
);
}

#[starknet::contract]
mod StarkTxAuthenticator {
use super::IStarkTxAuthenticator;
use starknet::{ContractAddress, info};
use core::array::ArrayTrait;
use sx::space::space::{ISpaceDispatcher, ISpaceDispatcherTrait};
use sx::types::{UserAddress, Strategy, IndexedStrategy, Choice};

#[storage]
struct Storage {}

#[external(v0)]
impl StarkTxAuthenticator of IStarkTxAuthenticator<ContractState> {
fn authenticate_propose(
ref self: ContractState,
space: ContractAddress,
author: ContractAddress,
execution_strategy: Strategy,
user_proposal_validation_params: Array<felt252>,
metadata_URI: Array<felt252>
) {
assert(info::get_caller_address() == author, 'Invalid Caller');
Orland0x marked this conversation as resolved.
Show resolved Hide resolved

ISpaceDispatcher {
contract_address: space
}
.propose(
UserAddress::Starknet(author),
execution_strategy,
user_proposal_validation_params,
metadata_URI
);
}

fn authenticate_vote(
ref self: ContractState,
space: ContractAddress,
voter: ContractAddress,
proposal_id: u256,
choice: Choice,
user_voting_strategies: Array<IndexedStrategy>,
metadata_URI: Array<felt252>
) {
assert(info::get_caller_address() == voter, 'Invalid Caller');
Orland0x marked this conversation as resolved.
Show resolved Hide resolved

ISpaceDispatcher {
contract_address: space
}
.vote(
UserAddress::Starknet(voter),
proposal_id,
choice,
user_voting_strategies,
metadata_URI
);
}

fn authenticate_update_proposal(
ref self: ContractState,
space: ContractAddress,
author: ContractAddress,
proposal_id: u256,
execution_strategy: Strategy,
metadata_URI: Array<felt252>
) {
assert(info::get_caller_address() == author, 'Invalid Caller');
Orland0x marked this conversation as resolved.
Show resolved Hide resolved

ISpaceDispatcher {
contract_address: space
}
.update_proposal(
UserAddress::Starknet(author), proposal_id, execution_strategy, metadata_URI
);
}
}
}
1 change: 1 addition & 0 deletions starknet/src/tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod test_merkle_whitelist;
mod test_factory;
mod test_space;
mod test_upgrade;
mod test_stark_tx_auth;

mod mocks;
mod setup;
Expand Down
Loading