Skip to content

Instantly share code, notes, and snippets.

@codemedici
Created December 7, 2021 17:27
Show Gist options
  • Save codemedici/0783a4bd5b2e92eea3de9961767b452b to your computer and use it in GitHub Desktop.
Save codemedici/0783a4bd5b2e92eea3de9961767b452b to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.0+commit.26b70077.js&optimize=false&runs=200&gist=
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;
}
}
}
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;
}
}
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;
}
}
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;
}
}
{
"deploy": {
"VM:-": {
"linkReferences": {},
"autoDeployLib": true
},
"main:1": {
"linkReferences": {},
"autoDeployLib": true
},
"ropsten:3": {
"linkReferences": {},
"autoDeployLib": true
},
"rinkeby:4": {
"linkReferences": {},
"autoDeployLib": true
},
"kovan:42": {
"linkReferences": {},
"autoDeployLib": true
},
"görli:5": {
"linkReferences": {},
"autoDeployLib": true
},
"Custom": {
"linkReferences": {},
"autoDeployLib": true
}
},
"data": {
"bytecode": {
"linkReferences": {},
"object": "60806040527f04994f67dc55b09e814ab7ffc8df3686b4afb2bb53e60eae97ef043fe03fb82960001b60005534801561003757600080fd5b5061017c806100476000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063149264ea1461003b578063a28b749a14610080575b600080fd5b61006a6004803603602081101561005157600080fd5b81019080803560ff1690602001909291905050506100a4565b6040518082815260200191505060405180910390f35b6100886100dd565b604051808260ff1660ff16815260200191505060405180910390f35b600081604051602001808260ff1660ff1660f81b8152600101915050604051602081830303815290604052805190602001209050919050565b600080600090505b6101008160ff1610156101415760005481604051602001808260ff1660ff1660f81b81526001019150506040516020818303038152906040528051906020012014156101345780915050610143565b80806001019150506100e5565b505b9056fea2646970667358221220b71bbe5374affc0001d0d71fe5c525e9fd97d422e86a21596f479c55da32189b64736f6c63430006000033",
"opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE PUSH32 0x4994F67DC55B09E814AB7FFC8DF3686B4AFB2BB53E60EAE97EF043FE03FB829 PUSH1 0x0 SHL PUSH1 0x0 SSTORE CALLVALUE DUP1 ISZERO PUSH2 0x37 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH2 0x17C DUP1 PUSH2 0x47 PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN INVALID PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x4 CALLDATASIZE LT PUSH2 0x36 JUMPI PUSH1 0x0 CALLDATALOAD PUSH1 0xE0 SHR DUP1 PUSH4 0x149264EA EQ PUSH2 0x3B JUMPI DUP1 PUSH4 0xA28B749A EQ PUSH2 0x80 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH2 0x6A PUSH1 0x4 DUP1 CALLDATASIZE SUB PUSH1 0x20 DUP2 LT ISZERO PUSH2 0x51 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST DUP2 ADD SWAP1 DUP1 DUP1 CALLDATALOAD PUSH1 0xFF AND SWAP1 PUSH1 0x20 ADD SWAP1 SWAP3 SWAP2 SWAP1 POP POP POP PUSH2 0xA4 JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 DUP3 DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST PUSH2 0x88 PUSH2 0xDD JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 DUP3 PUSH1 0xFF AND PUSH1 0xFF AND DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST PUSH1 0x0 DUP2 PUSH1 0x40 MLOAD PUSH1 0x20 ADD DUP1 DUP3 PUSH1 0xFF AND PUSH1 0xFF AND PUSH1 0xF8 SHL DUP2 MSTORE PUSH1 0x1 ADD SWAP2 POP POP PUSH1 0x40 MLOAD PUSH1 0x20 DUP2 DUP4 SUB SUB DUP2 MSTORE SWAP1 PUSH1 0x40 MSTORE DUP1 MLOAD SWAP1 PUSH1 0x20 ADD KECCAK256 SWAP1 POP SWAP2 SWAP1 POP JUMP JUMPDEST PUSH1 0x0 DUP1 PUSH1 0x0 SWAP1 POP JUMPDEST PUSH2 0x100 DUP2 PUSH1 0xFF AND LT ISZERO PUSH2 0x141 JUMPI PUSH1 0x0 SLOAD DUP2 PUSH1 0x40 MLOAD PUSH1 0x20 ADD DUP1 DUP3 PUSH1 0xFF AND PUSH1 0xFF AND PUSH1 0xF8 SHL DUP2 MSTORE PUSH1 0x1 ADD SWAP2 POP POP PUSH1 0x40 MLOAD PUSH1 0x20 DUP2 DUP4 SUB SUB DUP2 MSTORE SWAP1 PUSH1 0x40 MSTORE DUP1 MLOAD SWAP1 PUSH1 0x20 ADD KECCAK256 EQ ISZERO PUSH2 0x134 JUMPI DUP1 SWAP2 POP POP PUSH2 0x143 JUMP JUMPDEST DUP1 DUP1 PUSH1 0x1 ADD SWAP2 POP POP PUSH2 0xE5 JUMP JUMPDEST POP JUMPDEST SWAP1 JUMP INVALID LOG2 PUSH5 0x6970667358 0x22 SLT KECCAK256 0xB7 SHL 0xBE MSTORE8 PUSH21 0xAFFC0001D0D71FE5C525E9FD97D422E86A21596F47 SWAP13 SSTORE 0xDA ORIGIN XOR SWAP12 PUSH5 0x736F6C6343 STOP MOD STOP STOP CALLER ",
"sourceMap": "24:442:0:-:0;;;77:66;56:87;;;;24:442;8:9:-1;5:2;;;30:1;27;20:12;5:2;24:442:0;;;;;;;"
},
"deployedBytecode": {
"linkReferences": {},
"object": "608060405234801561001057600080fd5b50600436106100365760003560e01c8063149264ea1461003b578063a28b749a14610080575b600080fd5b61006a6004803603602081101561005157600080fd5b81019080803560ff1690602001909291905050506100a4565b6040518082815260200191505060405180910390f35b6100886100dd565b604051808260ff1660ff16815260200191505060405180910390f35b600081604051602001808260ff1660ff1660f81b8152600101915050604051602081830303815290604052805190602001209050919050565b600080600090505b6101008160ff1610156101415760005481604051602001808260ff1660ff1660f81b81526001019150506040516020818303038152906040528051906020012014156101345780915050610143565b80806001019150506100e5565b505b9056fea2646970667358221220b71bbe5374affc0001d0d71fe5c525e9fd97d422e86a21596f479c55da32189b64736f6c63430006000033",
"opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x4 CALLDATASIZE LT PUSH2 0x36 JUMPI PUSH1 0x0 CALLDATALOAD PUSH1 0xE0 SHR DUP1 PUSH4 0x149264EA EQ PUSH2 0x3B JUMPI DUP1 PUSH4 0xA28B749A EQ PUSH2 0x80 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH2 0x6A PUSH1 0x4 DUP1 CALLDATASIZE SUB PUSH1 0x20 DUP2 LT ISZERO PUSH2 0x51 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST DUP2 ADD SWAP1 DUP1 DUP1 CALLDATALOAD PUSH1 0xFF AND SWAP1 PUSH1 0x20 ADD SWAP1 SWAP3 SWAP2 SWAP1 POP POP POP PUSH2 0xA4 JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 DUP3 DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST PUSH2 0x88 PUSH2 0xDD JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 DUP3 PUSH1 0xFF AND PUSH1 0xFF AND DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST PUSH1 0x0 DUP2 PUSH1 0x40 MLOAD PUSH1 0x20 ADD DUP1 DUP3 PUSH1 0xFF AND PUSH1 0xFF AND PUSH1 0xF8 SHL DUP2 MSTORE PUSH1 0x1 ADD SWAP2 POP POP PUSH1 0x40 MLOAD PUSH1 0x20 DUP2 DUP4 SUB SUB DUP2 MSTORE SWAP1 PUSH1 0x40 MSTORE DUP1 MLOAD SWAP1 PUSH1 0x20 ADD KECCAK256 SWAP1 POP SWAP2 SWAP1 POP JUMP JUMPDEST PUSH1 0x0 DUP1 PUSH1 0x0 SWAP1 POP JUMPDEST PUSH2 0x100 DUP2 PUSH1 0xFF AND LT ISZERO PUSH2 0x141 JUMPI PUSH1 0x0 SLOAD DUP2 PUSH1 0x40 MLOAD PUSH1 0x20 ADD DUP1 DUP3 PUSH1 0xFF AND PUSH1 0xFF AND PUSH1 0xF8 SHL DUP2 MSTORE PUSH1 0x1 ADD SWAP2 POP POP PUSH1 0x40 MLOAD PUSH1 0x20 DUP2 DUP4 SUB SUB DUP2 MSTORE SWAP1 PUSH1 0x40 MSTORE DUP1 MLOAD SWAP1 PUSH1 0x20 ADD KECCAK256 EQ ISZERO PUSH2 0x134 JUMPI DUP1 SWAP2 POP POP PUSH2 0x143 JUMP JUMPDEST DUP1 DUP1 PUSH1 0x1 ADD SWAP2 POP POP PUSH2 0xE5 JUMP JUMPDEST POP JUMPDEST SWAP1 JUMP INVALID LOG2 PUSH5 0x6970667358 0x22 SLT KECCAK256 0xB7 SHL 0xBE MSTORE8 PUSH21 0xAFFC0001D0D71FE5C525E9FD97D422E86A21596F47 SWAP13 SSTORE 0xDA ORIGIN XOR SWAP12 PUSH5 0x736F6C6343 STOP MOD STOP STOP CALLER ",
"sourceMap": "24:442:0:-:0;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;24:442:0;;;;;;;;;;;;;;;;;;;;;;;;351:113;;;;;;13:2:-1;8:3;5:11;2:2;;;29:1;26;19:12;2:2;351:113:0;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;154:191;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;351:113;403:7;454:1;437:19;;;;;;;;;;;;;;;;;;;;;49:4:-1;39:7;30;26:21;22:32;13:7;6:49;437:19:0;;;427:30;;;;;;420:37;;351:113;;;:::o;154:191::-;191:5;211:7;221:1;211:11;;206:133;228:3;224:1;:7;;;206:133;;;286:10;;279:1;262:19;;;;;;;;;;;;;;;;;;;;;49:4:-1;39:7;30;26:21;22:32;13:7;6:49;262:19:0;;;252:30;;;;;;:44;248:83;;;319:1;312:8;;;;;248:83;233:3;;;;;;;206:133;;;;154:191;;:::o"
},
"gasEstimates": {
"creation": {
"codeDepositCost": "76000",
"executionCost": "20135",
"totalCost": "96135"
},
"external": {
"guess()": "infinite",
"keccak256Uint(uint8)": "432"
}
},
"methodIdentifiers": {
"guess()": "a28b749a",
"keccak256Uint(uint8)": "149264ea"
}
},
"abi": [
{
"inputs": [],
"name": "guess",
"outputs": [
{
"internalType": "uint8",
"name": "",
"type": "uint8"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint8",
"name": "n",
"type": "uint8"
}
],
"name": "keccak256Uint",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "pure",
"type": "function"
}
]
}
{
"compiler": {
"version": "0.6.0+commit.26b70077"
},
"language": "Solidity",
"output": {
"abi": [
{
"inputs": [],
"name": "guess",
"outputs": [
{
"internalType": "uint8",
"name": "",
"type": "uint8"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint8",
"name": "n",
"type": "uint8"
}
],
"name": "keccak256Uint",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "pure",
"type": "function"
}
],
"devdoc": {
"methods": {}
},
"userdoc": {
"methods": {}
}
},
"settings": {
"compilationTarget": {
"gist-2e6d2ea22cc2b7d1394faa8c10b024cd/solutions/Level_1_So.ution.sol": "Level_1_Solution"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
},
"sources": {
"gist-2e6d2ea22cc2b7d1394faa8c10b024cd/solutions/Level_1_So.ution.sol": {
"keccak256": "0x0c376dd50bb6af9b7107aa0f6fbd89d134f94e9a6c4e5e1ff23db4ab4ddddf3e",
"urls": [
"bzz-raw://5ed75b912bf3978914101432aa7558a41b2da6551c64be3b416b6616696cbef3",
"dweb:/ipfs/QmPqKmpXCyXK9aTxfyqqksXW5idwWatQTFs1XD9wA9XmRK"
]
}
},
"version": 1
}
pragma solidity 0.6.0;
contract Level_1_Solution {
bytes32 answerHash = 0x04994f67dc55b09e814ab7ffc8df3686b4afb2bb53e60eae97ef043fe03fb829;
function guess() public view returns(uint8) {
for (uint8 i = 0; i < 256; i++) {
if (keccak256(abi.encodePacked(i)) == answerHash) {
return i;
}
}
}
function keccak256Uint(uint8 n) public pure returns(bytes32) {
return keccak256(abi.encodePacked(n));
}
}
pragma solidity 0.6.0;
import "../Level_2_Reentrancy.sol";
contract Attack {
Level_2_Reentrancy public token;
// intialize the etherStore variable with the contract address
constructor(address _tokenAddress) public {
token = Level_2_Reentrancy(_tokenAddress);
}
function attackToken() external payable {
// deposit and withdraw on ether at the time from target contract
require(msg.value >= 1 ether);
}
function cashOut() public {
// let the attacker (you) withdraw the funds
}
fallback() external payable {
// keep withdrawing until the balance of target contract has fallen below 1 ether
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment