Skip to content

Commit

Permalink
chore: space contract parity (#529)
Browse files Browse the repository at this point in the history
* add vote_registry view function

* add assert in initializer function; test them

* parity for initialize fn

* reorder propose arguments

* add comment regarding testing assert_proposal_exists

* reorder proposal_id in fn propose

* remove useless cote in test_vote_zero_address

* re-order proposalcreated event

* parity with vote function

* prevent re-entrency attacks in execute fn; parity with execute function

* reorder function delclaration; rename cancel_upgrade to cancel

* parity with cancel function ; add tests

* add invalid payload test for execute

* remove useless imports in test_upgrade

* reorder update_proposal; add missing assert in update_proposal

* add tests for assertions in update_proposal

* return a SyscallResult in upgrade

* add set_dao_uri / test update dao_uri

* finish testing branches

* remove string comments

* change metadataURI argument order in l1-execution.test.ts

* fix len mismatch error in l1 test

* modify stark / eth authenticators to take metadata_uri in second position
  • Loading branch information
pscott authored Sep 6, 2023
1 parent 10f373d commit b8844af
Show file tree
Hide file tree
Showing 18 changed files with 653 additions and 204 deletions.
8 changes: 4 additions & 4 deletions starknet/src/authenticators/eth_sig.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ trait IEthSigAuthenticator<TContractState> {
v: u256,
target: ContractAddress,
author: EthAddress,
metadata_uri: Array<felt252>,
execution_strategy: Strategy,
user_proposal_validation_params: Array<felt252>,
metadata_uri: Array<felt252>,
salt: u256,
);
fn authenticate_vote(
Expand Down Expand Up @@ -67,9 +67,9 @@ mod EthSigAuthenticator {
v: u256,
target: ContractAddress,
author: EthAddress,
metadata_uri: Array<felt252>,
execution_strategy: Strategy,
user_proposal_validation_params: Array<felt252>,
metadata_uri: Array<felt252>,
salt: u256,
) {
signatures::verify_propose_sig(
Expand All @@ -88,9 +88,9 @@ mod EthSigAuthenticator {
ISpaceDispatcher { contract_address: target }
.propose(
UserAddress::Ethereum(author),
metadata_uri,
execution_strategy,
user_proposal_validation_params,
metadata_uri
);
}

Expand Down Expand Up @@ -126,7 +126,7 @@ mod EthSigAuthenticator {
proposal_id,
choice,
user_voting_strategies,
metadata_uri
metadata_uri,
);
}

Expand Down
10 changes: 5 additions & 5 deletions starknet/src/authenticators/eth_tx.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ trait IEthTxAuthenticator<TContractState> {
ref self: TContractState,
target: ContractAddress,
author: EthAddress,
metadata_uri: Array<felt252>,
execution_strategy: Strategy,
user_proposal_validation_params: Array<felt252>,
metadata_uri: Array<felt252>
);
fn authenticate_vote(
ref self: TContractState,
Expand Down Expand Up @@ -53,27 +53,27 @@ mod EthTxAuthenticator {
ref self: ContractState,
target: ContractAddress,
author: EthAddress,
metadata_uri: Array<felt252>,
execution_strategy: Strategy,
user_proposal_validation_params: Array<felt252>,
metadata_uri: Array<felt252>
) {
let mut payload = array![];
target.serialize(ref payload);
PROPOSE_SELECTOR.serialize(ref payload);
author.serialize(ref payload);
metadata_uri.serialize(ref payload);
execution_strategy.serialize(ref payload);
user_proposal_validation_params.serialize(ref payload);
metadata_uri.serialize(ref payload);
let payload_hash = poseidon::poseidon_hash_span(payload.span());

consume_commit(ref self, payload_hash, author);

ISpaceDispatcher { contract_address: target }
.propose(
UserAddress::Ethereum(author),
metadata_uri,
execution_strategy,
user_proposal_validation_params,
metadata_uri
);
}

Expand Down Expand Up @@ -104,7 +104,7 @@ mod EthTxAuthenticator {
proposal_id,
choice,
user_voting_strategies,
metadata_uri
metadata_uri,
);
}

Expand Down
8 changes: 4 additions & 4 deletions starknet/src/authenticators/stark_sig.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ trait IStarkSigAuthenticator<TContractState> {
signature: Array<felt252>,
target: ContractAddress,
author: ContractAddress,
metadata_uri: Array<felt252>,
execution_strategy: Strategy,
user_proposal_validation_params: Array<felt252>,
metadata_uri: Array<felt252>,
salt: felt252,
account_type: felt252
);
Expand Down Expand Up @@ -60,9 +60,9 @@ mod StarkSigAuthenticator {
signature: Array<felt252>,
target: ContractAddress,
author: ContractAddress,
metadata_uri: Array<felt252>,
execution_strategy: Strategy,
user_proposal_validation_params: Array<felt252>,
metadata_uri: Array<felt252>,
salt: felt252,
account_type: felt252
) {
Expand All @@ -84,9 +84,9 @@ mod StarkSigAuthenticator {
ISpaceDispatcher { contract_address: target }
.propose(
UserAddress::Starknet(author),
metadata_uri,
execution_strategy,
user_proposal_validation_params,
metadata_uri
);
}

Expand Down Expand Up @@ -121,7 +121,7 @@ mod StarkSigAuthenticator {
proposal_id,
choice,
user_voting_strategies,
metadata_uri
metadata_uri,
);
}

Expand Down
8 changes: 4 additions & 4 deletions starknet/src/authenticators/stark_tx.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ trait IStarkTxAuthenticator<TContractState> {
ref self: TContractState,
space: ContractAddress,
author: ContractAddress,
metadata_uri: Array<felt252>,
execution_strategy: Strategy,
user_proposal_validation_params: Array<felt252>,
metadata_uri: Array<felt252>
);
fn authenticate_vote(
ref self: TContractState,
Expand Down Expand Up @@ -48,18 +48,18 @@ mod StarkTxAuthenticator {
ref self: ContractState,
space: ContractAddress,
author: ContractAddress,
metadata_uri: Array<felt252>,
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),
metadata_uri,
execution_strategy,
user_proposal_validation_params,
metadata_uri
);
}

Expand All @@ -80,7 +80,7 @@ mod StarkTxAuthenticator {
proposal_id,
choice,
user_voting_strategies,
metadata_uri
metadata_uri,
);
}

Expand Down
15 changes: 7 additions & 8 deletions starknet/src/factory/factory.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use starknet::{ContractAddress, ClassHash};
use starknet::{ContractAddress, ClassHash, SyscallResult};

#[starknet::interface]
trait IFactory<TContractState> {
Expand All @@ -7,7 +7,7 @@ trait IFactory<TContractState> {
class_hash: ClassHash,
contract_address_salt: felt252,
initialize_calldata: Span<felt252>
) -> ContractAddress;
) -> SyscallResult<ContractAddress>;
}


Expand All @@ -16,7 +16,7 @@ mod Factory {
use super::IFactory;
use starknet::{
ContractAddress, ClassHash, contract_address_const,
syscalls::{deploy_syscall, call_contract_syscall}
syscalls::{deploy_syscall, call_contract_syscall}, SyscallResult
};
use sx::utils::constants::INITIALIZE_SELECTOR;

Expand All @@ -42,14 +42,13 @@ mod Factory {
class_hash: ClassHash,
contract_address_salt: felt252,
initialize_calldata: Span<felt252>
) -> ContractAddress {
) -> SyscallResult<ContractAddress> {
let (space_address, _) = deploy_syscall(
class_hash, contract_address_salt, array![].span(), false
)
.unwrap();
)?;

// Call initializer.
call_contract_syscall(space_address, INITIALIZE_SELECTOR, initialize_calldata).unwrap();
call_contract_syscall(space_address, INITIALIZE_SELECTOR, initialize_calldata)?;

self
.emit(
Expand All @@ -58,7 +57,7 @@ mod Factory {
)
);

space_address
Result::Ok(space_address)
}
}
}
Loading

0 comments on commit b8844af

Please sign in to comment.