Dataset Viewer
Auto-converted to Parquet Duplicate
Title
stringclasses
3 values
Function_Vulnerability
stringclasses
3 values
Description
stringclasses
3 values
Severity
stringclasses
2 values
POC_Foundry_Hardhat
stringclasses
2 values
Recommended
stringclasses
3 values
User could withdraw more than supposed to, forcing last user withdraw to fail
function _executeWithdrawal( MarketState memory state, address accountAddress, uint32 expiry, uint baseCalldataSize ) internal returns (uint256) { WithdrawalBatch memory batch = _withdrawalData.batches[expiry]; // If the market is closed, allow withdrawal prior to expiry. if (expiry >= block.timestamp && !state.isClosed) { revert_WithdrawalBatchNotExpired(); } AccountWithdrawalStatus storage status = _withdrawalData.accountStatuses[expiry][ accountAddress ]; uint128 newTotalWithdrawn = uint128( MathUtils.mulDiv(batch.normalizedAmountPaid, status.scaledAmount, batch.scaledTotalAmount) ); uint128 normalizedAmountWithdrawn = newTotalWithdrawn - status.normalizedAmountWithdrawn; if (normalizedAmountWithdrawn == 0) revert_NullWithdrawalAmount(); hooks.onExecuteWithdrawal(accountAddress, normalizedAmountWithdrawn, state, baseCalldataSize); status.normalizedAmountWithdrawn = newTotalWithdrawn; state.normalizedUnclaimedWithdrawals -= normalizedAmountWithdrawn; if (_isSanctioned(accountAddress)) { // Get or create an escrow contract for the lender and transfer the owed amount to it. // They will be unable to withdraw from the escrow until their sanctioned // status is lifted on Chainalysis, or until the borrower overrides it. address escrow = _createEscrowForUnderlyingAsset(accountAddress); asset.safeTransfer(escrow, normalizedAmountWithdrawn); // Emit `SanctionedAccountWithdrawalSentToEscrow` event using a custom emitter. emit_SanctionedAccountWithdrawalSentToEscrow( accountAddress, escrow, expiry, normalizedAmountWithdrawn ); } else { asset.safeTransfer(accountAddress, normalizedAmountWithdrawn); } emit_WithdrawalExecuted(expiry, accountAddress, normalizedAmountWithdrawn); return normalizedAmountWithdrawn; }
Within Wildcat, withdraw requests are put into batches. Users first queue their withdraws and whenever there’s sufficient liquidity, they’re filled at the current rate. Usually, withdraw requests are only executable after the expiry passes and then all users within the batch get a cut from the batch.normalizedAmountPaid proportional to the scaled amount they’ve requested a withdraw for. uint128 newTotalWithdrawn = uint128( MathUtils.mulDiv(batch.normalizedAmountPaid, status.scaledAmount, batch.scaledTotalAmount) ); This makes sure that the sum of all withdraws doesn’t exceed the total batch.normalizedAmountPaid. However, this invariant could be broken, if the market is closed as it allows for a batch’s withdraws to be executed, before all requests are added. Consider the market is made of 3 lenders - Alice, Bob and Laurence. Alice queues a larger withdraw with an expiry time 1 year in the future. Market gets closed. Alice executes her withdraw request at the current rate. Bob makes queues multiple smaller requests. As they’re smaller, the normalized amount they represent suffers higher precision loss. Because they’re part of the whole batch, they also slightly lower the batch’s overall rate. Bob executes his requests. Laurence queues a withdraw for his entire amount. When he attempts to execute it, it will fail. This is because Alice has executed her withdraw at a higher rate than the current one and there’s now insufficient state.normalizedUnclaimedWithdrawals Note: marking this as High severity as it both could happen intentionally (attacker purposefully queuing numerous low-value withdraws to cause rounding down) and also with normal behaviour in high-value closed access markets where a user’s withdraw could easily be in the hundreds of thousands. Also breaks core invariant: The sum of all transfer amounts for withdrawal executions in a batch must be less than or equal to batch.normalizedAmountPaid
High
function test_deadrosesxyzissue() external { parameters.annualInterestBips = 3650; _deposit(alice, 1e18); _deposit(bob, 0.5e18); address laurence = address(1337); _deposit(laurence, 0.5e18); fastForward(200 weeks); vm.startPrank(borrower); asset.approve(address(market), 10e18); asset.mint(borrower, 10e18); vm.stopPrank(); vm.prank(alice); uint32 expiry = market.queueFullWithdrawal(); // alice queues large withdraw vm.prank(borrower); market.closeMarket(); // market is closed market.executeWithdrawal(alice, expiry); // alice withdraws at the current rate vm.startPrank(bob); for (uint i; i < 10; i++) { market.queueWithdrawal(1); // bob does multiple small withdraw requests just so they round down the batch's overall rate } market.queueFullWithdrawal(); vm.stopPrank(); vm.prank(laurence); market.queueFullWithdrawal(); market.executeWithdrawal(bob, expiry); // bob can successfully withdraw all of his funds vm.expectRevert(); market.executeWithdrawal(laurence, expiry); // laurence cannot withdraw his funds. Scammer get scammed. }
Although it’s not a clean fix, consider adding a addNormalizedUnclaimedRewards function which can only be called after a market is closed. It takes token from the user and increases the global variable state.normalizedUnclaimedRewards. The invariant would remain broken, but it will make sure no funds are permanently stuck.
Users are incentivized to not withdraw immediately after the market is closed
function _applyWithdrawalBatchPayment( WithdrawalBatch memory batch, MarketState memory state, uint32 expiry, uint256 availableLiquidity ) internal returns (uint104 scaledAmountBurned, uint128 normalizedAmountPaid) { uint104 scaledAmountOwed = batch.scaledTotalAmount - batch.scaledAmountBurned; // Do nothing if batch is already paid if (scaledAmountOwed == 0) return (0, 0); uint256 scaledAvailableLiquidity = state.scaleAmount(availableLiquidity); scaledAmountBurned = MathUtils.min(scaledAvailableLiquidity, scaledAmountOwed).toUint104(); // Use mulDiv instead of normalizeAmount to round `normalizedAmountPaid` down, ensuring // it is always possible to finish withdrawal batches on closed markets. normalizedAmountPaid = MathUtils.mulDiv(scaledAmountBurned, state.scaleFactor, RAY).toUint128(); batch.scaledAmountBurned += scaledAmountBurned; batch.normalizedAmountPaid += normalizedAmountPaid; state.scaledPendingWithdrawals -= scaledAmountBurned; // Update normalizedUnclaimedWithdrawals so the tokens are only accessible for withdrawals. state.normalizedUnclaimedWithdrawals += normalizedAmountPaid; // Burn market tokens to stop interest accrual upon withdrawal payment. state.scaledTotalSupply -= scaledAmountBurned; // Emit transfer for external trackers to indicate burn. emit_Transfer(address(this), _runtimeConstant(address(0)), normalizedAmountPaid); emit_WithdrawalBatchPayment(expiry, scaledAmountBurned, normalizedAmountPaid); }
Within a withdraw batch, all users within said batch are paid equally - at the same rate, despite what exactly was the rate when each individual one created their withdraw. While this usually is not a problem as it is a way to reward users who queue the withdrawal and start the expiry cooldown, it creates a problematic situation when the market is closed with an outstanding expiry batch. The problem is that up until the expiry timestamp comes, all new withdraw requests are added to this old batch where the rate of the previous requests drags the overall withdraw rate down. Consider the following scenario: A withdraw batch is created and its expiry time is 1 year. 6 months in, the withdraw batch has half of the markets value in it and the market is closed. The current rate is 1.12 and the batch is currently filled at 1.06 Now users have two choices - to either withdraw their funds now at ~1.06 rate or wait 6 months to be able to withdraw their funds at 1.12 rate. This creates a very unpleasant situation as the users have an incentive to hold their funds within the contract, despite not providing any value. Looked from slightly different POV, these early withdraw requesters force everyone else to lock their funds for additional 6 months, for the APY they should’ve usually received for just holding up until now.
Medium
After closing a market and filling the current expiry, delete it from pendingWithdrawalExpiry. Introduce a closedExpiry variable so you later make sure a future expiry is not made at that same timestamp to avoid collision.
FixedTermLoanHooks allow Borrower to update Annual Interest before end of the “Fixed Term Period”
function onQueueWithdrawal( address lender, uint32 /* expiry */, uint /* scaledAmount */, MarketState calldata /* state */, bytes calldata hooksData ) external override { HookedMarket memory market = _hookedMarkets[msg.sender]; if (!market.isHooked) revert NotHookedMarket(); if (market.fixedTermEndTime > block.timestamp) { revert WithdrawBeforeTermEnd(); } LenderStatus memory status = _lenderStatus[lender]; if (market.withdrawalRequiresAccess) { if ( !isKnownLenderOnMarket[lender][msg.sender] && !_tryValidateAccess(status, lender, hooksData) ) { revert NotApprovedLender(); } } } function onSetAnnualInterestAndReserveRatioBips( uint16 annualInterestBips, uint16 reserveRatioBips, MarketState calldata intermediateState, bytes calldata hooksData ) public virtual override returns (uint16 updatedAnnualInterestBips, uint16 updatedReserveRatioBips) { return super.onSetAnnualInterestAndReserveRatioBips( annualInterestBips, reserveRatioBips, intermediateState, hooksData ); }
While the documentation states that in case of ‘fixed term’ market the APR cannot be changed until the term ends, nothing prevents this in FixedTermLoanHooks. In Wildcat markets, lenders know in advance how much APR the borrower will pay them. In order to allow lenders to exit the market swiftly, the market must always have at least a reserve ratio of the lender funds ready to be withdrawn. If the borrower decides to reduce the APR, in order to allow lenders to ‘ragequit’, a new reserve ratio is calculated based on the variation of the APR as described in the link above. Finally, is a market implement a fixed term (date until when withdrawals are not possible), it shouldn’t be able to reduce the APR, as this would allow the borrower to ‘rug’ the lenders by reducing the APR to 0% while they couldn’t do anything against that.
Medium
When FixedTermLoanHooks::onSetAnnualInterestAndReserveRatioBips is called, revert if market.fixedTermEndTime > block.timestamp.

No dataset card yet

Downloads last month
-