Skip to content
Business logic Audit finding Intermediate

Self-Referral Vulnerability in Account Referral System

The referral-setting function did not check that an account and its referrer were different addresses, so an account could be made its own referrer. This would let that account collect both the referral discount and the referral commission on the same trades, reducing fees paid to the protocol.

Catchme Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

#46747 [SC-Insight] Self-Referral Vulnerability in Account Referral System

Submitted on Jun 4th 2025 at 07:21:29 UTC by @Catchme for IOP | Paradex

Description

Summary

There is a critical vulnerability in the set_account_referral function that allows an account to be set as its own referrer, creating a circular referral system that can be exploited to reduce trading fees unfairly.

Vulnerability Details

In AccountComponent::set_account_referral:

CAIRO
fn set_account_referral(
    ref self: ComponentState<TContractState>,
    account: ContractAddress,
    referrer: ContractAddress,
    commission: felt252,
    discount: felt252,
) {
    self.assert_only_role(roles::CONFIGURATOR_ROLE);
    self
        .Paraclear_account_referral
        .write(
            account,
            AccountReferral {
                referrer: referrer, fee_commission: commission, fee_discount: discount,
            },
        );
    self
        .emit(
            AccountReferralUpdate {
                account: account,
                referrer: referrer,
                fee_commission: commission,
                fee_discount: discount,
            },
        );
}

The function lacks validation to ensure that account != referrer. This allows setting up self-referrals where an account can refer itself, creating a circular referral relationship.

Impact

  1. Fee Manipulation: An account could receive both fee discounts as a referred account and fee commissions as a referrer for the same trades, allowing users to significantly reduce trading fees.

  2. Economic Exploit: The system's fee calculation logic in get_trade_fee_and_referral_commission would apply both a discount and generate commissions for the same account:

    CAIRO
    if self.referral.fee_discount != @0 {
        let one_minus_discount = math::MULTIPLIER - (*self.referral.fee_discount).try_into().unwrap();
        let fee_after_discount = mul_128(fee, one_minus_discount);
        if self.referral.fee_commission != @0 {
            let fee_commission = mul_128(
                fee_after_discount, (*self.referral.fee_commission).try_into().unwrap(),
            );
            return (fee_after_discount, *self.referral.referrer, fee_commission);
        }
        return (fee_after_discount, *self.referral.referrer, 0);
    }
    
  3. Protocol Revenue Loss: This could result in reduced protocol revenue from trading fees.

Recommended Fix

Add a validation check to ensure that account and referrer cannot be the same address:

CAIRO
fn set_account_referral(
    ref self: ComponentState<TContractState>,
    account: ContractAddress,
    referrer: ContractAddress,
    commission: felt252,
    discount: felt252,
) {
    self.assert_only_role(roles::CONFIGURATOR_ROLE);
    
    // Prevent self-referral
    assert(account != referrer, 'Self-referral not allowed');
    
    self
        .Paraclear_account_referral
        .write(
            account,
            AccountReferral {
                referrer: referrer, fee_commission: commission, fee_discount: discount,
            },
        );
    self
        .emit(
            AccountReferralUpdate {
                account: account,
                referrer: referrer,
                fee_commission: commission,
                fee_discount: discount,
            },
        );
}

Proof of Concept

Proof of Concept

  1. A user with CONFIGURATOR_ROLE calls set_account_referral with:
    • account = user's address
    • referrer = same user's address
    • commission =3000
    • discount = 2000
  2. When the user trades, they receive both a 20% discount on fees and earn 30% commission on these already discounted fees.

The original report as published on Immunefi, by Catchme. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The set_account_referral function wrote the referral record without asserting that the account and referrer addresses differ.

Impact

An account set up this way could pay reduced trading fees while also earning commission on those same fees, which could reduce protocol revenue; the text does not show this happening without the privileged role.

What the attacker needed

Caller holds CONFIGURATOR_ROLE

The fix

The function should reject any call where the account and referrer are the same address.

How it was found

  1. A holder of the configurator role calls the referral-setting function with the same address as both account and referrer, plus a commission and a discount.
  2. When that account trades, the fee logic applies the discount and also pays commission to the same address.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A referral system gives a discount to the person being referred and a cut of the fee to the person who referred them. Here nothing stopped an account from referring itself, so one account could get both benefits at once. The catch is that only a privileged role could set this up, so it is a design flaw rather than something any user could trigger.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by Catchme

View all

16 more disclosed reports, best first.

More from Paradex

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.