57467 sc insight unlimited referrals hashedcode referralusers increases gas cost with each new referral making it very expensive

Submitted on Oct 26th 2025 at 13:41:48 UTC by @Oxlookman for Audit Comp | Belongarrow-up-right

  • Report ID: #57467

  • Report Type: Smart Contract

  • Report severity: Insight

  • Target: https://github.com/immunefi-team/audit-comp-belong/blob/main/contracts/v2/platform/extensions/ReferralSystemV2.sol

  • Impacts:

    • Griefing (e.g. no profit motive for an attacker, but damage to the users or the protocol)

    • Unbounded gas consumption

circle-info

Brief/Intro

Growing referrals[hashedCode].referralUsers array will make it difficult for a referrer to refer new users as this array grows.

Description

Vulnerability Details

Referrer's referral array increases over time. When a new referral is being added in _setReferralUser, the array is iterated to check if the referral is new:

for (uint256 i; i < len; ++i) {
    if (users[i] == referralUser) {
        // User already added; no need to add again
        inArray = true;
        break;
    }
}
if (!inArray) users.push(referralUser);

Since this array keeps growing with each new referral it will become very expensive for referrals to use the referrer code and at some point it will be DoSed.

Impact Details

  • The referrer will pay more gas fees as the array keeps growing, discouraging use of their referral code and causing them to lose their intended percentage.

  • Users also incur very expensive transactions.

References

  • https://github.com/immunefi-team/audit-comp-belong/blob/a17f775dcc4c125704ce85d4e18b744daece65af/contracts/v2/platform/extensions/ReferralSystemV2.sol#L148C8-L155C48

Proof of Concept

chevron-rightTest demonstrating increasing transaction costs with more referralshashtag

Add this to factort.test.ts in the describe with referral, setup local network in your config since this test was run on the localhost.

Was this helpful?