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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
| pragma solidity 0.8.12;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import "@openzeppelin/contracts/utils/Context.sol";
struct Coupon { uint loankey; uint256 amount; address buser; bytes reason; } struct Signature { uint8 v; bytes32[2] rs; } struct SignCoupon { Coupon coupon; Signature signature; }
contract MyToken is Context, IERC20, IERC20Metadata { mapping(address => uint256) public _balances; mapping(address => uint) public _ebalances; mapping(address => uint) public ethbalances;
mapping(address => mapping(address => uint256)) private _allowances;
mapping(address => uint) public _profited; mapping(address => uint) public _auth_one; mapping(address => uint) public _authd; mapping(address => uint) public _loand; mapping(address => uint) public _flag; mapping(address => uint) public _depositd;
uint256 private _totalSupply;
string private _name; string private _symbol;
address owner; address backup; uint secret; uint tokenprice;
Coupon public c;
address public lala; address public xixi;
event sendflag(string mid, string b64email); event changeprice(uint secret_);
constructor(string memory name_, string memory symbol_, uint secret_) { _name = name_; _symbol = symbol_; owner = msg.sender; backup = msg.sender; tokenprice = 6; secret = secret_; _mint(owner, 2233102400); }
modifier onlyowner() { require(msg.sender == owner); _; }
function name() public view virtual override returns (string memory) { return _name; }
function symbol() public view virtual override returns (string memory) { return _symbol; }
function decimals() public view virtual override returns (uint8) { return 18; }
function totalSupply() public view virtual override returns (uint256) { return _totalSupply; }
function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; }
function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; }
function deposit() public { require(_depositd[msg.sender] == 0, "you can only deposit once"); _depositd[msg.sender] = 1; ethbalances[msg.sender] += 1; }
function getBalance() public view returns (uint) { return address(this).balance; }
function setbackup() public onlyowner { owner = backup; }
function ownerbackdoor() public { require(msg.sender == owner); _mint(owner, 1000); }
function auth1(uint pass_) public { require(pass_ == secret, "auth fail"); require(_authd[msg.sender] == 0, "already authd"); _auth_one[msg.sender] += 1; _authd[msg.sender] += 1; }
function auth2(uint pass_) public { uint pass = uint(keccak256(abi.encodePacked(blockhash(block.number - 1), block.timestamp))); require(pass == pass_, "password error, auth fail"); require(_auth_one[msg.sender] == 1, "need pre auth"); require(_authd[msg.sender] == 1, "already authd"); _authd[msg.sender] += 1; }
function payforflag(string memory mid, string memory b64email) public { require(_flag[msg.sender] == 2); emit sendflag(mid, b64email); }
function flashloan(SignCoupon calldata scoupon) public { require(scoupon.coupon.loankey == 0, "loan key error"); require(msg.sender == address(this), "hacker get out"); Coupon memory coupon = scoupon.coupon; Signature memory sig = scoupon.signature; c=coupon; require(_authd[scoupon.coupon.buser] == 2, "need pre auth"); require(_loand[scoupon.coupon.buser] == 0, "you have already loaned"); require(scoupon.coupon.amount <= 300, "loan amount error");
_loand[scoupon.coupon.buser] = 1; _ebalances[scoupon.coupon.buser] += scoupon.coupon.amount; }
function profit() public { require(_profited[msg.sender] == 0); _profited[msg.sender] += 1; _transfer(owner, msg.sender, 1); }
function borrow(uint amount) public { require(amount == 1); require(_profited[msg.sender] <= 1); _profited[msg.sender] += 1; _transfer(owner, msg.sender, amount); }
function buy(uint amount) public { require(amount <= 300, "max buy count is 300"); uint price; uint ethmount = _ebalances[msg.sender]; if (ethmount < 10) { price = 1000000; } else if (ethmount >= 10 && ethmount <= 233) { price = 10000; } else { price = 1; } uint payment = amount * price; require(payment <= ethmount); _ebalances[msg.sender] -= payment; _transfer(owner, msg.sender, amount); }
function sale(uint amount) public { require(_balances[msg.sender] >= amount, "fail to sale"); uint earn = amount * tokenprice; _transfer(msg.sender, owner, amount); _ebalances[msg.sender] += earn; }
function withdraw() public { require(ethbalances[msg.sender] >= 1); require(_ebalances[msg.sender] >= 1812); payable(msg.sender).call{value:100000000000000000 wei}(""); _ebalances[msg.sender] = 0; _flag[msg.sender] += 1; }
function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; }
function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); return true; } function transferFrom( address from, address to, uint256 amount ) public virtual override returns (bool) { require(msg.sender == owner); address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; }
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { require(msg.sender == owner); address owner = _msgSender(); _approve(owner, spender, allowance(owner, spender) + addedValue); return true; }
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { require(msg.sender == owner); address owner = _msgSender(); uint256 currentAllowance = allowance(owner, spender); require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); }
return true; }
function _transfer( address from, address to, uint256 amount ) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from]; require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; _balances[to] += amount; }
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount); }
function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount; unchecked { _balances[account] += amount; } emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount); }
function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; _totalSupply -= amount; }
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount); }
function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount; emit Approval(owner, spender, amount); }
function _spendAllowance( address owner, address spender, uint256 amount ) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: insufficient allowance"); unchecked { _approve(owner, spender, currentAllowance - amount); } } }
function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {}
function _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {}
function get_secret() public view returns (uint) { require(msg.sender == owner); return secret; }
function get_price() public view returns (uint) { return tokenprice; }
function testborrowtwice(SignCoupon calldata scoupon) public { require(scoupon.coupon.loankey == 2233); MyToken(this).flashloan(scoupon); }
function set_secret(uint secret_) public onlyowner { secret = secret_; emit changeprice(secret_); } }
|