Skip to content

Instantly share code, notes, and snippets.

View raineorshine's full-sized avatar

Raine Revere raineorshine

  • New York, NY
View GitHub Profile
@paullewis
paullewis / requestIdleCallback.js
Last active February 21, 2024 16:56
Shims rIC in case a browser doesn't support it.
/*!
* Copyright 2015 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@raineorshine
raineorshine / package.json
Last active October 23, 2023 15:35
Raine's initial package.json
{
"name": "",
"description": "",
"version": "0.0.0",
"author": {
"name": "Raine Revere",
"email": "raine.revere@pm.me",
"url": "https://github.com/raineorshine"
},
"engines": {
/**
* 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.
anonymous
anonymous / FallbackGasFunctions.sol
Created June 8, 2016 18:44
Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-latest.js&optimize=undefined&gist=
// 21,030
contract Fallback {
uint deposits = 0;
}
// Transaction: 41,143
// Execution: 20,143
contract FallbackDeposit {
uint deposits = 0;
function() {
@chriseth
chriseth / 0 README.md
Last active November 6, 2022 19:55
Formal verification for re-entrant Solidity contracts

This gist shows how formal conditions of Solidity smart contracts can be automatically verified even in the presence of potential re-entrant calls from other contracts.

Solidity already supports formal verification of some contracts that do not make calls to other contracts. This of course excludes any contract that transfers Ether or tokens.

The Solidity contract below models a crude crowdfunding contract that can hold Ether and some person can withdraw Ether according to their shares. It is missing the actual access control, but the point that wants to be made

@haroldtreen
haroldtreen / promise-test.js
Last active August 25, 2023 13:59
Testing promise rejection with Mocha
const { assert } = require('chai');
function isError(e) {
if (typeof e === 'string') {
return Promise.reject(new Error(e));
}
return Promise.resolve(e);
}
@holiman
holiman / Cloner.sol
Last active April 9, 2024 16:36
A generic 'cloner' contract which clones other contract instances
pragma solidity ^0.4.4;
contract X{
string junk;
function y() returns(string){
//Uncomment the 'junk' below to make gas-measurements
//junk="0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345
@raineorshine
raineorshine / assert-throw.js
Last active March 16, 2019 18:37
Asserting solidity throws in truffle tests.
it('should throw an error', cb => {
const result = aMethodThatRejects()
result.then(x => { cb('Expected error. Instead got ' + x) }))
result.catch(() => cb())
})
pragma solidity ^0.4.7;
library convertLib {
function b32toString(bytes32 x) internal returns (string) {
// gas usage: about 1K gas per char.
bytes memory bytesString = new bytes(32);
uint charCount = 0;
pragma solidity ^0.4.7;
contract usingCallback {
function __callback(uint id, string s) {}
}
contract A {