Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions contracts/governor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ fn assert_not_paused(env: &Env) -> Result<(), Error> {
}
}

/// The zero Stellar account is represented by an Ed25519 public key
/// consisting entirely of zero bytes.
fn is_zero_stellar_account(env: &Env, address: &Address) -> bool {
let zero_account = Address::from_string(&soroban_sdk::String::from_str(
env,
"GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF",
));

address == &zero_account
}

#[contract]
pub struct DripGovernor;

Expand Down Expand Up @@ -391,6 +402,9 @@ impl DripGovernor {
pub fn set_fee_recipient(env: Env, caller: Address, recipient: Address) -> Result<(), Error> {
assert_not_paused(&env)?;
role::require_role_or_admin(&env, &caller, Role::FeeManager)?;
if is_zero_stellar_account(&env, &recipient) {
return Err(Error::InvalidParam);
}
ttl::bump(&env);
let old_recipient: Address = env
.storage()
Expand Down
18 changes: 18 additions & 0 deletions tests/governor_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,24 @@ fn set_fee_recipient_extends_instance_ttl() {
assert_eq!(ttl, 200_000);
}

#[test]
fn set_fee_recipient_rejects_zero_address() {
let env = Env::default();
env.mock_all_auths();

let (client, authority, fee_recipient) = deploy_governor(&env);
let zero_account = Address::from_string(&soroban_sdk::String::from_str(
&env,
"GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF",
));

let result = client.try_set_fee_recipient(&authority, &zero_account);
assert_eq!(result, Err(Ok(Error::InvalidParam)));

// The rejected call must not have mutated state.
assert_eq!(client.config().fee_recipient, fee_recipient);
}

#[test]
fn set_min_duration_extends_instance_ttl() {
let env = Env::default();
Expand Down