Skip to content

Instantly share code, notes, and snippets.

View naterush's full-sized avatar

Nate Rush naterush

  • University of Pennsylvania
View GitHub Profile
@naterush
naterush / pollard_failure.py
Last active April 17, 2019 14:37
Help me figure out how much this thing fails!
import math
import time
def f(x):
return x**2 + 1
def pollard_rho(N):
xn = 2
x2n = 2
#print("xn: {}, x2n: {}".format(xn, x2n))
@naterush
naterush / factoring.py
Created April 16, 2019 17:53
An implementation of Pollard Rho and Trial Division factoring algorithms
import math
import time
FACTOR = [10972771937, 1690899676867]
def f(x):
return x**2 + 1
def pollard_rho(N):
xn = 2
@naterush
naterush / GasOracle.sol
Created September 10, 2017 04:34
This is taken from a hack-a-thon project w/ the wonderful Eric Tu (https://github.com/tueric) and myself. It's only the essential parts of the gas oracle. More coming soon (hopefully :) ).
pragma solidity ^0.4.8;
// RLP library moved below for readability
contract GasOracle {
using RLP for RLP.RLPItem;
using RLP for RLP.Iterator;
using RLP for bytes;
mapping (uint => BlockHeader) blocks;
@naterush
naterush / AndSomeNonMembers.sol
Last active August 18, 2017 07:13
In token contracts where tokens can only be held by permissioned owners, this allows for a backing token. Trades at the price of the real token - risk of having account seized for bad behavior :~)
pragma solidity ^0.4.15;
import "./MembersOnly.sol";
contract AndSomeNonMembers {
MembersOnly token;
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
function AndSomeNonMembers(address _tokenAdd) {
@naterush
naterush / MembersOnly.sol
Created August 18, 2017 06:24
Assuming initial supply goes to members - only members can ever hold tokens. If a member is removed while holding tokens, their tokens are frozen. Also, no tests include. (don't) Use with caution :~)
// USING
// https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/ownership/Ownable.sol
// https://github.com/ConsenSys/Tokens/blob/master/contracts/StandardToken.sol
pragma solidity ^0.4.15;
import "./Ownable.sol"; // left out for conciseness
contract MembersOnly is Ownable {
uint256 public totalSupply;
@naterush
naterush / SimpleStorage.sol
Created July 25, 2017 16:59
A simple storage contract as an introduction to Solidity.
//Tell the Solidity compiler what version to use
pragma solidity ^0.4.8;
//Declares a new contract
contract SimpleStorage {
//Storage. Persists in between transactions
uint x;
//Allows the unsigned integer stored to be changed
function set(uint newValue) {
pragma solidity ^0.4.8;
//Allows for decentralized incentivization of initilizing storage
//to pay lower fees overall.
contract FuelEfficient {
uint maxGasPrice;
address contractAdd;
function FuelEfficient(uint _maxGasPrice, address add) {
@naterush
naterush / TokenHolder.sol
Created June 4, 2017 21:30
This set of contracts would allow a whale to easily buy many more tokens per block in the case of a sale w/ limited amount by addr, and a limited number of contributions per block. Has not been tested/reviewed :)
pragma solidity ^0.4.10;
import "ERCToken.sol"; //Assumes ERC Tokens standard
contract HoldTokens {
address owner = msg.sender;
ERCToken token;
function buyTokens(bytes data, address tokenAddress) payable {
if (msg.sender != owner) throw;
token = ERCToken(tokenAddress);
@naterush
naterush / AcceptMyTx.sol
Created June 4, 2017 18:54
This contract allows users to keep their gas price very low while still effectively paying miners. This would allow users to circumnavigate any imposed gas price maximums.
pragma solidity ^0.4.10;
contract AcceptMyTx {
function forwardTransaction(address destination, bytes data, uint amountToMiner) payable {
block.coinbase.transfer(amountToMiner);
destination.call.value(msg.value - amountToMiner)(data); //even in case of failure, miner is paid
}
}