hats-finance / StakeWise-0xd91cd6ed6c9a112fdc112b1a3c66e47697f522cd

Liquid staking protocol for Ethereum
Other
0 stars 0 forks source link

Incorrect calculation of shares for the fee receive #107

Open hats-bug-reporter[bot] opened 1 year ago

hats-bug-reporter[bot] commented 1 year ago

Github username: @0xmahdirostami Submission hash (on-chain): 0x75be549b866a04a89b15b940f9dbb02891d0089e67530973cbe15f1adc7461fa Severity: low

Description: Description\

In deposit function :

    // calculate amount of shares to mint
    shares = _convertToShares(assets, Math.Rounding.Up);

BUT in _processTotalAssetsDelta function:

    // calculate fee recipient's shares
    uint256 feeRecipientShares;
    if (totalShares == 0) {
      feeRecipientShares = feeRecipientAssets;
    } else {
      unchecked {
        feeRecipientShares = Math.mulDiv(
          feeRecipientAssets,
          totalShares,
          newTotalAssets - feeRecipientAssets
        );
      }
    }

Math.mulDiv Calculates floor(x * y / denominator). So shares are calculated differently for the fee receiver.

Impact\

wrong calculation of shares for the fee received. As the the difference in calculations, I think it's low severity.

Attachments

  1. Proof of Concept (PoC) File

  2. Revised Code File (Optional)

         feeRecipientShares = Math.mulDiv(
           feeRecipientAssets,
           totalShares,
           newTotalAssets - feeRecipientAssets,
    +          Math.Rounding.Up
         );
       }
     }
tsudmi commented 1 year ago

We round up only for user, because we don't want him to deposit 1 ETH and see 0.99999... ETH in the UI, otherwise we round down.