Skip to content
Open
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
6 changes: 5 additions & 1 deletion contracts/smart-account/src/auth/policy/token_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ impl AuthorizationCheck for TokenTransferPolicy {

fn validate_policy(policy: &TokenTransferPolicy, env: &Env) -> Result<(), SmartAccountError> {
if let Some(limit) = policy.limit {
if limit <= 0 {
// `<= 0` rejects zero and negative limits. `== i128::MAX` is also
// rejected: `extract_transfer_total` and `check_spending_limit`
// saturate on overflow, so `limit == i128::MAX` would degenerate
// into unlimited spending (`new_total > i128::MAX` is never true).
if limit <= 0 || limit == i128::MAX {
return Err(SmartAccountError::InvalidPolicy);
}
}
Expand Down
16 changes: 16 additions & 0 deletions contracts/smart-account/src/tests/token_transfer_policy_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,3 +928,19 @@ fn test_updating_allowed_recipients_preserves_spending_tracker() {
let contexts = vec![&env, make_transfer_context(&env, &token, &allowed_2, 300)];
check_auth(&env, &contract_id, &signer, &contexts).unwrap();
}

// ============================================================================
// validate_policy must reject `limit = Some(i128::MAX)`.
// With saturating-adds in extract_transfer_total / check_spending_limit,
// a MAX limit silently degenerates into unlimited spending.
// ============================================================================

#[test]
#[should_panic(expected = "#80")]
fn test_on_add_rejects_i128_max_limit() {
let env = setup();
let token = Address::generate(&env);
let mut policy = make_policy(&env, &token, Some(1000));
policy.limit = Some(i128::MAX);
let _ = setup_account_with_policy(&env, &policy);
}
Loading