Skip to content

Instantly share code, notes, and snippets.

@cwhinfrey
cwhinfrey / PaymentChannelPOC.sol
Created December 21, 2018 17:09
PaymentChannelPOC.sol
pragma solidity ^0.4.24;
library ECDSA {
/**
* @dev Recover signer address from a message by using their signature
* @param hash bytes32 message, the hash is the signed message. What is recovered is the signer address.
* @param signature bytes signature, the signature is generated using web3.eth.sign()
*/
function recover(bytes32 hash, bytes signature) internal pure returns (address) {
bytes32 r;
@cwhinfrey
cwhinfrey / OracleInterfaces.sol
Last active January 8, 2019 01:14
OracleInterfaces.sol
interface Oracle {
function isResultSetFor(uint256 id) external view returns (bool isSet);
function resultFor(uint256 id) external view returns (bytes32 result);
}
// Optional, OraclePrimary must implement Oracle
interface OraclePrimary {
event ResultSet(bytes32 _result, uint256 _id);
}
@cwhinfrey
cwhinfrey / AccountFactory.sol
Last active February 16, 2019 22:26
Meta Tx Create2 Contract Factory
pragma solidity ^0.5.0;
library ECDSA {
/**
* @dev Recover signer address from a message by using their signature
* @param hash bytes32 message, the hash is the signed message. What is recovered is the signer address.
* @param signature bytes signature, the signature is generated using web3.eth.sign()
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
bytes32 r;
@cwhinfrey
cwhinfrey / Create2Factory.sol
Created February 27, 2019 06:47
Create2Factory.sol
pragma solidity ^0.5.2;
contract Create2FactoryBase {
bytes private contractCode;
constructor(bytes memory _contractCode) public {
contractCode = _contractCode;
}
@cwhinfrey
cwhinfrey / LibraryEncapsulation.sol
Created March 22, 2019 03:55
LibraryEncapsulation.sol
pragma solidity ^0.5.5;
// Libs
library FooLib {
struct Foo {
uint a;
uint b;
uint c;
}
contract ContractSignerVerifier {
// returns keccak256("isValidSigner") if signer is valid
function isValidSigner(address _signer, bytes memory data) public view returns (bytes32);
}
interface IChannelArbiter {
function channelValueForUpdate(address sender, address receiver, uint256 nonce) external view returns (uint256 value);
}
contract ChannelIdentifier {
pragma solidity ^0.5.8;
contract Channels {
function deposit(address _participant) public payable;
}
contract Bouncer {
Channels channelContract;
address participant;
@cwhinfrey
cwhinfrey / Create2.sol
Created July 8, 2019 01:19
Create2 Library
/**
* @title Create2
*
* @dev Utility library for deploying contracts with the CREATE2 EVM opcode and
* computing the contract address of CREATE2 deployments
*/
library Create2 {
/**
* @dev Function to compute the address of a contract created with CREATE2.
* @param _salt The salt used to the contract address computation
@cwhinfrey
cwhinfrey / BasicProxy.sol
Created October 17, 2019 02:30
BasicProxy.sol
pragma solidity ^0.5.0;
contract BasicProxy {
address public implementation = 0xB6Eb4245eF5626E3505c6223D3157FCE3CE8d0AE;
function () external payable {
address target = implementation;
assembly {
@cwhinfrey
cwhinfrey / UpgradabilityPatterns.sol
Last active October 19, 2019 00:14
UpgradabilityPatterns.sol
pragma solidity ^0.5.10;
// V1
contract AccountV1Storage {
uint lastInitializedVersion;
uint a;
}
contract AccountV1 is AccountV1Storage {