TempleGold

TempleDAO
Foundry
25,000 USDC
View results
Submission Details
Severity: medium
Invalid

Lack of Zero Address Validation in `stakeFor` Function

Summary

The stakeFor function in the TempleGoldStaking contract lacks a check to prevent staking for the zero address. This oversight could lead to permanent loss of funds if tokens are accidentally or maliciously staked to the zero address.

Vulnerability Details

The stakeFor function allows users to stake tokens on behalf of another address. However, it does not validate that the recipient address (_for parameter) is not the zero address (0x0). As a result, it's possible to stake tokens for the zero address, which would effectively lock these tokens in the contract permanently, as there would be no way to withdraw them.

function stakeFor(address _for, uint256 _amount) public whenNotPaused {
if (_amount == 0) revert CommonEventsAndErrors.ExpectedNonZero();
// pull tokens and apply stake
stakingToken.safeTransferFrom(msg.sender, address(this), _amount);
uint256 _lastIndex = _accountLastStakeIndex[_for];
_accountLastStakeIndex[_for] = ++_lastIndex;
_applyStake(_for, _amount, _lastIndex);
_moveDelegates(address(0), delegates[_for], _amount);
}

Impact

The impact of this vulnerability is potentially severe. If tokens are staked to the zero address, they become irretrievable, resulting in a permanent loss of funds. This could occur due to user error or could be exploited maliciously. The financial impact would be directly proportional to the amount of tokens staked to the zero address.

Tools Used

Manual Review

Recommendations

To address this vulnerability, implement a zero address check at the beginning of the stakeFor function. Here's the recommended modification:

function stakeFor(address _for, uint256 _amount) public whenNotPaused {
if (_amount == 0) revert CommonEventsAndErrors.ExpectedNonZero();
if (_for == address(0)) revert CommonEventsAndErrors.InvalidAddress();
// Rest of the function remains the same
...
}

This check ensures that tokens cannot be staked for the zero address, preventing potential loss of funds.

Updates

Lead Judging Commences

inallhonesty Lead Judge 11 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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