2022-10-05 18:05:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2022-10-06 12:32:08 +00:00
|
|
|
// Challenges inspired by CCTF
|
|
|
|
pragma solidity ^0.8.17;
|
2022-10-05 18:05:05 +00:00
|
|
|
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
|
|
|
|
|
2022-10-05 18:48:58 +00:00
|
|
|
contract SafuDotERC20 is AccessControlUpgradeable {
|
|
|
|
|
|
|
|
uint256 public max_supply;
|
|
|
|
mapping (address => uint256) internal amountToAddress;
|
|
|
|
uint256 public amountOfBridge;
|
|
|
|
uint256 public mint_amount;
|
2022-10-05 18:05:05 +00:00
|
|
|
string private correct_password;
|
2022-10-06 12:32:08 +00:00
|
|
|
//mapping(bytes32 => bool) public hashes;
|
2022-10-05 18:05:05 +00:00
|
|
|
|
|
|
|
uint160 answer = 0;
|
|
|
|
address private admin = 0xdD870fA1b7C4700F2BD7f44238821C26f7392148;
|
|
|
|
event contractStart(address indexed _admin);
|
|
|
|
mapping(address => uint256) public calls;
|
|
|
|
mapping(address => uint256) public tries;
|
|
|
|
|
2022-10-06 12:32:08 +00:00
|
|
|
//bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
|
|
|
|
mapping(address => bool) public minter;
|
2022-10-05 18:05:05 +00:00
|
|
|
|
2022-10-05 18:48:58 +00:00
|
|
|
// Homework 1
|
2022-10-05 18:05:05 +00:00
|
|
|
constructor(address O) payable {
|
|
|
|
emit contractStart(admin);
|
|
|
|
answer = uint160(admin);
|
|
|
|
admin = 0==0?O:0x583031D1113aD414F02576BD6afaBfb302140225;
|
2022-10-05 18:48:58 +00:00
|
|
|
|
|
|
|
max_supply = 1000000;
|
|
|
|
amountToAddress[msg.sender] = max_supply - 100000;
|
|
|
|
amountOfBridge = max_supply - amountToAddress[msg.sender];
|
|
|
|
mint_amount = 10000;
|
2022-10-06 12:32:08 +00:00
|
|
|
minter[msg.sender] = true;
|
2022-10-05 18:05:05 +00:00
|
|
|
}
|
|
|
|
|
2022-10-06 12:32:08 +00:00
|
|
|
function mint() internal {
|
|
|
|
amountToAddress[msg.sender] = amountToAddress[msg.sender] + mint_amount;
|
2022-10-05 18:05:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function mintWithReceipt(
|
|
|
|
address recipient,
|
|
|
|
uint256 amount,
|
|
|
|
uint256 uuid,
|
|
|
|
uint8 v,
|
|
|
|
bytes32 r,
|
|
|
|
bytes32 s
|
|
|
|
) public {
|
|
|
|
|
|
|
|
bytes32 payloadHash = keccak256(abi.encode(recipient, amount, uuid));
|
|
|
|
bytes32 hash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", payloadHash));
|
|
|
|
//require(!_receipts[hash], "Receipt already used"); // Dumb without it.
|
|
|
|
_checkSignature(hash, v, r, s);
|
2022-10-05 18:48:58 +00:00
|
|
|
mint();
|
2022-10-05 18:05:05 +00:00
|
|
|
//_receipts[hash] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _checkSignature(
|
|
|
|
bytes32 hash,
|
|
|
|
uint8 v,
|
|
|
|
bytes32 r,
|
|
|
|
bytes32 s
|
|
|
|
) internal view {
|
|
|
|
address signer = ecrecover(hash, v, r, s);
|
2022-10-06 12:32:08 +00:00
|
|
|
require(minter[signer] == true, "Not minter");
|
2022-10-05 18:05:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-06 12:32:08 +00:00
|
|
|
function transfer(uint256 _value, address _toAddress) external {
|
|
|
|
require(amountToAddress[msg.sender] - _value >= 0, 'Oooops');
|
|
|
|
amountToAddress[_toAddress] = amountToAddress[_toAddress] + _value;
|
2022-10-05 18:05:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function adminWithdraw() external returns (bool) {
|
|
|
|
require(msg.sender == admin, 'You are not the central admin!');
|
|
|
|
(bool sent,) = msg.sender.call{value: address(this).balance}("");
|
|
|
|
return sent;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-06 12:32:08 +00:00
|
|
|
// Easypeasy
|
2022-10-05 18:05:05 +00:00
|
|
|
function adminChange(address _newAdmin) external returns (bool) {
|
|
|
|
admin = _newAdmin;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-10-06 12:32:08 +00:00
|
|
|
// Homework 2
|
2022-10-05 18:05:05 +00:00
|
|
|
function set_password(string memory _password) external {
|
|
|
|
require(msg.sender == admin, 'You are not the central admin!');
|
|
|
|
correct_password = _password;
|
|
|
|
}
|
|
|
|
|
2022-10-06 12:32:08 +00:00
|
|
|
// Homework 5 - Final
|
2022-10-05 18:05:05 +00:00
|
|
|
function su1c1d3(address payable _addr, string memory _password) external {
|
|
|
|
require(msg.sender == admin, 'You are not the central admin!');
|
|
|
|
require(keccak256(abi.encodePacked(correct_password)) == keccak256(abi.encodePacked(_password)), 'Very sekur.');
|
|
|
|
selfdestruct(_addr);
|
|
|
|
}
|
|
|
|
|
2022-10-06 12:32:08 +00:00
|
|
|
// Homework 3
|
2022-10-05 18:05:05 +00:00
|
|
|
function callOnlyOnce() public {
|
|
|
|
require(tries[msg.sender] < 1, "No more tries");
|
|
|
|
calls[msg.sender] += 1;
|
|
|
|
answer = answer ^ uint160(admin);
|
|
|
|
(bool sent, ) = msg.sender.call{value: 1}("");
|
|
|
|
require(sent, "Failed to call");
|
|
|
|
tries[msg.sender] += 1;
|
|
|
|
}
|
|
|
|
|
2022-10-06 12:32:08 +00:00
|
|
|
// Homework 4
|
2022-10-05 18:05:05 +00:00
|
|
|
function answerReveal() public view returns(uint256 ) {
|
|
|
|
require(calls[msg.sender] == 2, "Try more :)");
|
|
|
|
return answer;
|
|
|
|
}
|
|
|
|
|
|
|
|
function deposit() public payable {}
|
|
|
|
fallback() external payable {}
|
|
|
|
receive() external payable {}
|
|
|
|
}
|