DeFiFoundry
60,000 USDC
View results
Submission Details
Severity: medium
Invalid

External function call before the state update

Summary

The _update function calls an external contract (IPerpsEngine) before updating the state. This can allow the external contract to reenter the function and potentially manipulate the state.

Vulnerability Details

Here is the vulnerability present

https://github.com/Cyfrin/2024-07-zaros/blob/main/src/account-nft/AccountNFT.sol

function _update(address to, uint256 tokenId, address auth) internal virtual override returns (address) {
address previousOwner = super._update(to, tokenId, auth);
IPerpsEngine(owner()).notifyAccountTransfer(to, tokenId.toUint128());
return previousOwner;
}

Impact

Calling an external contract before updating the state can lead to reentrancy attacks, where the external contract can call back into the vulnerable function before the state is updated.

Tools Used

Recommendations:

Update the state before calling the external contract to prevent reentrancy attacks.

function _update(address to, uint256 tokenId, address auth) internal virtual override returns (address) {
address previousOwner = super._update(to, tokenId, auth);
super._update(to, tokenId, auth);
IPerpsEngine(owner()).notifyAccountTransfer(to, tokenId.toUint128());
return previousOwner;
}
Updates

Lead Judging Commences

inallhonesty Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Lack of quality

Support

FAQs

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

Give us feedback!