Skip to content

Instantly share code, notes, and snippets.

/**
* Base contract that all upgradeable contracts should use.
*
* Contracts implementing this interface are all called using delegatecall from
* a dispatcher. As a result, the _sizes and _dest variables are shared with the
* dispatcher contract, which allows the called contract to update these at will.
*
* _sizes is a map of function signatures to return value sizes. Due to EVM
* limitations, these need to be populated by the target contract, so the
* dispatcher knows how many bytes of data to return from called functions.
@D-Nice
D-Nice / testingDAO v1.1
Last active June 5, 2016 19:10
DAO for use in testing and finding any bugs in V1.1 features
/*
- Bytecode Verification performed was compared on second iteration -
This file is part of the DAO.
The DAO is free software: you can redistribute it and/or modify
it under the terms of the GNU lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
contract Creator {
function newContract(bytes data) public returns (address) {
address theNewContract;
uint s = data.length;
assembly {
calldatacopy(mload(0x40), 68, s)
theNewContract := create(callvalue, mload(0x40), s)
}
@D-Nice
D-Nice / stringaskey.sol
Created August 20, 2016 18:01 — forked from axic/stringaskey.sol
How to use string as a key in a mapping in Solidity aka. how to store short strings cheape
//
// In Solidity, a mapping is like a hashmap and works with `string` like this:
// mapping (string => uint) a;
//
// However it doesn't support accessors where string is a key:
// mapping (string => uint) public a;
//
// "Internal compiler error: Accessors for mapping with dynamically-sized keys not yet implemented."
//
// An accessor returns uint when called as `a(string)`.
@D-Nice
D-Nice / etherUnitConverter.sol
Last active September 17, 2016 23:16
An Ethereum unit converter living on the blockchain with some caveats (doesn't support decimal places and they get truncated)
pragma solidity ^0.4.0;
contract EtherUnitConverter {
/*
* Ethereum Units Converter contract
*
* created by: D-Nice
* contract address: 0x52070b253406fc4F2bf71dBaF910F66c45828DBA
*/
@D-Nice
D-Nice / BigInt.sol
Created September 29, 2016 23:39 — forked from axic/BigInt.sol
Big number library in Solidity (for modexp)
//
// Big number library in Solidity for the purpose of implementing modexp.
//
// Should have a similar API to https://github.com/ethereum/EIPs/issues/101
//
// Internally bignumbers are represented as an uint array of 128 bit values.
//
// NOTE: it assumes usage with "small" (<256bit) exponents (such as in RSA)
//
@D-Nice
D-Nice / tlsn-notarization-file-format.md
Created November 9, 2016 21:45 — forked from AdamISZ/tlsn-notarization-file-format.md
TLSNotary notarization file format

Data format: binary. Default file extension: '.tlsn'

Contents

Field description (size in bytes) code in Python version
Header (29) 'tlsnotary notarization file\n\n'
@D-Nice
D-Nice / DatePayout.sol
Last active November 28, 2016 11:44
Contract for locking a certain amount of ether until a set date
contract DateTime {
/*
* Credit to pipermerriam for this utility contract
*
* Date and Time utilities for ethereum contracts
*
* address: 0x1a6184cd4c5bea62b0116de7962ee7315b7bcbce
*/
function toTimestamp(uint16 year, uint8 month, uint8 day) constant returns (uint timestamp);
pragma solidity ^0.4.0;
contract SHA1 {
uint8[4] shift = [3, 8, 14, 16];
uint constant leftAlign = 16**56;
uint constant prep = 16**55; //allow extra bits as requested in spec
uint constant h0 = 1732584193 * prep; //0x67452301
uint constant h1 = 4023233417 * prep; //0xEFCDAB89
contract stringArrayToBytes {
string[] x = ["qs2333332222222222222222222222222233333311", "q2", "q3", "5025",
"anotherquery", "oisjgsodjgdsogjsdgsdgsdgsdoigjsdiogjsodigjsdoigjsdog",
"777777777", "88888888", "99999", "TEN"];
function convert(string[] x, uint from, uint to) internal returns (bytes) {
bytes memory z;
uint zlen = 0;
for (var i = from; i <= to; i++) {
bytes memory y = bytes(x[i]);