Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded Q -> 2 from #117 [1675572860639] #685

Closed
c4-judge opened this issue Feb 5, 2023 · 2 comments
Closed

Upgraded Q -> 2 from #117 [1675572860639] #685

c4-judge opened this issue Feb 5, 2023 · 2 comments
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value duplicate-552 satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@c4-judge
Copy link
Contributor

c4-judge commented Feb 5, 2023

Judge has assessed an item in Issue #117 as 2 risk. The relevant finding follows:

Description
If a single address has certain amount of RabbitHoleReceipt tokens (receipts) - according to tests ~1050, when he tries to call claim function from Quest.sol it will always revert with 'Transaction ran out of gas' error. The reason for the error is that claim function loops over user's all tokens.

uint[] memory tokens = rabbitHoleReceiptContract.getOwnedTokenIdsOfQuest(questId, msg.sender);
...
for (uint i = 0; i < tokens.length; i++) {
if (!isClaimed(tokens[i])) {
redeemableTokenCount++;
}
}
PoC
Add a new test case in test/Erc20Quest.spec.ts file.

it('user can DoS himself (claim function)', async () => {
const signers = await ethers.getSigners();
const seller = signers[9]
const buyer = signers[10];

await deployedQuestContract.start()
await ethers.provider.send('evm_increaseTime', [86400])

// Ignore below function. It represents 1050 tokens from different users.
for (let i = 0; i < 1050; ++i) {
  await deployedRabbitholeReceiptContract.connect(seller).mint(seller.address, questId)
}

const totalTokens = await deployedRabbitholeReceiptContract.getOwnedTokenIdsOfQuest(questId, seller.address);

// Assume buyer gets 1050 tokens from different users, not one
for (let i = 0; i < totalTokens.length; ++i) {
  await deployedRabbitholeReceiptContract.connect(seller).transferFrom(seller.address, buyer.address, totalTokens[i]);
}

// Now buyer has 1050 tokens
// He calls claim to get the rewards, but function reverts with `Transaction ran out of gas` error everytime
await deployedQuestContract.connect(buyer).claim()

})
Mitigation Steps
The user can always generate a new address and transfer some of the funds there. But if he has many tokens (> 10000), he should manage dozen accounts which can be become difficult and time consuming.
Better approach is to add maximum token claim amount as function parameter or to check tokens array length to not exceed certain amount.

@c4-judge c4-judge added the 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value label Feb 5, 2023
@c4-judge
Copy link
Contributor Author

c4-judge commented Feb 5, 2023

kirk-baird marked the issue as duplicate of #135

@c4-judge c4-judge closed this as completed Feb 5, 2023
@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Feb 14, 2023
@c4-judge
Copy link
Contributor Author

kirk-baird marked the issue as satisfactory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value duplicate-552 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

1 participant