fix(referral): depth limit, cycle detection & sybil bonus guard (#74) - #121
Open
Anichris-koded wants to merge 1 commit into
Open
Conversation
SPulse-Org#74) - Add MAX_REFERRAL_DEPTH = 5 constant to cap referral chain length - Add ReferralDepthExceeded (SPulse-Org#7) error: reject registration when the referrer's ancestor chain already reaches MAX_REFERRAL_DEPTH hops - Add ReferralCycle (SPulse-Org#8) error: reject registration when 'user' already appears in the referrer's ancestor chain (direct or indirect cycle) - Restrict welcome bonus (WELCOME_BONUS_POINTS + WELCOME_BONUS_TOKENS) to referrals-only; solo registrations no longer earn tokens, eliminating the primary sybil farming incentive - Fix broken reward_bonus cross-contract call (function never existed on leaderboard) → correct add_bonus_pts + mint calls - Fix pre-existing set_token → set_token_contract typo in test setups - Add tests: test_referral_depth_limit_exceeded, test_referral_depth_at_ limit_accepted, test_referral_cycle_direct, test_referral_cycle_indirect, test_no_bonus_without_referrer, updated test_welcome_bonus - All 20 referral_registry tests pass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #74 — unbounded referral chain depth, cycle vulnerability, and sybil fee farming via unconditional welcome bonus.
Changes
referral_registry/src/lib.rsDepth limit
MAX_REFERRAL_DEPTH = 5constantReferralDepthExceeded = 7error variantMAX_REFERRAL_DEPTHhops) and rejects if the limit is already reachedCycle detection
ReferralCycle = 8error variantuseralready appears in the chain, rejecting both direct (A→B, B→A) and indirect (A→B→C, C→A) cyclesSybil bonus guard
WELCOME_BONUS_POINTS+WELCOME_BONUS_TOKENS) inside theif let Some(referrer)block — solo registrations no longer earn tokens, eliminating the primary incentive for sybil chainsreward_bonuscross-contract call (function never existed on leaderboard) → correctadd_bonus_pts+ directmintcallsprediction_market/src/tests.rsset_token→set_token_contracttypo in test setupTests
test_referral_depth_limit_exceededtest_referral_depth_at_limit_acceptedtest_referral_cycle_directtest_referral_cycle_indirecttest_no_bonus_without_referrertest_welcome_bonus(updated)Result:
cargo test -p referral_registry→ 20/20 passed