Skip to content
Business logic Audit finding Intermediate

Protocol Fee Exponential Compounding in ShareModule.handleReport

The protocol fee calculation in ShareModule.handleReport compounds exponentially because fees are calculated on total shares that already include previously minted fees. An attacker could not directly exploit this, but frequent reporting causes users to pay more fees than intended.

auditgpt Follow with blockace, bughuntoor and 1 other

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-07-mellow-flexible-vaults-judging/issues/161

Found by

auditgpt, blockace, bughuntoor, tedox

Summary

The protocol fee calculation in ShareModule.handleReport function suffers from exponential compounding instead of linear accumulation. When handleReport is called frequently (e.g., daily), the protocol fee is applied to the current total shares which includes all previously accrued fees, leading to higher-than-intended fee extraction.

Root Cause

In ShareModule.handleReport at line 281-284:

Solidity
uint256 fees = feeManager_.calculateFee(address(this), asset, priceD18, shareManager_.totalShares());
if (fees != 0) {
    shareManager_.mint(feeManager_.feeRecipient(), fees);
}

The issue is that shareManager_.totalShares() includes all previously minted shares, including fees that were already taken. This means each subsequent fee calculation is based on an inflated share count, leading to exponential compounding rather than linear fee accumulation.

The FeeManager.calculateFee function calculates fees based on the current total shares:

Solidity
function calculateFee(address vault, address asset, uint256 priceD18, uint256 totalShares) external view returns (uint256) {
    // ... other fee calculations ...
    uint256 protocolFee = (totalShares * protocolFeeRate * timeElapsed) / (365 days * 1e6);
    return protocolFee;
}

Internal Pre-conditions

  1. Protocol fees are enabled in the FeeManager
  2. handleReport function is called frequently (e.g., daily or more often)
  3. The vault has existing shares that include previously accrued fees
  4. The fee recipient is properly configured

External Pre-conditions

  1. The vault has active deposits and share minting
  2. Regular reporting cycles are established (daily/weekly reports)
  3. Protocol fee rates are set to non-zero values

Attack Path

  1. Initial Setup: A vault is created with a 5% annual protocol fee rate
  2. Daily Reports: The handleReport function is called daily for 365 days
  3. Fee Calculation: Each day, fees are calculated based on totalShares() which includes previous day's fees
  4. Exponential Growth: The fee base grows each day, leading to compounding effects
  5. Result: After 365 days, the actual fee taken is 5.11% instead of the intended 5%

Impact

Users pay higher fees than intended, with the difference increasing over time

PoC

Solidity
// test/unit/modules/ShareModule.t.sol
function testExponentialProtocolFeeVulnerability() external {
	Deployment memory deployment = createVault(vaultAdmin, vaultProxyAdmin, assets);
	
	// Set up a 5% annual protocol fee (5e4 in D6 format)
	vm.prank(vaultAdmin);
	deployment.feeManager.setFees(0, 0, 0, 5e4); // 5% protocol fee
	
	// Set the base asset for the vault
	vm.prank(vaultAdmin);
	deployment.feeManager.setBaseAsset(address(deployment.vault), address(asset));
	
	// Create a deposit queue
	vm.prank(vaultAdmin);
	deployment.vault.setQueueLimit(1);
	vm.prank(vaultAdmin);
	deployment.vault.createQueue(0, true, vaultProxyAdmin, address(asset), new bytes(0));
	
	// Mint some initial shares to simulate existing deposits
	MockTokenizedShareManager(address(deployment.shareManager)).mintShares(user, 1000 ether);
	
	// Record initial state
	uint256 initialTotalShares = deployment.shareManager.totalShares();
	uint256 initialFeeRecipientShares = deployment.shareManager.sharesOf(vaultAdmin);
	
	// Start from a base timestamp
	uint256 baseTimestamp = block.timestamp;
	
	// Call handleReport daily for 365 days
	for (uint256 day = 1; day <= 365; day++) {
		uint256 timestamp = baseTimestamp + day * 1 days;
		
		// Move time forward by 1 day
		vm.warp(timestamp);
		
		// Call handleReport as the oracle with the current timestamp
		vm.prank(address(deployment.vault.oracle()));
		deployment.vault.handleReport(address(asset), 1e18, uint32(timestamp - 1 hours), uint32(timestamp - 1 hours));
	}
	
	// Check final state
	uint256 finalTotalShares = deployment.shareManager.totalShares();
	uint256 finalFeeRecipientShares = deployment.shareManager.sharesOf(vaultAdmin);
	
	// Calculate the total fees taken
	uint256 totalFeesTaken = finalFeeRecipientShares - initialFeeRecipientShares;
	
	// Calculate what the fees should be with linear compounding (5% annual)
	uint256 expectedFees = (initialTotalShares * 5) / 100; // 5% of initial shares
	
	console.log("Initial total shares:", initialTotalShares);
	console.log("Final total shares:", finalTotalShares);
	console.log("Initial fee recipient shares:", initialFeeRecipientShares);
	console.log("Final fee recipient shares:", finalFeeRecipientShares);
	console.log("Total fees taken:", totalFeesTaken);
	console.log("Expected fees (5% linear):", expectedFees);
}

Mitigation

The recommended fix would be to modify the fee calculation to calculate fess on assets amount based on total assets, and then mint corresponding shares to the fee recipient.

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/mellow-finance/flexible-vaults/pull/28/files

The original report as published on Sherlock, by auditgpt. 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

The fee is calculated using totalShares(), which includes previously minted fee shares, so each fee calculation is based on an inflated share count.

Impact

Users pay higher fees than intended, with the difference increasing over time.

What the attacker needed

Protocol fees enabled; handleReport called frequently; Vault has existing shares; Fee recipient configured

The fix

The fee calculation should be based on total assets rather than total shares, and then mint corresponding shares to the fee recipient.

How it was found

  1. Set up a vault with a 5% annual protocol fee.
  2. Call handleReport daily for 365 days.
  3. Each day, fees are calculated on totalShares() which includes previous fees.
  4. After 365 days, the actual fee taken is 5.11% instead of 5%.

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.

When a vault charges a fee, it mints new shares to the fee recipient. If this is done often, each new fee is calculated on a share count that already includes earlier fees, so the fee grows faster than intended. This means users end up paying more than the stated annual fee.

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 auditgpt

View all

1 more disclosed report, best first.

More from Mellow Flexible Vaults

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.