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

wrong implement of getPositionsForCurator #232

Open
howlbot-integration bot opened this issue Sep 6, 2024 · 3 comments
Open

wrong implement of getPositionsForCurator #232

howlbot-integration bot opened this issue Sep 6, 2024 · 3 comments
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-72 grade-a Q-29 QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 🤖_59_group AI based duplicate group recommendation satisfactory satisfies C4 submission criteria; eligible for awards sufficient quality report This report is of sufficient quality

Comments

@howlbot-integration
Copy link

Lines of code

https://github.com/code-423n4/2024-08-phi/blob/main/src/Cred.sol#L513

Vulnerability details

Impact

Detailed description of the impact of this finding.

wrong implement of getPositionsForCurator as we are doing
credIds[i] = credId;
@> amounts[i] = amount;

instead of credIds[index] = credId;
@> amounts[index] = amount;

Proof of Concept

Provide direct links to all referenced code in GitHub. Add screenshots, logs, or any other relevant proof that illustrates the concept.

function getPositionsForCurator(
address curator_,
uint256 start_,
uint256 stop_
)
external
view
returns (uint256[] memory credIds, uint256[] memory amounts)
{
uint256[] storage userCredIds = credIdsPerAddress[curator];

    uint256 stopIndex;
    if (userCredIds.length == 0) {
        return (credIds, amounts);
    }
    if (stop_ == 0 || stop_ > userCredIds.length) {
        stopIndex = userCredIds.length;
    } else {
        stopIndex = stop_;
    }

    if (start_ >= stopIndex) {
        revert InvalidPaginationParameters();
    }

    credIds = new uint256[](stopIndex - start_);
    amounts = new uint256[](stopIndex - start_);

    uint256 index = 0;
    for (uint256 i = start_; i < stopIndex; i++) {
        uint256 credId = userCredIds[i];
        if (_credIdExistsPerAddress[curator_][credId]) {
            uint256 amount = shareBalance[credId].get(curator_);
          @>  credIds[i] = credId;
          @>  amounts[i] = amount;
            index++;
        }
    }
    // Resize the result array to remove unused slots
    assembly {
       mstore(credIds, index)
       mstore(amounts, index)
    }
}

Tools Used

Recommended Mitigation Steps

function getPositionsForCurator(
address curator_,
uint256 start_,
uint256 stop_
)
external
view
returns (uint256[] memory credIds, uint256[] memory amounts)
{
uint256[] storage userCredIds = credIdsPerAddress[curator];

    uint256 stopIndex;
    if (userCredIds.length == 0) {
        return (credIds, amounts);
    }
    if (stop_ == 0 || stop_ > userCredIds.length) {
        stopIndex = userCredIds.length;
    } else {
        stopIndex = stop_;
    }

    if (start_ >= stopIndex) {
        revert InvalidPaginationParameters();
    }

    credIds = new uint256[](stopIndex - start_);
    amounts = new uint256[](stopIndex - start_);

    uint256 index = 0;
    for (uint256 i = start_; i < stopIndex; i++) {
        uint256 credId = userCredIds[i];
        if (_credIdExistsPerAddress[curator_][credId]) {
            uint256 amount = shareBalance[credId].get(curator_);
        @>    credIds[index] = credId;
        @>    amounts[index] = amount;
            index++;
        }
    }
    // Resize the result array to remove unused slots
    assembly {
        mstore(credIds, index)
        mstore(amounts, index)
    }
}

Assessed type

Context

@howlbot-integration howlbot-integration bot added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value 🤖_59_group AI based duplicate group recommendation bug Something isn't working duplicate-72 sufficient quality report This report is of sufficient quality labels Sep 6, 2024
howlbot-integration bot added a commit that referenced this issue Sep 6, 2024
@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Sep 13, 2024
@c4-judge
Copy link
Contributor

fatherGoose1 marked the issue as satisfactory

@c4-judge c4-judge removed the 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value label Sep 18, 2024
@c4-judge
Copy link
Contributor

fatherGoose1 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-a labels Sep 18, 2024
@c4-judge
Copy link
Contributor

fatherGoose1 marked the issue as grade-a

@C4-Staff C4-Staff reopened this Sep 24, 2024
@C4-Staff C4-Staff added the Q-29 label Sep 24, 2024
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-72 grade-a Q-29 QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 🤖_59_group AI based duplicate group recommendation satisfactory satisfies C4 submission criteria; eligible for awards sufficient quality report This report is of sufficient quality
Projects
None yet
Development

No branches or pull requests

2 participants