Created
April 24, 2023 12:48
-
-
Save pcaversaccio/67e7335126f19d6a2fb4acaab209e37b to your computer and use it in GitHub Desktop.
Always remember that `address(this).balance` includes also `msg.value` of the current transaction.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: WTFPL | |
pragma solidity ^0.8.19; | |
contract TryToReachMe { | |
constructor() payable { | |
assert(msg.value == 1 wei); | |
} | |
function tryMeBabe(address addr) public payable { | |
uint256 balance = address(this).balance; | |
if (msg.value > balance) { | |
unchecked { | |
payable(addr).transfer(balance + msg.value); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment