A critical vulnerability has been identified in the StarklaneEscrow contract, specifically within the _depositIntoEscrow function. This vulnerability could potentially lead to a reentrancy attack, allowing unauthorized users to exploit the contract and make unauthorized withdrawals. Vulnerability Details
The _depositIntoEscrow function in the StarklaneEscrow contract is vulnerable to reentrancy attacks due to insufficient precautions during calls to external contracts. This issue was uncovered through targeted fuzz testing, using a specially crafted test designed to trigger the vulnerability.
Copy the test and past into a folder inside the test folder:
Run forge test --match-contract FuzzEscrow -vvvvv
Output: `Ran 1 test for test/auidt-test/FuzzEscrow.sol:FuzzEscrowTest
[FAIL. Reason: revert: depositIntoEscrow failed; counterexample: calldata=0x93e9950600000000000000000009306a66185253f1f5eba73b204748b6dc3d732e5d00f8 args=[880143175889589974894851208048151919871194488578572536 [8.801e53]]] testFuzzDepositAndReentrancy(uint256) (runs: 0, μ: 0, ~: 0)
Traces:
[1216190] FuzzEscrowTest::setUp()
├─ [12666] → new StarklaneEscrow@0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f
│ └─ ← [Return] 63 bytes of code
├─ [1049460] → new TestERC721@0x2e234DAe75C793f67A35089C9d99245E1C58470b
│ └─ ← [Return] 4906 bytes of code
└─ ← [Stop]
[114298] FuzzEscrowTest::testFuzzDepositAndReentrancy(880143175889589974894851208048151919871194488578572536 [8.801e53])
├─ [47507] TestERC721::mint(0x0000000000000000000000000000000000000001, 880143175889589974894851208048151919871194488578572536 [8.801e53])
│ ├─ emit Transfer(from: 0x0000000000000000000000000000000000000000, to: 0x0000000000000000000000000000000000000001, tokenId: 880143175889589974894851208048151919871194488578572536 [8.801e53])
│ └─ ← [Stop]
├─ [0] VM::assume(true) [staticcall]
│ └─ ← [Return]
├─ [0] VM::startPrank(0x0000000000000000000000000000000000000001)
│ └─ ← [Return]
├─ [25147] TestERC721::approve(StarklaneEscrow: [0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f], 880143175889589974894851208048151919871194488578572536 [8.801e53])
│ ├─ emit Approval(owner: 0x0000000000000000000000000000000000000001, approved: StarklaneEscrow: [0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f], tokenId: 880143175889589974894851208048151919871194488578572536 [8.801e53])
│ └─ ← [Stop]
├─ [24] StarklaneEscrow::1c1887f5(00000000000000000000000000000000000000000000000000000000000000000000000000000000000000002e234dae75c793f67a35089c9d99245e1c58470b0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000100000000000000000009306a66185253f1f5eba73b204748b6dc3d732e5d00f8)
│ └─ ← [Revert]
├─ emit LogError(data: 0x)
└─ ← [Revert] revert: depositIntoEscrow failed´
During the setUp phase, the StarklaneEscrow and TestERC721 contracts were successfully deployed.
The test ran successfully until the depositIntoEscrow call failed with a revert.
The emitted error log indicates an issue during the execution of the depositIntoEscrow function within the StarklaneEscrow contract.
This issue exposes a critical vulnerability where a reentrancy attack can be performed.
High Impact:
Funds are directly at risk: Exploiting this vulnerability allows attackers to perform unauthorized withdrawals, directly putting user funds at jeopardy.
There's a severe disruption of protocol functionality or availability: A successful reentrancy attack could disrupt the functionality of the smart contract, impacting service availability.
Given the potential for significant financial losses and disruption to core functionality, this vulnerability is classified as High Impact.
Fuzz Testing in Foundry
Manual Review
One of the primary ways to mitigate reentrancy attacks is to apply the Check-Effects-Interactions pattern. This pattern involves:
Checks: Performing all necessary checks at the beginning of a function.
Effects: Updating the state of the contract immediately after the checks.
Interactions: Interacting with external contracts last, after all checks and state updates.
Implement Reentrancy Guard:
Use the ReentrancyGuard modifier from OpenZeppelin's contracts library to secure sensitive functions:
Input Validation:
Add rigorous input validation to ensure the function handles edge cases and large token IDs appropriately:
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.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.