DeFiFoundry
60,000 USDC
View results
Submission Details
Severity: high
Invalid

the function 'depositMargin' can be front run

Summary

The depositMargin function allows anyone (not just the account owner) to deposit collateral for other traders.

Vulnerability Details

This opens up the potential for malicious front-running activity where an attacker observes a trader's intended action (e.g., open a large position), then deposits into the trader's account in advance with the aim to financially benefit when the trader's action naturally moves the market in favor of the attacker's deposit.

Additionally, the createTradingAccount function could potentially be abused. In its current state, anyone can create an account using someone else's referral code. This could lead to confusion, potential reputational harm to the looks of the initial code owner, and even flooding a legitimate user's referral list with spam accounts.

Example

function depositMargin(uint128 tradingAccountId, address collateralType, uint256 amount) public virtual {
// [...]
TradingAccount.Data storage tradingAccount = TradingAccount.loadExisting(tradingAccountId);
// [...]
IERC20(collateralType).safeTransferFrom(msg.sender, address(this), amount);
// then perform the actual deposit
tradingAccount.deposit(collateralType, amountX18);
// [...]
}
function createTradingAccount( bytes memory referralCode, bool isCustomReferralCode ) public virtual returns (uint128 tradingAccountId)
{
[...]
Referral.Data storage referral = Referral.load(msg.sender);
if (referralCode.length != 0 && referral.referralCode.length == 0) {
// [...]
emit LogReferralSet(msg.sender, referral.getReferrerAddress(), referralCode, isCustomReferralCode);
}
return tradingAccountId;
}

Impact

Lost of funds for users

Tools Used

Manual Review

Recommendations

Consider introducing access controls and restrictions to functions like depositMargin and createTradingAccount to prevent arbitrary accounts from submitting deposits and referrals on behalf of other users.

Validate that the account wanting to deposit tokens matches the tradingAccountId owner.

Similarly, consider only allowing the creation of a referral if the account holder decides to create one.

Updates

Lead Judging Commences

inallhonesty Lead Judge 11 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.