Reentrancy

Security

परिभाषा

Reentrancy एक critical vulnerability है जहां malicious contract एक function को recursively call कर सकता है इससे पहले कि first call complete हो। Famous DAO hack (2016) में reentrancy exploit हुआ था। इससे बचने के लिए checks-effects-interactions pattern या ReentrancyGuard use करें।

English version

Reentrancy is a critical vulnerability where a malicious contract can recursively call a function before the first call completes. The famous DAO hack (2016) was a reentrancy exploit. Prevent it using the checks-effects-interactions pattern or ReentrancyGuard.

Code Example

// VULNÉRABLE à la reentrancy
function withdraw() public {
    uint256 amount = balances[msg.sender];
    (bool success, ) = msg.sender.call{value: amount}("");
    require(success);
    balances[msg.sender] = 0; // TROP TARD !
}

// SÉCURISÉ : Checks-Effects-Interactions
function withdrawSecure() public {
    uint256 amount = balances[msg.sender];
    balances[msg.sender] = 0; // État modifié AVANT l'appel externe
    (bool success, ) = msg.sender.call{value: amount}("");
    require(success);
}

संबंधित शब्द

Solingo पर इस concept को practice करें

Reentrancy को interactive exercises और integrated IDE के साथ master करें।

मुफ्त में शुरू करें