Skip to content

fix(referral_registry): reject unregistered referrers in register_referral - #125

Open
Anichris-koded wants to merge 2 commits into
SPulse-Org:mainfrom
Anichris-koded:fix/issue-71-validate-referrer-registered
Open

fix(referral_registry): reject unregistered referrers in register_referral#125
Anichris-koded wants to merge 2 commits into
SPulse-Org:mainfrom
Anichris-koded:fix/issue-71-validate-referrer-registered

Conversation

@Anichris-koded

Copy link
Copy Markdown

Summary

Fixes #71

register_referral accepted any referrer: Option<Address> with no check that the address was a registered user. This allowed:

  • Fee routing to attacker-controlled addresses
  • Inflation of ReferralCount/ReferralEarnings for non-participants

Changes

referral_registry/src/lib.rs

  • Added UnregisteredReferrer = 7 to ReferralError
  • Added a guard in register_referral immediately after the self-referral check:
    if !Self::is_registered(env.clone(), ref_addr.clone()) {
        return Err(ReferralError::UnregisteredReferrer);
    }
    Uses the existing is_registered() helper, which handles both the new Profile key and legacy Registered key — so legacy users remain valid referrers.

referral_registry/src/tests.rs

  • Added test_reject_unregistered_referrer — asserts Error(Contract, #7) when a never-registered address is used as referrer
  • Updated 5 existing tests to pre-register the referrer before using them: test_register_with_referrer, test_credit_with_referrer, test_earnings_accumulation, test_referrer_bonus_points_accumulate, test_referral_count_tracking
  • Fixed points assertions in test_credit_with_referrer (5 welcome + 3 credit = 8) and test_referrer_bonus_points_accumulate (5 welcome + 3×3 credit = 14)

What was tested

  • All referral_registry tests reviewed and updated to pass under the new validation rule
  • No other contracts are affected (the guard is entirely within register_referral)

…erral

Closes SPulse-Org#71

- Add UnregisteredReferrer = 7 to ReferralError enum
- Guard in register_referral validates the referrer is already a
  registered user before accepting the relationship; returns
  Err(ReferralError::UnregisteredReferrer) otherwise
- Prevents fee routing to arbitrary/attacker-controlled addresses
  and stops inflation of ReferralCount for non-participants
- Add test_reject_unregistered_referrer (expects Error SPulse-Org#7)
- Update test_register_with_referrer, test_credit_with_referrer,
  test_earnings_accumulation, test_referrer_bonus_points_accumulate,
  and test_referral_count_tracking to pre-register the referrer;
  fix points assertions that now include the referrer's welcome bonus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MEDIUM] register_referral doesn't validate that the referrer is registered — unregistered referrers get paid

1 participant