Last active
September 10, 2020 09:46
-
-
Save codemedici/2e6d2ea22cc2b7d1394faa8c10b024cd to your computer and use it in GitHub Desktop.
CTF Levels
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.6.0; | |
contract Level_0_Practice { | |
bool public levelComplete; | |
uint8 answer; | |
constructor() public { | |
levelComplete = false; | |
answer = 42; | |
} | |
function completeLevel(uint8 n) public payable { | |
if (n == answer) { | |
levelComplete = true; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.6.0; | |
contract Level_1_Brute_Force { | |
bool public levelComplete; | |
bytes32 public answer; | |
event Guess(bytes32 _guess); | |
constructor() public { | |
levelComplete = false; | |
answer = 0x04994f67dc55b09e814ab7ffc8df3686b4afb2bb53e60eae97ef043fe03fb829; | |
} | |
function completeLevel(uint8 n) public { | |
bytes32 _guess = keccak256(abi.encodePacked(n)); | |
emit Guess(_guess); | |
require(_guess == answer); | |
levelComplete = true; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.6.0; | |
contract Level_2_Reentrancy { | |
string constant name = "Token"; | |
string constant symbol = "T"; | |
uint8 constant decimals = 18; | |
uint public totalSupply; | |
bool public levelComplete; | |
mapping (address => uint256) balances; | |
event Transfer(address indexed _from, address indexed _to, uint256 _value); | |
constructor () public payable { | |
require(msg.value >= 1 ether); | |
totalSupply = msg.value; | |
levelComplete = false; | |
} | |
function balanceOf(address _owner) public view returns (uint256 balance) { | |
return balances[_owner]; | |
} | |
function deposit() public payable returns (bool success) { | |
if (balances[msg.sender] + msg.value < msg.value) return false; | |
if (totalSupply + msg.value < msg.value) return false; | |
balances[msg.sender] += msg.value; | |
totalSupply += msg.value; | |
return true; | |
} | |
function withdraw(uint256 _value) public payable returns (bool success) { | |
if (balances[msg.sender] < _value) return false; | |
msg.sender.call.value(_value)(""); | |
balances[msg.sender] -= _value; | |
totalSupply -= _value; | |
return true; | |
} | |
function transfer(address _to, uint256 _value) public returns (bool success) { | |
if (balances[msg.sender] < _value) return false; | |
if (balances[_to] + _value < _value) return false; | |
balances[msg.sender] -= _value; | |
balances[_to] += _value; | |
emit Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
function completeLevel() external { | |
require(balances[msg.sender] > totalSupply || totalSupply < 1000000000000000000); | |
levelComplete = true; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.6.0; | |
contract Level_3_Global_Functions { | |
bytes32 guess; | |
uint256 settlementBlockNumber; | |
uint public totalSupply; | |
bool public levelComplete; | |
function guessTheFutureHash(bytes32 hash) public payable { | |
guess = hash; | |
settlementBlockNumber = block.number + 1; | |
} | |
function completeLevel() external { | |
require(block.number > settlementBlockNumber); | |
bytes32 answer = blockhash(settlementBlockNumber); | |
require(guess == answer); | |
levelComplete = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment