Skip to content
DoS Audit finding Intermediate

Protocol can be repeatedly gas griefed in AutoRange external call

A malicious contract implementing the ERC721 receive callback can burn all gas and revert when the AutoRange bot transfers a newly minted NFT to it, causing the bot's execute transaction to fail. Because the token config is only cleared at the end of execute, the griefing can repeat and drain the off-chain operator's gas budget.

falconhoof Follow with ktg and novamanbg

Originally disclosed on Code4rena

Submitted by falconhoof, also found by ktg and novamanbg

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, by wasting all the transaction gas and reverting 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 an attacker has set the token’s config from positionConfigs, the protocol has no way to stop the griefing occurring 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

An 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 transaction
    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

Foundry Testing

Recommended Mitigation Steps

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.

kalinbas (Revert) acknowledged and commented:

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

ronnyx2017 (judge) decreased severity to Medium and commented:

valid gas grief, but not a persistent dos, so Medium.

falconhoof (warden) commented:

@ronnyx2017 - When a 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 (Revert) commented:

The logic which positions to execute is the responsibility 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.

falconhoof (warden) commented:

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. 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 audit.

ronnyx2017 (judge) commented:

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 this org issue.


The original report as published on Code4rena, by falconhoof. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the protocol pushes NFTs to user-controlled addresses via safeTransferFrom inside the bot's execute flow, so a hostile receiver callback can consume gas and revert the whole transaction before state cleanup runs.

Impact

The off-chain operator's gas can be repeatedly wasted, which may deplete protocol fees and disrupt bot-driven AutoRange functions; the judge rated it a valid gas grief but not a persistent denial of service, and the team says off-chain monitoring and gas limiting reduce the risk.

What the attacker needed

No open position or vault loan needed; attacker deploys a malicious contract; attacker registers token config via configToken

The fix

The report recommends a pull mechanism where the NFT is first sent to a protocol-owned contract and the user later pulls it to themselves.

How it was found

  1. Attacker deploys a contract with a malicious onERC721Received that burns gas and reverts.
  2. Attacker sends their NPM NFT to that contract.
  3. Attacker calls configToken on AutoRange to register the token config.
  4. When the bot detects the trigger conditions, it calls execute and the transfer to the malicious contract reverts the transaction.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When a contract sends an NFT to another address, it calls a small function on the receiving side to confirm the transfer. Here the receiver is written to use up all the gas and then fail, so the bot's whole transaction is wasted. The bot pays for that gas, so the attacker makes the protocol lose money without spending much.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by falconhoof

View all

4 more disclosed reports, best first.

More from Revert Lend

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.