# Protocol Fee Exponential Compounding in ShareModule.handleReport

ShareModule.handleReport computes protocol fee on totalShares including prior fees, so frequent reports compound fees exponentially instead of linearly.

- Payout: Audit contest
- Severity: medium
- Program: Mellow Flexible Vaults
- Found by: auditgpt
- Disclosed: 2025-07-12
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2025-07-mellow-flexible-vaults-judging/issues/161
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-07-mellow-flexible-vaults%3AM-4
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:fee-bypass

**Target:** ShareModule.handleReport / FeeManager.calculateFee
**Root cause:** Fee is computed from shareManager_.totalShares(), which already includes previously minted fee shares, so each report compounds on the inflated base rather than the original principal.
**Steps:**
1. Deploy vault, set protocol fee rate to 5e4 (5% annual) via `feeManager.setFees(0,0,0,5e4)`
2. Set base asset and create deposit queue
3. Mint initial shares to a user
4. Loop 365 times: `vm.warp(base + day*1 days)` then call `vault.handleReport(asset, 1e18, ts-1h, ts-1h)` as oracle
5. Observe fee recipient shares exceed 5% of initial shares (≈5.11%)
**How found:** Code reading of handleReport fee path noticing totalShares() is used as fee base and includes previously minted fee shares, then PoC simulating daily reports over a year.
**Exploitation:** Passive: fee recipient gains extra shares over time as handleReport is called frequently; no attacker action needed beyond normal reporting cadence.
**Insight:** When auditing fee accrual, check whether the fee base is the pre-fee principal or a total that already includes prior fee mints; frequent-report cadence turns linear rates into compounding.

## Proof of concept (copied exactly from the original report)

**Foundry test looping handleReport 365 days**

```
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);
}
```

