2020-03-09 21:14:07 +00:00
|
|
|
contract helper {
|
|
|
|
bool flag;
|
|
|
|
|
|
|
|
function getBalance() public payable returns (uint256 myBalance) {
|
|
|
|
return address(this).balance;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setFlag() public {
|
|
|
|
flag = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getFlag() public returns (bool fl) {
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
contract test {
|
|
|
|
helper h;
|
|
|
|
|
2020-06-23 12:14:24 +00:00
|
|
|
constructor() payable {
|
2020-03-09 21:14:07 +00:00
|
|
|
h = new helper();
|
|
|
|
}
|
|
|
|
|
|
|
|
function sendAmount(uint256 amount) public payable returns (uint256 bal) {
|
2020-04-03 14:29:17 +00:00
|
|
|
return h.getBalance{value: amount}();
|
2020-03-09 21:14:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function outOfGas() public returns (bool ret) {
|
2020-04-03 14:29:17 +00:00
|
|
|
h.setFlag{gas: 2}(); // should fail due to OOG
|
2020-03-09 21:14:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkState() public returns (bool flagAfter, uint256 myBal) {
|
|
|
|
flagAfter = h.getFlag();
|
|
|
|
myBal = address(this).balance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 13:12:56 +00:00
|
|
|
// ====
|
|
|
|
// compileViaYul: also
|
2020-03-09 21:14:07 +00:00
|
|
|
// ----
|
|
|
|
// constructor(), 20 wei ->
|
2022-02-16 12:03:39 +00:00
|
|
|
// gas irOptimized: 283040
|
2021-11-15 15:19:33 +00:00
|
|
|
// gas legacy: 402654
|
|
|
|
// gas legacyOptimized: 274470
|
2020-03-09 21:14:07 +00:00
|
|
|
// sendAmount(uint256): 5 -> 5
|
|
|
|
// outOfGas() -> FAILURE # call to helper should not succeed but amount should be transferred anyway #
|
|
|
|
// checkState() -> false, 15
|