Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The constructor assume 18 decimals for underlying token incorrectly due to low-level static call fails #58

Closed
c4-bot-9 opened this issue Mar 8, 2024 · 6 comments
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-172 grade-c QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 🤖_25_group AI based duplicate group recommendation sufficient quality report This report is of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@c4-bot-9
Copy link
Contributor

c4-bot-9 commented Mar 8, 2024

Lines of code

https://github.com/code-423n4/2024-03-pooltogether/blob/480d58b9e8611c13587f28811864aea138a0021a/pt-v5-vault/src/PrizeVault.sol#L304-L305
https://github.com/code-423n4/2024-03-pooltogether/blob/480d58b9e8611c13587f28811864aea138a0021a/pt-v5-vault/src/PrizeVault.sol#L772-L783

Vulnerability details

Impact

PrizeVault::_underlyingDecimals sets to 18 decimals incorrectly when low-level static call in function PrizeVault::_tryGetAssetDecimals() fails due to reasons like insufficient gas / target contract deployment failure, etc.

Proof of Concept

function _tryGetAssetDecimals(IERC20 asset_) internal view returns (bool, uint8) {
    (bool success, bytes memory encodedDecimals) = address(asset_).staticcall(
        abi.encodeWithSelector(IERC20Metadata.decimals.selector)
    );
    if (success && encodedDecimals.length >= 32) {
        uint256 returnedDecimals = abi.decode(encodedDecimals, (uint256));
        if (returnedDecimals <= type(uint8).max) {
            return (true, uint8(returnedDecimals));
        }
    }
    return (false, 0);
}

When (bool success, bytes memory encodedDecimals) = address(asset_).staticcall( abi.encodeWithSelector(IERC20Metadata.decimals.selector) ); fails due to reasons mentioned above, return (false, 0);

In constructor call :

(bool success, uint8 assetDecimals) = _tryGetAssetDecimals(asset_);
        _underlyingDecimals = success ? assetDecimals : 18;

PrizeVault::_underlyingDecimals sets to 18 decimals while other token does not have 18 decimals.

Tools Used

Manual Review

Recommended Mitigation Steps

  1. Eliminate PrizeVault::_tryGetAssetDecimals()
  2. adding _underlyingDecimals = asset_.decimals() in constructor;
constructor(
    string memory name_,
    string memory symbol_,
    IERC4626 yieldVault_,
    PrizePool prizePool_,
    address claimer_,
    address yieldFeeRecipient_,
    uint32 yieldFeePercentage_,
    uint256 yieldBuffer_,
    address owner_
)
    TwabERC20(name_, symbol_, prizePool_.twabController())
    Claimable(prizePool_, claimer_)
    Ownable(owner_)
{
    if (address(yieldVault_) == address(0)) revert YieldVaultZeroAddress();
    if (owner_ == address(0)) revert OwnerZeroAddress();

    IERC20 asset_ = IERC20(yieldVault_.asset());
    (bool success, uint8 assetDecimals) = _tryGetAssetDecimals(asset_);
-       _underlyingDecimals = success ? assetDecimals : 18;
+       _underlyingDecimals = asset_.decimals();
    _asset = asset_;

    yieldVault = yieldVault_;
    yieldBuffer = yieldBuffer_;

    _setYieldFeeRecipient(yieldFeeRecipient_);
    _setYieldFeePercentage(yieldFeePercentage_);
}

Assessed type

Decimal

@c4-bot-9 c4-bot-9 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Mar 8, 2024
c4-bot-9 added a commit that referenced this issue Mar 8, 2024
@c4-bot-12 c4-bot-12 added the 🤖_25_group AI based duplicate group recommendation label Mar 11, 2024
@c4-pre-sort c4-pre-sort added the sufficient quality report This report is of sufficient quality label Mar 12, 2024
@c4-pre-sort
Copy link

raymondfam marked the issue as sufficient quality report

@c4-pre-sort
Copy link

raymondfam marked the issue as duplicate of #25

@c4-pre-sort
Copy link

raymondfam marked the issue as duplicate of #172

@c4-judge
Copy link
Contributor

hansfriese marked the issue as satisfactory

@c4-judge c4-judge added satisfactory satisfies C4 submission criteria; eligible for awards and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Mar 15, 2024
@c4-judge
Copy link
Contributor

hansfriese changed the severity to QA (Quality Assurance)

@c4-judge c4-judge added downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax grade-c unsatisfactory does not satisfy C4 submission criteria; not eligible for awards and removed satisfactory satisfies C4 submission criteria; eligible for awards labels Mar 20, 2024
@c4-judge
Copy link
Contributor

hansfriese marked the issue as grade-c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-172 grade-c QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 🤖_25_group AI based duplicate group recommendation sufficient quality report This report is of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

4 participants