15,000 USDC
View results
Submission Details
Severity: low

Event Emission Occurring Before Token Transfer

Summary

The function _redeemCollateral has an issue where the CollateralRedeemed event is emitted before the collateral token transfer occurs.

Vulnerability Details

information being emitted in the event log if the token transfer fails due to reasons such as insufficient balance, token contract issues, or out-of-gas conditions. Emitting the event before ensuring a successful transfer could confuse external systems that rely on the emitted event to track collateral redemption activities.

Impact

This could confuse external systems that rely on the emitted event to track collateral redemption activities.

function depositCollateral(address tokenCollateralAddress, uint256 amountCollateral)
public
moreThanZero(amountCollateral)
isAllowedToken(tokenCollateralAddress)
nonReentrant
{
s_collateralDeposited[msg.sender][tokenCollateralAddress] += amountCollateral;
emit CollateralDeposited(msg.sender, tokenCollateralAddress, amountCollateral);
bool success = IERC20(tokenCollateralAddress).transferFrom(msg.sender, address(this), amountCollateral);
if (!success) {
revert DSCEngine__TransferFailed();
}
}
function _redeemCollateral(address from, address to, address tokenCollateralAddress, uint256 amountCollateral)
private
{
s_collateralDeposited[from][tokenCollateralAddress] -= amountCollateral;
emit CollateralRedeemed(from, to, tokenCollateralAddress, amountCollateral);
bool success = IERC20(tokenCollateralAddress).transfer(to, amountCollateral);
if (!success) {
revert DSCEngine__TransferFailed();
}
}

Tools Used

Manual Review

Recommendations

To rectify this issue and ensure that the event is emitted at the right time, the token transfer should be executed before emitting the event. This ensures that the event is only emitted if the transfer is successful, providing accurate and reliable information to external systems.

Support

FAQs

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