Skip to content

Instantly share code, notes, and snippets.

@shayanb
Last active October 9, 2019 11:39
Show Gist options
  • Select an option

  • Save shayanb/19dace14c6730a57c8df8682eb3f1ba6 to your computer and use it in GitHub Desktop.

Select an option

Save shayanb/19dace14c6730a57c8df8682eb3f1ba6 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.5.8+commit.23d335f2.js&optimize=false&gist=
// ConsenSys Diligence
// NorthSec 2019
// Montreal, Canada
pragma solidity ^0.5.4;
contract challenge1 {
string public name;
address private owner;
//Placeholder
}
// ___ __ __ _ ____ ____ __ _ ____ _ _ ____
// / __)/ \ ( ( \/ ___)( __)( ( \/ ___)( \/ )/ ___)
// ( (__( O )/ /\___ \ ) _) / /\___ \ ) / \___ \
// \___)\__/ \_)__)(____/(____)\_)__)(____/(__/ (____/
// ____ __ __ __ ___ ____ __ _ ___ ____
// ( \( )( ) ( )/ __)( __)( ( \ / __)( __)
// ) D ( )( / (_/\ )(( (_ \ ) _) / /( (__ ) _)
// (____/(__)\____/(__)\___/(____)\_)__) \___)(____)
// ConsenSys Diligence
// NorthSec 2019
// Montreal, Canada
pragma solidity ^0.5.4;
// Guess the password for the safe
contract challenge2 {
bytes32 private password;
address public owner;
constructor(string memory secretPassword) public payable{
require(msg.value == 1 ether); //1 Ether Deposit required
owner = msg.sender;
password = keccak256(abi.encode(secretPassword));
}
function changePassword(string memory secretPassword) public payable{
require(msg.sender == owner); //OnlyOwner
require(msg.value == 1 ether); //1 Ether Deposit required
password = keccak256(abi.encode(secretPassword));
}
function passwordTest() public view returns (bytes32){
//TODO: remove this for production
return (password);
}
function guessPassword(string memory n) public payable {
require(msg.value == 1 ether); // 1 Ether Deposit required
if (keccak256(abi.encode(n)) == password) {
msg.sender.transfer(2 ether);
}
}
}
// _________ _________
// \_ ___ \ ____ ____ ______ ____ ____ / _____/__.__. ______
// / \ \/ / _ \ / \ / ___// __ \ / \ \_____ < | |/ ___/
// \ \___( <_> ) | \\___ \\ ___/| | \/ \___ |\___ \
// \______ /\____/|___| /____ >\___ >___| /_______ / ____/____ >
// \/ \/ \/ \/ \/ \/\/ \/
// ________ .__.__ .__
// \______ \ |__| | |__| ____ ____ ____ ____ ____
// | | \| | | | |/ ___\_/ __ \ / \_/ ___\/ __ \
// | ` \ | |_| / /_/ > ___/| | \ \__\ ___/
// /_______ /__|____/__\___ / \___ >___| /\___ >___ >
// \/ /_____/ \/ \/ \/ \/
// ConsenSys Diligence
// NorthSec 2019
// Montreal, Canada
pragma solidity ^0.5.4;
// Lottery using block hash as source of randomness
contract challenge3 {
uint256 public answer;
constructor () payable public {
require(msg.value == 1 ether);
}
function lottery(uint256 n) payable public {
require(msg.value == 1 ether); //1 Ether Deposit required
answer = uint256(keccak256(abi.encode(blockhash(block.number))));
if (n == answer) {
msg.sender.transfer(2 ether);
}
}
}
// ___ __
// / __\___ _ __ ___ ___ _ __ / _\_ _ ___
// / / / _ \| '_ \/ __|/ _ \ '_ \\ \| | | / __|
// / /__| (_) | | | \__ \ __/ | | |\ \ |_| \__ \
// \____/\___/|_| |_|___/\___|_| |_\__/\__, |___/
// |___/
// ___ _ _ _
// / (_) (_) __ _ ___ _ __ ___ ___
// / /\ / | | |/ _` |/ _ \ '_ \ / __/ _ \
// / /_//| | | | (_| | __/ | | | (_| __/
// /___,' |_|_|_|\__, |\___|_| |_|\___\___|
// |___/
// ConsenSys Diligence
// NorthSec 2019
// Montreal, Canada
pragma solidity ^0.5.4;
contract challenge4 {
// Steal money from charity
mapping(address => uint) public balances;
event paid(address payee, uint amount);
constructor() public payable{
require(msg.value == 1 ether);
balances[msg.sender] = msg.value;
}
function donate(address _to) public payable {
balances[_to] += msg.value;
}
function balanceOf(address _who) public view returns (uint balance) {
return balances[_who];
}
function withdraw(uint _amount) public {
if(balances[msg.sender] >= _amount) {
(bool success, ) = msg.sender.call.value(_amount)("");
if(success) {
emit paid(msg.sender, _amount);
}
balances[msg.sender] -= _amount; //decrease the balance
}
}
function() external payable {}
}
// ______ ______ __ __ ______ ______ __ __ ______ __ __ ______
// /\ ___\ /\ __ \ /\ "-.\ \ /\ ___\ /\ ___\ /\ "-.\ \ /\ ___\ /\ \_\ \ /\ ___\
// \ \ \____ \ \ \/\ \ \ \ \-. \ \ \___ \ \ \ __\ \ \ \-. \ \ \___ \ \ \____ \ \ \___ \
// \ \_____\ \ \_____\ \ \_\\"\_\ \/\_____\ \ \_____\ \ \_\\"\_\ \/\_____\ \/\_____\ \/\_____\
// \/_____/ \/_____/ \/_/ \/_/ \/_____/ \/_____/ \/_/ \/_/ \/_____/ \/_____/ \/_____/
// _____ __ __ __ ______ ______ __ __ ______ ______
// /\ __-. /\ \ /\ \ /\ \ /\ ___\ /\ ___\ /\ "-.\ \ /\ ___\ /\ ___\
// \ \ \/\ \ \ \ \ \ \ \____ \ \ \ \ \ \__ \ \ \ __\ \ \ \-. \ \ \ \____ \ \ __\
// \ \____- \ \_\ \ \_____\ \ \_\ \ \_____\ \ \_____\ \ \_\\"\_\ \ \_____\ \ \_____\
// \/____/ \/_/ \/_____/ \/_/ \/_____/ \/_____/ \/_/ \/_/ \/_____/ \/_____/
// ConsenSys Diligence
// NorthSec 2019
// Montreal, Canada
pragma solidity ^0.5.4;
contract challenge5 {
string public name;
address private owner;
//Placeholder
}
// ██████╗ ██████╗ ███╗ ██╗███████╗███████╗███╗ ██╗███████╗██╗ ██╗███████╗
// ██╔════╝██╔═══██╗████╗ ██║██╔════╝██╔════╝████╗ ██║██╔════╝╚██╗ ██╔╝██╔════╝
// ██║ ██║ ██║██╔██╗ ██║███████╗█████╗ ██╔██╗ ██║███████╗ ╚████╔╝ ███████╗
// ██║ ██║ ██║██║╚██╗██║╚════██║██╔══╝ ██║╚██╗██║╚════██║ ╚██╔╝ ╚════██║
// ╚██████╗╚██████╔╝██║ ╚████║███████║███████╗██║ ╚████║███████║ ██║ ███████║
// ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝╚══════╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚══════╝
// ██████╗ ██╗██╗ ██╗ ██████╗ ███████╗███╗ ██╗ ██████╗███████╗
// ██╔══██╗██║██║ ██║██╔════╝ ██╔════╝████╗ ██║██╔════╝██╔════╝
// ██║ ██║██║██║ ██║██║ ███╗█████╗ ██╔██╗ ██║██║ █████╗
// ██║ ██║██║██║ ██║██║ ██║██╔══╝ ██║╚██╗██║██║ ██╔══╝
// ██████╔╝██║███████╗██║╚██████╔╝███████╗██║ ╚████║╚██████╗███████╗
// ╚═════╝ ╚═╝╚══════╝╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═════╝╚══════╝
// ConsenSys Diligence
// NorthSec 2019
// Montreal, Canada
pragma solidity ^0.5.4;
// Say Hi
contract helloWorld {
string public name;
address private owner;
event Hi(string name);
constructor() public {
owner = msg.sender;
}
function sayHi(string memory _name) public {
//change the name if owner calls
if (msg.sender == owner) {
name = _name;
}
emit Hi(_name);
}
//fallback function.
function() external {
emit Hi("Hello World");
}
}
// ______ _____
// / ____/___ ____ ________ ____ / ___/__ _______
// / / / __ \/ __ \/ ___/ _ \/ __ \\__ \/ / / / ___/
// / /___/ /_/ / / / (__ ) __/ / / /__/ / /_/ (__ )
// \__________/___/_/____/\___/_/ /_/____/\__, /____/
// / __ \(_) (_)___ ____ ____ ______//___/
// / / / / / / / __ `/ _ \/ __ \/ ___/ _ \
// / /_/ / / / / /_/ / __/ / / / /__/ __/
// /_____/_/_/_/\__, /\___/_/ /_/\___/\___/
// /____/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment