Skip to content

max deposit check works wrong #20

@c4-bot-6

Description

@c4-bot-6

Lines of code

https://github.com/code-423n4/2024-05-bakerfi/blob/main/contracts/core/Vault.sol#L214

Vulnerability details

Proof of Concept

User are restricted to not deposit more than settings().getMaxDepositInETH() to the Vault.

In order to check which amount user deposited they sum msg.value + currentDepositedValue.

To calculate user's current position they call _tokenPerETH(maxPriceAge).
https://github.com/code-423n4/2024-05-bakerfi/blob/main/contracts/core/Vault.sol#L334-L340

    function _tokenPerETH(uint256 priceMaxAge) internal view returns (uint256) {
        uint256 position = _totalAssets(priceMaxAge);
        if (totalSupply() == 0 || position == 0) {
            return 1 ether;
        }
        return (totalSupply() * 1 ether) / position;
    }

This function calculates how many Vault tokens should be paid for ETH, but what we need to check max deposit breach is how many ETH 1 vault token costs.
As a result, max deposit check will work incorrectly.

Impact

Max deposit check will work incorrectly.

Tools Used

VsCode

Recommended Mitigation Steps

Use 1/_tokenPerETH() as Vault token price.

Assessed type

Error

Metadata

Metadata

Assignees

No one assigned

    Labels

    2 (Med Risk)Assets not at direct risk, but function/availability of the protocol could be impacted or leak value🤖_08_groupAI based duplicate group recommendationbugSomething isn't workingduplicate-29satisfactorysatisfies C4 submission criteria; eligible for awards

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions