Keen Spruce Bison
High
Reentrancy attack occurs when protocol not implemented yet CEI pattern in ReputationMarket::withdrawGraduatedMarketFunds()
. Attacker could still all of funds from protocol.
This vulnerability comes from protocol not doing check-effect-interactions in system. Let's see code below :
Native token are sent first and then state of marketFunds[profileId]
is updated after sending the native token. It can impact reentrancy attack to the protocol.
Attacker can still all of funds from the protocol.
Implement CEI to avoid reentrancy attack
function withdrawGraduatedMarketFunds(uint256 profileId) public whenNotPaused {
address authorizedAddress = contractAddressManager.getContractAddressForName(
"GRADUATION_WITHDRAWAL"
);
if (msg.sender != authorizedAddress) {
revert UnauthorizedWithdrawal();
}
_checkMarketExists(profileId);
if (!graduatedMarkets[profileId]) {
revert MarketNotGraduated();
}
if (marketFunds[profileId] == 0) {
revert InsufficientFunds();
}
+ marketFunds[profileId] = 0;
_sendEth(marketFunds[profileId]);
emit MarketFundsWithdrawn(profileId, msg.sender, marketFunds[profileId]);
- marketFunds[profileId] = 0;
}