Skip to content

Instantly share code, notes, and snippets.

View recmo's full-sized avatar

Remco Bloemen recmo

View GitHub Profile
pragma solidity ^0.4.0;
contract HexEncoding {
function hexEncodeTest(address addr) returns (bytes32 ret) {
uint x = uint(addr) / 2**32;
// Nibble interleave
x = x & 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff;
x = (x | (x * 2**64)) & 0x0000000000000000ffffffffffffffff0000000000000000ffffffffffffffff;
@recmo
recmo / async-fizzbuzz.js
Last active February 2, 2017 14:23
Async FizzBuzz — implemented using *only* callbacks
// Async FizzBuzz -- implemented using only callbacks
//
// node --stack-size=100000 ./async-fizzbuzz.js
//
// Wrap process.stdout.write
const print = (message, callback) =>{
process.stdout.write(message, callback)
}
@recmo
recmo / faucet-contracts.sol
Created March 29, 2017 11:05
Facuet, Multiplexer and Manager
pragma solidity ^0.4.8;
import "../lib/Owned.sol";
import "../lib/SafeMath.sol";
// This contract can be used when a smart contract has a
// role that can be fullfilled by one account, but you would
// like several accounts to fullfill the role.
contract Multiplexer is Owned {
contract Owned {
address public owner;
function Owned() {
owner = msg.sender;
}
modifier onlyOwner() {
if (msg.sender != owner) {
throw;
@recmo
recmo / NeukeySerial.py
Last active May 9, 2017 10:56
Serial number generator for Neukey's using Damm's algorithm.
#!/usr/bin/env python3
from os import urandom
# Damm's weakly totally antisymetric quasigroup of order 10
# https://en.wikipedia.org/wiki/Damm_algorithm
Damm = [
[0, 3, 1, 7, 5, 9, 8, 6, 4, 2],
[7, 0, 9, 2, 1, 5, 4, 8, 6, 3],
[4, 2, 0, 6, 8, 7, 1, 3, 5, 9],
[1, 7, 5, 0, 9, 8, 3, 4, 2, 6],
@recmo
recmo / wasm.js
Last active June 1, 2017 14:55
WebAssembly compile and run example
/* global WebAssembly */
import wast2wasm from 'wast2wasm';
// Run with: babel-node --expose-wasm ./wasm.js
const wast = `(module
(func $fac (param i32) (result i32)
get_local 0
i32.eqz
if i32
@recmo
recmo / TestKeccak.sol
Last active March 1, 2018 21:04
Experiments to understand Solidity's hashing of structured data.
pragma solidity 0.4.20;
// pragma experimental ABIEncoderV2; // Does not affect outcome
contract Test {
function test1() public pure returns (bool) {
bytes32 hash1 = keccak256("abc", "def");
bytes32 hash2 = keccak256("abcd", "ef");
return hash1 == hash2; // Returns true
}
@recmo
recmo / StructuredHashes.sol
Created March 6, 2018 00:26
Hashing algorithms
pragma solidity 0.4.20;
contract StructuredHashes {
struct Order {
address maker;
address taker;
address makerToken;
address takerToken;
address feeRecipient;
contract BloomNuke {
function nuke() {
assembly {
log4(0, 0, 0, 1, 2, 3)
log4(0, 0, 4, 5, 6, 7)
log4(0, 0, 8, 10, 11, 12)
log4(0, 0, 13, 14, 15, 16)
log4(0, 0, 17, 18, 19, 20)
log4(0, 0, 21, 22, 23, 24)
log4(0, 0, 25, 27, 28, 29)
@recmo
recmo / lending.sol
Created November 21, 2018 12:38
Lending contracts having state invariants depending on call stack.
// Simple lending contract demostrating complex call-stack
// dependant state invariants.
// @author Remco Bloemen <remco@0xproject.com>
pragma solidity ^0.4.25;
// Simple non-reentrant version. (Or actually, the innermost call is responsible for paying back everyone.)
contract Lending1 {
constructor () public payable {