Skip to content

ERC677 callAfterTransfer() Reentrancy

Description

The ERC677 token's callAfterTransfer() function is vulnerable to reentrancy attacks. This occurs when the transfer function calls an external contract, which then calls back into the token contract, allowing an attacker to drain the contract's funds.

Examples

Insecure Code

solidity
function transfer(address to, uint256 value) public {
    balances[msg.sender] -= value;
    callAfterTransfer();
    balances[to] += value;
}

Secure Code

solidity
function transfer(address to, uint256 value) public {
    balances[msg.sender] -= value;
    balances[to] += value;
    callAfterTransfer();
}

Remediation

Use the Checks-Effects-Interactions pattern to prevent reentrancy. This involves checking conditions, making any necessary changes to the contract's state, and then making external calls.

Rule Details

FieldValue
IDCODE-0231
CategoryCrypto
SeverityHIGH
CWECWE-841
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagsreentrancy, erc677
OWASPN/A

References