code-423n4 / 2023-01-drips-findings

0 stars 2 forks source link

_split will mostly fail/revert on small-weighted receivers due to underflow #84

Closed code423n4 closed 1 year ago

code423n4 commented 1 year ago

Lines of code

https://github.com/code-423n4/2023-01-drips/blob/9fd776b50f4be23ca038b1d0426e63a69c7a511d/src/Splits.sol#L143-L170

Vulnerability details

Impact

Detailed description of the impact of this finding. _split() will mostly fail/revert on small-weighted receivers due to underflow. This is because it calculates the split amount for a receiver in the following way, which will underflow for small-weighted receivers.

uint128 currSplitAmt =
                uint128((uint160(collectableAmt) * splitsWeight) / _TOTAL_SPLITS_WEIGHT - splitAmt);

Proof of Concept

Provide direct links to all referenced code in GitHub. Add screenshots, logs, or any other relevant proof that illustrates the concept.

Here is an example of how _split() will fail/revert on small-weighted receivers due to underflow:

1) Suppose the total balance is 100, and to be distributed to receivers A (50%), B (40%) and C(10%). Therefore, A will get 50, B will get 40, and C will get 10.

2) When it is time to calculate the amount for B, we have: collectableAmt = 100, _TOTAL_SPLITS_WEIGHT =1_000_000, splitsWeight = 400_000, and splitAmt = 50, As a resul,t we have 40-50, an underflow.

uint128 currSplitAmt =
                uint128((uint160(collectableAmt) * splitsWeight) / _TOTAL_SPLITS_WEIGHT - splitAmt);

3) _split() will fail/revert on B, C will not be processed at all.

Tools Used

Remix

Recommended Mitigation Steps

We need to correct the way of calculating the split amount of a receiver as follows:

uint128 currSplitAmt =
                uint128((uint160(collectableAmt) * splitsWeight) / _TOTAL_SPLITS_WEIGHT;
xmxanuel commented 1 year ago

This is a misunderstanding how the formular is working with:

Testcase with your Example

CodeSandwich commented 1 year ago

[dispute validity] What Manuel said. Good job with recreating the PoC in code.

c4-sponsor commented 1 year ago

CodeSandwich marked the issue as sponsor disputed

c4-judge commented 1 year ago

GalloDaSballo marked the issue as unsatisfactory: Insufficient proof

GalloDaSballo commented 1 year ago

Always recommend adding a POC to avoid any miscommunication issue

Due to the POC from the sponsor disputing the submission, I must close