Budget allocation will break in case of a fee on transfer ERC 20 token
The allocate function in ManagedBudget.sol reverts when the contract's balance of an asset is less than the payload amount, which prevents the use of fee-on-transfer ERC20 tokens because the received amount is reduced by the fee. An attacker could not exploit this directly, but the protocol cannot allocate such tokens as intended.
Source: https://github.com/sherlock-audit/2024-06-boost-aa-wallet-judging/issues/325
The protocol has acknowledged this issue.
Found by
0xDemon, 0xbranded, 0xbrivan, 0xsome, 4b, AresAudits, Atharv, Aycozzynfada, DenTonylifer, Galturok, IvanFitro, Japy69, KungFuPanda, KupiaSec, MSK, MSaptarshi, MrCrowNFT, ParthMandale, Pheonix, TessKimy, dimulski, ge6a, haxagon, iamnmt, ihtishamsudo, nikhilx0111, oxelmiguel, sakshamguruji, tmotfl, y4y
Summary
Docs mention that the protocol should work with all kinds of weird tokens but a fee on transfer token won't be allocated to the budget since the allocate function in ManagedBudget.sol reverts when the balance of the asset is lesser than the amount mentioned in the payload.
Root Cause
ManagedBudget.sol:71: This check prevents the use of fee on transfer tokens since the allocated tokens actually transferred to the contract's balance will always be lesser than the payload amount owing to the fee component.
Internal pre-conditions
No response
External pre-conditions
No response
Attack Path
No response
Impact
The protocol will not be able to use fee on transfer tokens which they clearly want to use according to the questionnaire they answered.
PoC
This is a mock ERC20 fee on transfer token used for the POC
contract FeeOnTransferMockERC20 is ERC20("MOCK","MOCK"){
uint FEE = 10000;
function mint(address to, uint256 amount) public {
_balances[to] += amount;
}
function transfer(address to, uint256 amount) public override returns (bool) {
require(amount > FEE);
_balances[msg.sender] = _balances[msg.sender] - amount;
_balances[to] = _balances[msg.sender] + amount - FEE;
return true;
}
function safeTransferFrom(address from, address to, uint amount) public {
transferFrom(from, to, amount);
}
function transferFrom(address from, address to, uint amount) public override returns(bool){
require(amount > FEE);
_balances[from] = _balances[from] - amount;
_balances[to] = _balances[from] + amount - FEE;
return true;
}
function mintPayable(address to, uint256 amount) public payable {
require(msg.value >= amount / 100, "MockERC20: gimme more money!");
mint(to, amount);
}
}
The test to be added to ManagedBudget.t.sol to replicate the results
function testFeeOnTransfer() public{
//deploy a feeon transfer mock token and mint tokens to this address
mockFeeOnTransferERC20 = new FeeOnTransferMockERC20();
mockFeeOnTransferERC20.mint(address(this), 100 ether);
managedBudget = ManagedBudget(payable(LibClone.clone(address(new ManagedBudget()))));
managedBudget.initialize(
abi.encode(
ManagedBudget.InitPayload({owner: address(this), authorized: new address[](0), roles: new uint256[](0)})
)
);
mockFeeOnTransferERC20.approve(address(managedBudget), 100 ether);
bytes memory data = _makeFungibleTransfer(ABudget.AssetType.ERC20, address(mockFeeOnTransferERC20), address(this), 100 ether);
vm.expectRevert(abi.encodeWithSelector(ABudget.InvalidAllocation.selector, address(mockFeeOnTransferERC20), uint256(100 ether)));
managedBudget.allocate(data);
}
The test passes which means the managedBudget.allocate(data) call reverts with an InvalidAllocation error
Mitigation
This one is tricky since there are 2 paths the sponsor can take:
- Remove the support for fee on transfer tokens and mention this explicitly
- Keep supporting fee on transfer tokens and remove the aforementioned check.
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 the balance check in allocate assumes the received amount equals the requested amount, which fails for fee-on-transfer tokens.
Impact
The protocol will not be able to use fee-on-transfer tokens, which it intended to support.
What the attacker needed
Protocol intends to support fee-on-transfer tokens
The fix
Either explicitly remove support for fee-on-transfer tokens or remove the balance check that causes the revert.
How it was found
- Deploy a mock fee-on-transfer ERC20 token and mint tokens to the test address.
- Deploy and initialize a ManagedBudget contract.
- Approve the ManagedBudget to spend the mock tokens.
- Call allocate with a payload requesting the full token amount.
- Observe that the call reverts with InvalidAllocation.
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.
Some tokens take a small fee when they are transferred, so the receiver gets less than the sender sent. The protocol checks that the contract's balance increased by exactly the amount requested, so it rejects these tokens. This means the protocol cannot use tokens that behave this way, even though it intended to support them.
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.