Liquid Staking

Stakelink
DeFiHardhatOracle
50,000 USDC
View results
Submission Details
Severity: medium
Invalid

contracts/core/sdlPool/LinearBoostController.sol

Your Solidity code for the LinearBoostController contract is generally well-structured and adheres to common Solidity practices, but there are some potential vulnerabilities and areas for improvement to consider:

1. Integer Overflow/Underflow

While Solidity 0.8.0 and later versions automatically check for overflow and underflow in arithmetic operations, it’s good practice to validate inputs. However, your use of uint64 for locking durations and maxBoost could lead to unexpected results if not properly constrained.

2. Input Validation

  • Zero Locking Duration: The getBoostAmount function currently allows _lockingDuration to be 0, but it is only checked against minLockingDuration. Consider explicitly checking for this in the require statement or reverting if it is 0 since the comment suggests it should be non-zero.

  • Max Boost Validation: There is no validation on maxBoost in the setMaxBoost function. It should be ensured that the new boost value does not exceed a reasonable limit to prevent unwanted behaviors.

3. Constructor Validation

There are no checks in the constructor for valid ranges:

  • Ensure that _minLockingDuration is non-zero.

  • Ensure that _maxLockingDuration is greater than or equal to _minLockingDuration.

  • Validate _maxBoost to ensure it is a sensible value.

4. Event Emissions for State Changes

While you're correctly emitting events for state changes in setter functions, it would be beneficial to emit an event in the getBoostAmount function as well for traceability, especially in more complex systems.

5. Access Control Considerations

The contract uses Ownable, which is good for restricting access. However, consider potential future enhancements where you might want more granular access control rather than just an owner. For instance, using roles may provide more flexibility.

6. Gas Optimization

Consider using uint256 instead of uint64 for all the state variables since most computations and storage in Ethereum are optimized for uint256. This can reduce complexity when interacting with other contracts or libraries that expect uint256.

7. Reentrancy Considerations

Although your current implementation does not involve state-changing functions that interact with external contracts (like token transfers), always be cautious of reentrancy attacks if you later add features that do. You might consider using checks-effects-interactions pattern if you introduce external calls.

8. Default Values for minLockingDuration, maxLockingDuration, and maxBoost

Make sure these values have sensible defaults or are properly set upon contract deployment. If left uninitialized, they will default to 0, which may lead to unintended behavior.

Suggested Modifications

Here’s how you could modify the constructor and getBoostAmount function to include additional validation:

constructor(uint64 _minLockingDuration, uint64 _maxLockingDuration, uint64 _maxBoost) {
require(_minLockingDuration > 0, "Min locking duration must be non-zero");
require(_maxLockingDuration >= _minLockingDuration, "Max locking duration must be >= min locking duration");
require(_maxBoost > 0, "Max boost must be positive");
minLockingDuration = _minLockingDuration;
maxLockingDuration = _maxLockingDuration;
maxBoost = _maxBoost;
}
function getBoostAmount(
uint256 _amount,
uint64 _lockingDuration
) external view returns (uint256) {
require(_lockingDuration > 0, "Locking duration must be non-zero");
if (
(_lockingDuration < minLockingDuration) ||
(_lockingDuration > maxLockingDuration)
) revert InvalidLockingDuration();
return
(_amount * uint256(maxBoost) * uint256(_lockingDuration)) / uint256(maxLockingDuration);
}

By implementing these checks and considerations, you can enhance the security and robustness of your smart contract.

Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Lack of quality

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!