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.
- 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
- Report ID: #46747
- Report Type: Smart Contract
- Report severity: Insight
- Target: https://github.com/tradeparadex/audit-competition-may-2025/tree/main/paraclear
- Impacts:
- Direct theft of any user funds, whether at-rest or in-motion, other than unclaimed yield
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:
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
-
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.
-
Economic Exploit: The system's fee calculation logic in
get_trade_fee_and_referral_commissionwould 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); } -
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:
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
- A user with
CONFIGURATOR_ROLEcallsset_account_referralwith:account= user's addressreferrer= same user's addresscommission=3000discount= 2000
- When the user trades, they receive both a 20% discount on fees and earn 30% commission on these already discounted fees.
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
- 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.
- 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.