Skip to content

Commit

Permalink
fix the critical issue in governor account contract implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed Jun 19, 2024
1 parent d933fe4 commit c564dae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/governor.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub trait IGovernor<TContractState> {
fn upgrade(ref self: TContractState, class_hash: ClassHash);
}

#[starknet::contract]
#[starknet::contract(account)]
pub mod Governor {
use core::hash::{HashStateTrait, HashStateExTrait};
use core::num::traits::zero::{Zero};
Expand Down Expand Up @@ -461,6 +461,7 @@ pub mod Governor {
0
}
fn __execute__(ref self: ContractState, mut calls: Array<Call>) -> Array<Span<felt252>> {
assert(get_caller_address().is_zero(), 'Invalid caller');
let mut results: Array<Span<felt252>> = array![];
while let Option::Some(call) = calls.pop_front() {
results.append(call.execute());
Expand Down
27 changes: 26 additions & 1 deletion src/governor_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use starknet::account::{Call};
use starknet::{
get_contract_address, syscalls::deploy_syscall, ClassHash, contract_address_const,
ContractAddress, get_block_timestamp,
testing::{set_block_timestamp, set_contract_address, pop_log}
testing::{set_block_timestamp, set_contract_address, pop_log},
account::{AccountContractDispatcher, AccountContractDispatcherTrait}
};

fn recipient() -> ContractAddress {
Expand Down Expand Up @@ -1014,6 +1015,30 @@ fn test_reconfigure_fails_if_not_self_call() {
);
}

#[test]
#[should_panic(expected: ("Not allowed", 'ENTRYPOINT_FAILED'))]
fn test_governor_validate_fails() {
let (_staker, _token, governor, _config) = setup();
AccountContractDispatcher { contract_address: governor.contract_address }
.__validate__(array![]);
}

#[test]
#[should_panic(expected: ("Not allowed", 'ENTRYPOINT_FAILED'))]
fn test_governor_validate_declare_fails() {
let (_staker, _token, governor, _config) = setup();
AccountContractDispatcher { contract_address: governor.contract_address }
.__validate_declare__(123);
}

#[test]
#[should_panic(expected: ('Invalid caller', 'ENTRYPOINT_FAILED'))]
fn test_governor_execute_fails_from_non_zero() {
let (_staker, _token, governor, _config) = setup();
set_contract_address(contract_address_const::<1>());
AccountContractDispatcher { contract_address: governor.contract_address }.__execute__(array![]);
}

#[test]
fn test_reconfigure_succeeds_self_call() {
let (staker, token, governor, config) = setup();
Expand Down

0 comments on commit c564dae

Please sign in to comment.