sherlock-audit / 2024-01-napier-judging

8 stars 5 forks source link

Rhaydden - Precision handling and division by zero in BaseLSTAdapter.sol #109

Closed sherlock-admin closed 5 months ago

sherlock-admin commented 5 months ago

Rhaydden

medium

Precision handling and division by zero in BaseLSTAdapter.sol

Summary

There are issues related to precision handling and division by zero, which could lead to unexpected behavior or errors in the BaseLSTAdapter.sol

Vulnerability Detail

  1. Precision and Division by Zero: Division operations without checks for division by zero. This could lead to a revert if totalAssets() or BUFFER_PERCENTAGE_PRECISION returns zero. Additionally, precision loss may occur due to integer division in Solidity, which could affect the accuracy of calculations like targetBufferEth.
  2. Precision in Calculating targetBufferEth: The calculation of targetBufferEth involves division, which could lead to precision loss. This is particularly concerning because the calculation is critical for managing the buffer's size, which directly affects the system's behavior.

Impact

  1. If division by zero occurs, the contract could revert unexpectedly. This could disrupt operations and potentially lead to loss of funds.
  2. Precision loss in calculating targetBufferEth could result in the buffer not being managed accurately. This could affect the contract's ability to maintain the desired buffer size, potentially leading to suboptimal performance or even financial losses.

Code Snippet

https://github.com/sherlock-audit/2024-01-napier/blob/main/napier-v1/src/adapters/BaseLSTAdapter.sol#L100

Tool used

Manual Review

Recommendation

  1. Implement checks to ensure that totalAssets() and BUFFER_PERCENTAGE_PRECISION are never zero before performing the division. Use a conditional statement to check for zero values before the division operation.
  2. Manage the values used in the calculation of targetBufferEth to avoid extreme values that could lead to imprecise results. This could involve ensuring that totalAssets(), assets, and targetBufferPercentage are within expected ranges.