Security analysis tool for EVM bytecode. Supports smart contracts built for Ethereum, Hedera, Quorum, Vechain, Roostock, Tron and other EVM-compatible blockchains.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
mythril/tests/testdata/input_contracts/transient.sol

42 lines
1.1 KiB

pragma solidity 0.8.25;
contract Generosity {
mapping(address => bool) sentGifts;
modifier nonreentrant {
uint x;
assembly {
x := tload(0)
}
assert (x == 0);
assembly {
if tload(0) { revert(0, 0) }
tstore(0, 1)
}
_;
// Unlocks the guard, making the pattern composable.
// After the function exits, it can be called again, even in the same transaction.
assembly {
x := tload(0)
}
// It should be same as before, i.e., 1
assert (x == 1);
assembly {
tstore(0, 0)
}
assembly {
x := tload(0)
}
// resets to 0
assert (x == 0);
}
function claimGift() nonreentrant public {
require(address(this).balance >= 1 ether);
require(!sentGifts[msg.sender]);
(bool success, ) = msg.sender.call{value: 1 ether}("");
require(success);
// In a reentrant function, doing this last would open up the vulnerability
sentGifts[msg.sender] = true;
}
}