Closed howlbot-integration[bot] closed 3 months ago
Cannot replicate the reentrancy PoC -- can see by inspection very quickly that bidWithCallback
is not vulnerable in the way described:
function bidWithCallback(bytes calldata data) external returns (uint256 amountIn) {
require(bidder == address(0), "bid already received");
assert(status == TradeStatus.OPEN);
// {buyTok/sellTok}
uint192 price = _price(uint48(block.timestamp)); // enforces auction ongoing
// {qBuyTok}
amountIn = _bidAmount(price);
// Mark bidder
bidder = msg.sender;
bidType = BidType.CALLBACK;
...
_price() and _bidAmount() are view functions
Additionally, can see that warden's mitigation does not change the CEI pattern meaningfully; the callback remains below the effects section in both cases.
require(bidder == address(0))
and bidder=msg.sender
effectively prevents reentrancy.
function bidWithCallback(bytes calldata data) external returns (uint256 amountIn) {
require(bidder == address(0), "bid already received");
assert(status == TradeStatus.OPEN);
// {buyTok/sellTok}
uint192 price = _price(uint48(block.timestamp)); // enforces auction ongoing
// {qBuyTok}
amountIn = _bidAmount(price);
// Mark bidder
bidder = msg.sender;
// Mark bidder
bidder = msg.sender;
bidder = msg.sender
before _price()
and _bidAmount()
. But _price() and _bidAmount() are view functions, which doesn't do anything to mitigate "reentrancy".thereksfour marked the issue as unsatisfactory: Invalid
Lines of code
https://github.com/code-423n4/2024-07-reserve/blob/3f133997e186465f4904553b0f8e86ecb7bbacbf/contracts/plugins/trading/DutchTrade.sol#L235-L269
Vulnerability details
Impact
Detailed description of the impact of this finding.
Reentrancy Vulnerability in bidWithCallback(bytes) in the DutchTrade contract
Contract: DutchTrade Function Name: bidWithCallback(bytes) PC Address: 16558 File: /contracts/plugins/trading/DutchTrade.sol Severity Level: High Issue Type: Reentrancy Vulnerability Estimated Gas Usage: 2328 - 3273
The bidWithCallback(bytes) function in the DutchTrade contract is vulnerable to a reentrancy attack.
This vulnerability arises from the fact that the function makes an external call to the user-defined dutchTradeCallback function before performing critical state changes or settling the trade.
This allows a malicious bidder to reenter the contract during the callback and execute additional bids, which could manipulate the auction or cause unintended state changes.
Proof of Concept
Provide direct links to all referenced code in GitHub. Add screenshots, logs, or any other relevant proof that illustrates the concept.
An attacker can exploit this vulnerability to:
Reenter the bidWithCallback(bytes) function, causing unexpected state changes, including manipulating the auction to their advantage.
Drain tokens from the contract by placing multiple bids within the same transaction, potentially at manipulated prices.
Disrupt the auction process, resulting in financial loss or denial of service for other participants.
In this proof of concept, the MaliciousBidder contract reenters the DutchTrade contract by calling bidWithCallback within the dutchTradeCallback function, allowing it to place multiple bids within the same transaction.
MythX log
POC - Remix IDE Step 1: Malicious Contract Code
Step 2: Explanation
Step 3: Using the Malicious Contract in Remix
Remix IDE Log: Call Dutch trade callback function
Call initiate attack function
Call Receive Fallback Function
Tools Used
Manual review & MythX & Remix IDE.
Recommended Mitigation Steps
To prevent reentrancy attacks, the state of the contract should be updated before making any external calls, including the call to dutchTradeCallback.
Additionally, the use of a reentrancy guard is recommended to ensure that no reentrant calls can be made during the execution of sensitive functions.
Coded Mitigation:
By updating the state before making external calls and using a reentrancy guard pattern, the vulnerability is mitigated, preventing potential reentrancy attacks.
Assessed type
Reentrancy