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

Protocol can be repeatedly gas griefed in AutoRange external call #459

Open
c4-bot-7 opened this issue Mar 15, 2024 · 13 comments
Open

Protocol can be repeatedly gas griefed in AutoRange external call #459

c4-bot-7 opened this issue Mar 15, 2024 · 13 comments
Labels
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 downgraded by judge Judge downgraded the risk level of this issue M-02 primary issue Highest quality submission among a set of duplicates 🤖_29_group AI based duplicate group recommendation satisfactory satisfies C4 submission criteria; eligible for awards selected for report This submission will be included/highlighted in the audit report sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons sufficient quality report This report is of sufficient quality

Comments

@c4-bot-7
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2024-03-revert-lend/blob/435b054f9ad2404173f36f0f74a5096c894b12b7/src/transformers/AutoRange.sol#L111-L272

Vulnerability details

Summary

Revert controlled AutoRange bot can be gas griefed and execute() reverted by malicious onERC721Received implementation

Vulnerability Details

The initiator of a transaction pays the transaction gas; in the case of AutoRange::execute() and AutoRange::executeWithVault(), this will be a Revert controlled bot which is set up as an operator.
Newly minted NFTs are sent to users via NPM::safeTransferFrom() which uses the onERC721Received callback.
An attacker can implement a malicious implementation of this callback; waste all the transaction gas and revreting the function to grief the protocol.
It is expected that the gas spent by bots initiating transactions will be covered by protocol fees; however no protocol fees will be generated from the attacker's position as AutoRange::execute() will not complete; so the protocol will experience a loss.

Furthermore, once attacker has set the token's config from positionConfigs, the protocol has no way to stop the griefing occuring each time the bot detects that the tokenId meets the conditions for a Range Change.
Token Config is only removed from positionConfigs at the end of execute() which the gas grief will prevent from being reached making it a recurring attack.
The only recourse to the protocol is shutting down the contract completely by removing the bot address as an operator and DOSing the contract.

All this makes the likelihood of this attack quite high as it is a very inexpensive attack; user does not even need an open position and loan in the vault.
A determined attacker

POC

Attacker would need to create a malicious contract to which they send their NPM NFT.
Via this contract they can then add token config for this NFT to the AutoRange contract via AutoRange::configToken().
The malicious contract would need to have a malicious implementation such as the one below which uses as much gas as possible before reverting.

    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external override returns (bytes4) {

    uint256 initialGas = gasleft();
    uint256 counter = 0;

    // Loop until only small amount gas is left for the revert
    uint256 remainingGasThreshold = 5000;

    while(gasleft() > remainingGasThreshold) {

        counter += 1;
    }

    // Explicitly revert transcation
    revert("Consumed the allotted gas");
        
    }

Impact

Protocol fees can be completely drained; particularly if a determined attacker sets token configs for multiple NFTs in AutoRange all linked to the same malicious contract.
Lack of fees can DOS multiple functions like the bot initiated AutoRange functions and affect the protocol's profitability by draining fees.

Tools Used

Manual Review
Foundry Testing

Recommendations

Enact a pull mechanism by transferring the newly minted NFT to a protocol owned contract such as the AutoRange contract itself from where the user initiates the transaction to transfer the NFT to themselves.

Assessed type

Other

@c4-bot-7 c4-bot-7 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Mar 15, 2024
c4-bot-7 added a commit that referenced this issue Mar 15, 2024
@c4-bot-12 c4-bot-12 added the 🤖_29_group AI based duplicate group recommendation label Mar 15, 2024
@c4-pre-sort
Copy link

0xEVom marked the issue as sufficient quality report

@c4-pre-sort c4-pre-sort added sufficient quality report This report is of sufficient quality primary issue Highest quality submission among a set of duplicates labels Mar 20, 2024
@c4-pre-sort
Copy link

0xEVom marked the issue as primary issue

@0xEVom
Copy link

0xEVom commented Mar 20, 2024

Grouping all gas griefing submissions under this but note that there are multiple versions of it:

@c4-sponsor c4-sponsor added the sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons label Mar 26, 2024
@c4-sponsor
Copy link

kalinbas (sponsor) acknowledged

@kalinbas
Copy link

kalinbas commented Mar 26, 2024

All these cases are possible but we are monitoring these off-chain bots and also implement gas-limiting, and taking action where needed.

@jhsagd76
Copy link

valid gas grief, but not a persistent dos, so M

@c4-judge c4-judge added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value downgraded by judge Judge downgraded the risk level of this issue and removed 3 (High Risk) Assets can be stolen/lost/compromised directly labels Mar 31, 2024
@c4-judge
Copy link

jhsagd76 changed the severity to 2 (Med Risk)

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Mar 31, 2024
@c4-judge
Copy link

jhsagd76 marked the issue as satisfactory

@c4-judge c4-judge added the selected for report This submission will be included/highlighted in the audit report label Apr 1, 2024
@c4-judge
Copy link

c4-judge commented Apr 1, 2024

jhsagd76 marked the issue as selected for report

@Qormatic
Copy link

Qormatic commented Apr 2, 2024

Hi @jhsagd76,

When user adds their position's config details via configToken(); the positionConfigs mapping is updated accordingly.
From what i can see, there is no way to remove that config apart from at the end of execute().
Everytime the parameters defined in positionConfigs are met, the bot will call execute(), get griefed and user's token config will remain in state.
A malicious user can set up multiple positionConfigs to grief with many different parameter trigger points and the only recourse would be the shutting down of the AutoRange contract.
Once a new contract is set up of course the exact same thing can be done again so I think it's a strong case for a full DOS of this part of the protocol's functionality and loss of funds for the protocol which would be more than dust.

@kalinbas
Copy link

kalinbas commented Apr 2, 2024

The logic which positions to execute is the responsability of the bot. If there are worthless tokens detected or the tx simulation is not what expected the bot doesn't execute the operation. So this is a risk which is controlled off-chain.

@Qormatic
Copy link

Qormatic commented Apr 2, 2024

How would that work? It doesn't seem possible to foresee getting griefed at least the first time and after that would the tokenId be blacklisted to prevent further griefing which necessitates the shutting down of the contract?

Also, the mitigation of bots monitoring the contract is not documented under the list of known issues of the Contest's README so i think it's fair to flag this issue and leave up to the judge to decide if mitigation can be applied retrospectively after the contest.

@jhsagd76
Copy link

jhsagd76 commented Apr 4, 2024

I cannot understand what the warden is referring to with the "shutting down of the AutoRange contract". There is no reason for the operator to waste gas on a transaction that continuously fails. Gas griefing is valid, and it will indeed continue to deplete the resources of the off-chain operator, but this does not constitute a substantial DoS. For predictions on any future actions/deployments, please refer to code-423n4/org#72 .

@C4-Staff C4-Staff added the M-02 label Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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 downgraded by judge Judge downgraded the risk level of this issue M-02 primary issue Highest quality submission among a set of duplicates 🤖_29_group AI based duplicate group recommendation satisfactory satisfies C4 submission criteria; eligible for awards selected for report This submission will be included/highlighted in the audit report sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons sufficient quality report This report is of sufficient quality
Projects
None yet
Development

No branches or pull requests

10 participants