NFTBridge
60,000 USDC
View results
Submission Details
Severity: medium
Invalid

Re-Entrancy Vulnerability found in Withdraw function in Escrow contract

Summary

The escrow contract contains a reentrancy vulnerability that allows an attacker to withdraw tokens during the deposit process, potentially leading to unauthorized access and theft of assets.

Vulnerability Details

The _withdrawFromEscrow function lacks proper reentrancy protection. This flaw allows an attacker to call the withdrawFromEscrow function during the execution of the depositIntoEscrow function, leading to unexpected behavior and unauthorized withdrawal of tokens.

Impact

An attacker can exploit this vulnerability to drain assets from the escrow contract by re-entering the contract during the deposit phase. This could result in significant financial loss for the users of the contract.

Tools Used

Manual Review

PoC (Proof of Concept)

Place this test in your Escrow.t.sol file :

  1. Minting Tokens: Alice mints 10 ERC721 tokens (IDs 0-9) to her account.

  2. Prepare Tokens for Deposit: Alice prepares two token IDs (5 and 8) for deposit into the escrow contract.

  3. Start Prank: The testing framework's prank feature is activated to simulate Alice's actions.

  4. Deposit Tokens: Alice deposits the selected tokens (IDs 5 and 8) into the escrow contract.

  5. Reentrancy Exploit: During the deposit, the withdrawFromEscrow function is called to withdraw token ID 5 to Bob's account.

  6. Result: Token ID 5 is transferred to Bob, showing that an unauthorized withdrawal occurred during the deposit.

function testFail_reentrancyAttack() public {
IERC721MintRangeFree(erc721).mintRangeFree(alice, 0, 10);
uint256;
ids[0] = 5;
ids[1] = 8;
vm.startPrank(alice);
// The initial owner of the token
console.log("Address of Alice is : ", address(alice));
console.log("Owner of token ID 5:", IERC721(erc721).ownerOf(5));
escrow.depositIntoEscrow(CollectionType.ERC721, erc721, ids);
// Withdrawing during deposit
escrow.withdrawFromEscrow(CollectionType.ERC721, erc721, bob, 5);
// The owner of the token changes
console.log("Owner of token ID 5:", IERC721(erc721).ownerOf(5));
console.log("Address of Bob is : ", address(bob));
vm.stopPrank();
}

Recommendations

  1. To mitigate this vulnerability, implement a reentrancy guard on the withdrawFromEscrow function. This can be done by using the nonReentrant modifier provided by libraries like OpenZeppelin or by implementing a custom reentrancy guard to ensure that no reentrant calls can be made during sensitive operations.

  2. Use a CEI(Checks Effects Interactions) Pattern for writing code.

Updates

Lead Judging Commences

n0kto Lead Judge 9 months ago
Submission Judgement Published
Invalidated
Reason: Lack of quality
Assigned finding tags:

finding-withdraw-reentrancy-creates-unbridgeable-tokens

Impact: - NFT already bridged won’t be bridgeable anymore without being stuck. Likelyhood: Low. - Attackers will corrupt their own tokens, deploying a risky contract interacting with an upgradable proxy. They have to buy and sell them without real benefits, except being mean. Some really specific and rare scenario can also trigger that bug.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.