-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into chore_eth_sig_auth_test
- Loading branch information
Showing
41 changed files
with
1,518 additions
and
316 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 +1 @@ | ||
NETWORK_URL | ||
NETWORK_URL= |
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 |
---|---|---|
|
@@ -3,3 +3,7 @@ mod vanilla; | |
mod eth_tx; | ||
|
||
mod eth_sig; | ||
|
||
mod stark_sig; | ||
|
||
mod stark_tx; |
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 |
---|---|---|
@@ -0,0 +1,172 @@ | ||
use starknet::ContractAddress; | ||
use sx::types::{Strategy, IndexedStrategy, Choice}; | ||
|
||
#[starknet::interface] | ||
trait IStarkSigAuthenticator<TContractState> { | ||
fn authenticate_propose( | ||
ref self: TContractState, | ||
signature: Array<felt252>, | ||
target: ContractAddress, | ||
author: ContractAddress, | ||
execution_strategy: Strategy, | ||
user_proposal_validation_params: Array<felt252>, | ||
metadata_URI: Array<felt252>, | ||
salt: felt252, | ||
account_type: felt252 | ||
); | ||
fn authenticate_vote( | ||
ref self: TContractState, | ||
signature: Array<felt252>, | ||
target: ContractAddress, | ||
voter: ContractAddress, | ||
proposal_id: u256, | ||
choice: Choice, | ||
user_voting_strategies: Array<IndexedStrategy>, | ||
metadata_URI: Array<felt252>, | ||
account_type: felt252 | ||
); | ||
fn authenticate_update_proposal( | ||
ref self: TContractState, | ||
signature: Array<felt252>, | ||
target: ContractAddress, | ||
author: ContractAddress, | ||
proposal_id: u256, | ||
execution_strategy: Strategy, | ||
metadata_URI: Array<felt252>, | ||
salt: felt252, | ||
account_type: felt252 | ||
); | ||
} | ||
|
||
#[starknet::contract] | ||
mod StarkSigAuthenticator { | ||
use super::IStarkSigAuthenticator; | ||
use starknet::{ContractAddress, info}; | ||
use core::array::{ArrayTrait, SpanTrait}; | ||
use serde::Serde; | ||
use sx::space::space::{ISpaceDispatcher, ISpaceDispatcherTrait}; | ||
use sx::types::{Strategy, IndexedStrategy, UserAddress, Choice}; | ||
use sx::utils::stark_eip712; | ||
|
||
#[storage] | ||
struct Storage { | ||
_domain_hash: felt252, | ||
_used_salts: LegacyMap::<(ContractAddress, felt252), bool> | ||
} | ||
|
||
#[external(v0)] | ||
impl StarkSigAuthenticator of IStarkSigAuthenticator<ContractState> { | ||
fn authenticate_propose( | ||
ref self: ContractState, | ||
signature: Array<felt252>, | ||
target: ContractAddress, | ||
author: ContractAddress, | ||
execution_strategy: Strategy, | ||
user_proposal_validation_params: Array<felt252>, | ||
metadata_URI: Array<felt252>, | ||
salt: felt252, | ||
account_type: felt252 | ||
) { | ||
assert(!self._used_salts.read((author, salt)), 'Salt Already Used'); | ||
|
||
stark_eip712::verify_propose_sig( | ||
self._domain_hash.read(), | ||
signature, | ||
target, | ||
author, | ||
@execution_strategy, | ||
user_proposal_validation_params.span(), | ||
metadata_URI.span(), | ||
salt, | ||
account_type | ||
); | ||
|
||
self._used_salts.write((author, salt), true); | ||
ISpaceDispatcher { | ||
contract_address: target | ||
} | ||
.propose( | ||
UserAddress::Starknet(author), | ||
execution_strategy, | ||
user_proposal_validation_params, | ||
metadata_URI | ||
); | ||
} | ||
|
||
fn authenticate_vote( | ||
ref self: ContractState, | ||
signature: Array<felt252>, | ||
target: ContractAddress, | ||
voter: ContractAddress, | ||
proposal_id: u256, | ||
choice: Choice, | ||
user_voting_strategies: Array<IndexedStrategy>, | ||
metadata_URI: Array<felt252>, | ||
account_type: felt252 | ||
) { | ||
// No need to check salts here, as double voting is prevented by the space itself. | ||
|
||
stark_eip712::verify_vote_sig( | ||
self._domain_hash.read(), | ||
signature, | ||
target, | ||
voter, | ||
proposal_id, | ||
choice, | ||
user_voting_strategies.span(), | ||
metadata_URI.span(), | ||
account_type | ||
); | ||
|
||
ISpaceDispatcher { | ||
contract_address: target | ||
} | ||
.vote( | ||
UserAddress::Starknet(voter), | ||
proposal_id, | ||
choice, | ||
user_voting_strategies, | ||
metadata_URI | ||
); | ||
} | ||
|
||
fn authenticate_update_proposal( | ||
ref self: ContractState, | ||
signature: Array<felt252>, | ||
target: ContractAddress, | ||
author: ContractAddress, | ||
proposal_id: u256, | ||
execution_strategy: Strategy, | ||
metadata_URI: Array<felt252>, | ||
salt: felt252, | ||
account_type: felt252 | ||
) { | ||
assert(!self._used_salts.read((author, salt)), 'Salt Already Used'); | ||
|
||
stark_eip712::verify_update_proposal_sig( | ||
self._domain_hash.read(), | ||
signature, | ||
target, | ||
author, | ||
proposal_id, | ||
@execution_strategy, | ||
metadata_URI.span(), | ||
salt, | ||
account_type | ||
); | ||
|
||
self._used_salts.write((author, salt), true); | ||
ISpaceDispatcher { | ||
contract_address: target | ||
} | ||
.update_proposal( | ||
UserAddress::Starknet(author), proposal_id, execution_strategy, metadata_URI | ||
); | ||
} | ||
} | ||
#[constructor] | ||
fn constructor(ref self: ContractState, name: felt252, version: felt252) { | ||
// TODO: store domain hash in stark_eip712 component once syntax is live. | ||
self._domain_hash.write(stark_eip712::get_domain_hash(name, version)); | ||
} | ||
} |
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,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'); | ||
|
||
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'); | ||
|
||
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'); | ||
|
||
ISpaceDispatcher { | ||
contract_address: space | ||
} | ||
.update_proposal( | ||
UserAddress::Starknet(author), proposal_id, execution_strategy, metadata_URI | ||
); | ||
} | ||
} | ||
} |
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.