AaveDIVAWrapper contract incorrectly handles tokens that take fees on transfer (fee-on-transfer tokens) by minting more wTokens than the actual received collateral amount. This can lead to a mismatch between the wrapped token supply and the actual collateral backing, potentially allowing malicious users to drain funds from the protocol._handleTokenOperations function, the contract mints wTokens based on the input amount rather than the actual received amount after transfer fees. For tokens that deduct fees on transfer, this creates a discrepancy between: The amount of collateral actually received and supplied to Aave
The amount of wTokens minted
function _handleTokenOperations(address _collateralToken, uint256 _collateralAmount, address _wToken) private {
// Transfers collateral token - if token has 5% fee, only 95 tokens are received
IERC20Metadata(_collateralToken).safeTransferFrom(msg.sender, address(this), _collateralAmount);
}
This breaks the 1:1 peg between wTokens and underlying collateral
The protocol becomes undercollateralized
Malicious users can exploit this to drain funds from the protocol
import "forge-std/Test.sol";
import "../src/AaveDIVAWrapper.sol";
import "../src/mocks/MockFeeToken.sol";
import "../src/mocks/MockAave.sol";
import "../src/mocks/MockDIVA.sol";
contract AaveDIVAWrapperTest is Test {
AaveDIVAWrapper public wrapper;
MockFeeToken public feeToken;
MockAave public aave;
MockDIVA public diva;
address public owner;
address public attacker;
}
Manual review
Foundry for PoC development
Modify the _handleTokenOperations function to use the actual received amount:
function _handleTokenOperations(address _collateralToken, uint256 _collateralAmount, address _wToken) private {
// Record balance before transfer
uint256 balanceBefore = IERC20Metadata(_collateralToken).balanceOf(address(this));
}
Consider maintaining a whitelist of approved collateral tokens
Add explicit checks that token balances match expected amounts
Add documentation warning about fee-on-transfer tokens
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.