Gas Optimizations #126
Labels
bug
Something isn't working
G (Gas Optimization)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
#1
Impact
Light DoS of USDC withdrawal system
Proof of Concept
Currently, withdrawals are queued in an array and processed sequentially in a for loop.
However, a malicious user can post unlimited number of tiny (1 wei) withdrawals.
Or, not-malicious user can post multiple withdrawals.
User will receive funds from multiple transfers but it's possible to make only 1 transfer.
USDC transfers are actually expensive due to additional, non-standard SLOADs.
There is more...
Unused array's storage is not freed. I propose usage of mappings, so one can free the memory and get a refund.
https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/VUSD.sol#L53-L67
Tools Used
Manual review
Recommended Mitigation Steps
There are 3 ways it can be rewritten:
1st, preserve FIFO order + remove unused storage - multiple calls to the same recipient
2nd, don't preserve FIFO order + remove unused storage - most efficient although unfair property
3nd (BEST), preserve FIFO order + remove unused storage + single call to the same recipient (Aggregate)
1st approach
2nd approach
3rd approach
2
Impact
Excessive SLOAD in a for loop.
Proof of Concept
https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/VUSD.sol#L57
Tools Used
Manual review
Recommended Mitigation Steps
Cache array's length in memory
The text was updated successfully, but these errors were encountered: