Skip to content
DoS Audit finding Intermediate

Denial of Service - userDepositIndex and userWithdrawIndex growing indefinitely

The contract's user deposit and withdrawal index arrays grow indefinitely because deletions only zero out entries instead of removing them, causing every call to iterate over the entire array. This leads to increasingly expensive transactions and potential denial of service for users calling withdrawUSDC and dequeueCrabs.

indijanc Follow with __141345__, Trumpero and 6 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-11-opyn-judging/issues/156

Found by

indijanc, __141345__, Trumpero, reassor, Met, KingNFT, zapaz, csanuragjain, HonorLt

Summary

State variables userDepositIndex and userWithdrawIndex are growing indefinitely, this might lead to expensive transactions and effectively denial of service for the user when calling withdrawUSCD and dequeueCrabs functions that require iterations over the whole arrays.

Vulnerability Detail

The contract is using userDepositsIndex and userWithdrawsIndex to track deposits and withdraw for users. This helps with parsing state variables deposits and withdraws that contain data for all users. userDepositsIndex is expanded by depositUSDC function and the elements are deleted by withdrawUSDC, however the delete is only setting data located at the given index to zero. This make all element re-parsed every time the function is called, making the user consuming more gas. The very same logic is present within the function queueCrabForWithdrawal and dequeueCrabs. The first one will make the userWithdrawsIndex grow and the second will just zero-out the elements but keep parsing them every time the user call the function.

Impact

Denial of service/very expensive transactions for users of the protocol.

Code Snippet

Tool used

Manual Review

Recommendation

It is recommended to remove elements from the arrays userDepositsIndex/userWithdrawsIndex using pop() function when deleting deposits. This should be easy to implement since the iteration starts from last item and goes down until first element.

Discussion

sanandnarayan

fix: https://github.com/opynfinance/squeeth-monorepo/pull/799

thec00n

Fix LGTM.

The original report as published on Sherlock, by indijanc. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 deletion logic sets array elements to zero instead of removing them, so the arrays never shrink and iteration cost grows with each deposit or withdrawal.

Impact

Users may face very expensive transactions and effectively denial of service when calling withdrawUSDC and dequeueCrabs, as the functions iterate over ever-growing arrays.

What the attacker needed

User makes multiple deposits/withdrawals

The fix

The fix was to remove elements from the arrays using pop() when deleting deposits, which is easy since iteration starts from the last item.

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 keeps a list of a user's deposits and withdrawals. When an item is removed, the code only sets it to zero but leaves it in the list, so the list keeps getting longer. Each time the user interacts, the contract must go through the whole list, which costs more and more gas (transaction fee), eventually making it too expensive to use.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by indijanc

View all

3 more disclosed reports, best first.

More from Opyn Crab Netting

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.