You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Slither detects reentrancy in the code below.
I think the code is safe for reentrancy. bool locked is a variable for mutex.
Slither detects vulnerabilities by recognizing the variable as a state variable written after an external call.
pragma solidity ^0.7.0;
contract MutexPattern {
bool locked = false;
mapping(address => uint256) public balances;
function withdraw(uint _amount) public payable returns(bool) {
require(!locked, "Blocked from reentrancy.");
locked = true;
require(balances[msg.sender] >= _amount, "No balance to withdraw.");
balances[msg.sender] -= _amount;
(bool success, ) = msg.sender.call{value: _amount}("");
require(success);
locked = false;
return true;
}
}
Slither detects the code below using a modifier as safe, although the functionality is the same as the above code.
pragma solidity ^0.7.0;
contract MutexPattern {
bool locked = false;
mapping(address => uint256) public balances;
modifier noReentrancy() {
require(!locked, "Blocked from reentrancy.");
locked = true;
_;
locked = false;
}
function withdraw(uint _amount) public payable noReentrancy returns(bool) {
require(balances[msg.sender] >= _amount, "No balance to withdraw.");
balances[msg.sender] -= _amount;
(bool success, ) = msg.sender.call{value: _amount}("");
require(success);
return true;
}
}
What differences are in them?
The text was updated successfully, but these errors were encountered:
Describe the desired feature
Slither detects reentrancy in the code below.
I think the code is safe for reentrancy.
bool locked
is a variable for mutex.Slither detects vulnerabilities by recognizing the variable as a state variable written after an external call.
Slither detects the code below using a modifier as safe, although the functionality is the same as the above code.
What differences are in them?
The text was updated successfully, but these errors were encountered: