Skip to content
DoS Audit finding Intermediate

Unbounded loop in _removeNft could lead to a griefing/DOS attack

The vault's _removeNft function loops over a single shared array of NFTs until it finds the one to remove, and anyone can push NFTs into that array through the permission-less onERC721Received callback. A malicious NFT contract could flood the array and then revert on every transfer, so other users' unlock and transfer transactions consume huge amounts of gas or fail outright.

shw Follow

Originally disclosed on Code4rena

Submitted by shw, also found by cmichel, gpersoon, pauliax, Sherlock, and toastedsteaksandwhich

Griefing/DOS attack is possible when a malicious NFT contract sends many NFTs to the vault, which could cause excessive gas consumed and even transactions reverted when other users are trying to unlock or transfer NFTs.

The function _removeNft uses an unbounded loop, which iterates the array nfts until a specific one is found. If the NFT to be removed is at the very end of the nfts array, this function could consume a large amount of gas. The function onERC721Received is permission-less. The vault accepts any NFTs from any NFT contract and pushes the received NFT into the array nfts. A malicious user could write an NFT contract, which calls onERC721Received of the vault many times to make the array nfts grow to a large size. Besides, the malicious NFT contract reverts when anyone tries to transfer (e.g., safeTransferFrom) its NFT. The vault then has no way to remove the transferred NFT from the malicious NFT contract. The two only functions to remove NFTs, transferERC721 and timeUnlockERC721, fail since the malicious NFT contract reverts all safeTransferFrom calls. As a result, benign users who unlock or transfer NFTs would suffer from large and unnecessary gas consumption. The consumed gas could even exceed the block gas limit and cause the transaction to fail every time.

Recommend using a mapping (e.g., mapping(address=>Nft[]) nfts) to store the received NFTs into separate arrays according to nftContract instead of putting them into the same one. Or, add a method specifically for the owner to remove NFTs from the nfts array directly.

xyz-ctrl (Visor) confirmed:

sponsor confirmed We are working to mitigate this issue in our next upgrade

ghoul-sol (Judge) commented:

I’m making this high severity because it doesn’t need a malicious actor to happen. This can happen by simply being very successful

xyz-ctrl (Visor) commented:

Agreed. We merged a pr with mitigations a few weeks ago here VisorFinance/visor-core#2

ghoul-sol (Judge) commented:

Duplicate of #66

ztcrypto (Visor) patched:

duplicated and patched link

The original report as published on Code4rena, by shw. 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 design stores all received NFTs in one shared array and finds entries by linear scan, with no cap on array growth and no way to remove an entry without a successful transfer.

Impact

Unlock and transfer transactions could consume large amounts of gas or exceed the block gas limit and fail every time, and the judge noted this could also happen simply through heavy legitimate use.

What the attacker needed

Attacker can deploy an NFT contract; vault accepts NFTs from any contract

The fix

The project merged mitigations and later patched the issue; the report recommends storing NFTs in per-contract arrays via a mapping or giving the owner a direct way to remove entries from the array.

How it was found

  1. Deploy a malicious NFT contract that calls the vault's onERC721Received many times to grow the nfts array
  2. Make the malicious contract revert on any safeTransferFrom of its NFTs so they cannot be removed
  3. Observe that transferERC721 and timeUnlockERC721 fail or consume excessive gas for benign users

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.

A smart contract here keeps every NFT it receives in one long list. To remove an item it walks the list from the start until it finds the right one, so a very long list makes every removal slow and expensive. Because anyone can add items to the list, an attacker can make it enormous and effectively jam the vault for everyone else.

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 shw

View all

22 more disclosed reports, best first.

More from Visor Finance

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.