Created
July 10, 2018 10:39
-
-
Save Enigmatic331/3e90a871620fb67523228918cf54b3ed to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=false&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.21; | |
contract FiftyYearsChallenge { | |
struct Contribution { | |
uint256 amount; | |
uint256 unlockTimestamp; | |
} | |
Contribution[] queue; | |
uint256 head; | |
address owner; | |
function FiftyYearsChallenge(address player) public payable { | |
require(msg.value == 1 ether); | |
owner = player; | |
queue.push(Contribution(msg.value, now + 50 years)); | |
} | |
function isComplete() public view returns (bool) { | |
return address(this).balance == 0; | |
} | |
function upsert(uint256 index, uint256 timestamp) public payable { | |
require(msg.sender == owner); | |
if (index >= head && index < queue.length) { | |
// Update existing contribution amount without updating timestamp. | |
Contribution storage contribution = queue[index]; | |
contribution.amount += msg.value; | |
} else { | |
// Append a new contribution. Require that each contribution unlock | |
// at least 1 day after the previous one. | |
require(timestamp >= queue[queue.length - 1].unlockTimestamp + 1 days); | |
contribution.amount = msg.value; | |
contribution.unlockTimestamp = timestamp; | |
queue.push(contribution); | |
} | |
} | |
function withdraw(uint256 index) public { | |
require(msg.sender == owner); | |
require(now >= queue[index].unlockTimestamp); | |
// Withdraw this and any earlier contributions. | |
uint256 total = 0; | |
for (uint256 i = head; i <= index; i++) { | |
total += queue[i].amount; | |
// Reclaim storage. | |
delete queue[i]; | |
} | |
// Move the head of the queue forward so we don't have to loop over | |
// already-withdrawn contributions. | |
head = index + 1; | |
msg.sender.transfer(total); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.22; | |
import "./CalebCoin.sol"; | |
import "./SafeMath.sol"; | |
contract OwnedByICOOwner { | |
address public owner; | |
modifier onlyOwner { | |
require(msg.sender == owner); | |
_; | |
} | |
// allow transfer of ownership to another address in case shit hits the fan. | |
function transferOwnership(address newOwner) public onlyOwner { | |
owner = newOwner; | |
} | |
} | |
contract CalebCoinCrowdSale is OwnedByICOOwner { | |
// all values dealt with in wei, unless explicitly specified. | |
// Note: Contract to be loaded with the allocated tokens prior to pre/public sales | |
struct AllowedAddress { | |
uint256 allowedAmount; // amount allocated to contributor | |
uint256 remainder; // amount contributable left | |
bool check; // a check flag | |
} | |
// ==== start and end dates ==== // | |
uint256 public startDate; // Start date - to be determined | |
uint256 public endDate; // End date - to be determined | |
// ==== address of Caleb Coin ==== // | |
CalebCoin public token; | |
// ==== funds will be transferred to this address ==== // | |
address public coldStorage; | |
// // ==== maximum contribution per address ==== // | |
// uint public constant MAX_CONTRIBUTION = xx ether; | |
// ==== mappings (e.g. balance, whitelist checks) ==== // | |
mapping(address => uint256) public balanceOf; | |
mapping (address => AllowedAddress) public whiteList; | |
// ==== hardcap and software of ICO ==== // | |
uint256 public hardCap; | |
bool public isHalted; // is the crowdsale halted | |
uint256 public totalCollection; // total collected by the crowdsale | |
using SafeMath for uint256; | |
constructor(address _CalebCoin, address _contributionColdStorage, | |
uint256 _hardCap, | |
uint256 _startDate, uint256 _endDate) { | |
token = CalebCoin(_CalebCoin); // initialising reference to ERC20 | |
coldStorage = _contributionColdStorage; // cold wallet meant for contribution holding | |
startDate = _startDate; // ICO start date in UNIX time | |
endDate = _endDate; // ICO end date in UNIX time | |
owner = msg.sender; | |
hardCap = _hardCap * 10 ** 18; // hardcap in wei | |
} | |
function() public payable { | |
uint256 a; | |
// crowdsale checks | |
// accept only contributions > 0.1ETH | |
require(msg.value >= 0.1 ether); | |
// limit to gas price at 50 gwei. | |
require(tx.gasprice <= 50000000000 wei); | |
// requires crowdsale not closed | |
require(isCrowdSaleOngoing()); | |
//has to not be halted | |
require(!isHalted); | |
// Now check if individual is allowed to contribute | |
require(whiteList[msg.sender].check); | |
// and if this address still has any remainder allocation | |
require(whiteList[msg.sender].remainder > 0); | |
// set remainder amount to variable | |
uint256 remainder = whiteList[msg.sender].remainder; | |
// get amount sent | |
uint256 payAmt = msg.value; | |
if (payAmt <= remainder && payAmt.add(totalCollection) <= hardCap) { | |
// deduct payAmt off remainder | |
a = (remainder.sub(payAmt)); | |
// update remainder to whitelist | |
whiteList[msg.sender].remainder = a; | |
// update total collection from the received amount | |
totalCollection = totalCollection.add(payAmt); | |
// send tokens (payAmt * multiplier) | |
token.distributeTokens(msg.sender, calculateBonuses(payAmt)); | |
// send ethers to cold storage | |
coldStorage.send(payAmt); | |
} else { | |
// first check allocation | |
if (payAmt > remainder) { | |
// amount sent more than allocation (or remainder allocation) | |
// give contributor what is left of the tokens allocated, send back extra ethers. | |
// "a" variable denotes ethers to send back | |
a = (payAmt.sub(remainder)); | |
payAmt = remainder; | |
} | |
// during last transaction - if allowed contribution more than tokens available | |
if (payAmt.add(totalCollection) > hardCap) { | |
// First reset payAmt to msg.value. This is needed if payAmt > remainder as it was altered. | |
payAmt = msg.value; | |
// refund amount = payAmt + totalCollection - hard cap. | |
a = payAmt.add(totalCollection).sub(hardCap); | |
// allocation = hardCap - totalCollection | |
payAmt = hardCap.sub(totalCollection); | |
} | |
// minus payAmt off remainder | |
whiteList[msg.sender].remainder = whiteList[msg.sender].remainder.sub(payAmt); | |
// add contribution amount to total collected | |
totalCollection = totalCollection.add(payAmt); | |
//send tokens (e.g. 500 tokens per eth) | |
token.distributeTokens(msg.sender, calculateBonuses(payAmt)); | |
// return the rest of the ethers as denoted in "a" | |
msg.sender.send(a); | |
// send ethers to multisig wallet | |
coldStorage.send(payAmt); | |
} | |
} | |
function addToWhiteList(address[] _contributor, uint256[] _amount) external onlyOwner { | |
require(_contributor.length < 255); | |
for (uint8 i = 0; i < _contributor.length; i++) { | |
address tmpAddress = _contributor[i]; | |
uint256 tmpValue = _amount[i]; | |
whiteList[tmpAddress].allowedAmount = tmpValue; | |
whiteList[tmpAddress].remainder = tmpValue; | |
whiteList[tmpAddress].check = true; | |
} | |
} | |
function removeFromWhiteList(address contributor) public onlyOwner { | |
whiteList[contributor].check = false; | |
} | |
function calculateBonuses(uint256 amount) internal returns (uint256 total) { | |
return amount; | |
} | |
/** | |
* Halts token sales - Only callable by owner | |
* Ideally never used. | |
*/ | |
function haltTokenSales(bool _status) public onlyOwner { | |
isHalted = _status; | |
} | |
/** | |
* Notifies ERC20 contract for tokens to be burnt | |
*/ | |
function burnTokens() public onlyOwner { | |
token.burnSent(token.balanceOf(this)); | |
} | |
/** | |
* Internal check to see if crowdsale is still ongoing. | |
* Defaults to return false unless within crowdsale timeframe. | |
*/ | |
function isCrowdSaleOngoing() internal returns (bool ongoing) { | |
require(now >= startDate && now <= endDate); | |
require(totalCollection < hardCap); | |
return true; | |
} | |
/** | |
* Withdraws token from smart contract. | |
*/ | |
function withdrawTokens(uint256 amount) public onlyOwner { | |
token.distributeTokens(owner, amount); | |
} | |
/** | |
* If someone sends some ERC20 tokens, we could withdraw and return them | |
* Full credits to KyberNetwork. | |
*/ | |
function emergencyERC20Drain(ERC20 _token, uint256 amount) public onlyOwner { | |
_token.transfer(owner, amount); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.17; | |
import './token.sol'; | |
/// @title Dutch auction contract - distribution of a fixed number of tokens using an auction. | |
/// The contract code is inspired by the Gnosis auction contract. Main difference is that the | |
/// auction ends if a fixed number of tokens was sold. | |
contract DutchAuction { | |
/* | |
* Auction for the RDN Token. | |
* | |
* Terminology: | |
* 1 token unit = Rei | |
* 1 token = RDN = Rei * token_multiplier | |
* token_multiplier set from token's number of decimals (i.e. 10 ** decimals) | |
*/ | |
// Wait 7 days after the end of the auction, before ayone can claim tokens | |
uint constant public token_claim_waiting_period = 7 days; | |
/* | |
* Storage | |
*/ | |
CalebCoin public token; | |
address public owner_address; | |
address public wallet_address; | |
// Price decay function parameters to be changed depending on the desired outcome | |
// Starting price in WEI; e.g. 2 * 10 ** 18 | |
uint public price_start; | |
// Divisor constant; e.g. 524880000 | |
uint public price_constant; | |
// Divisor exponent; e.g. 3 | |
uint32 public price_exponent; | |
// For calculating elapsed time for price | |
uint public start_time; | |
uint public end_time; | |
uint public start_block; | |
// Keep track of all ETH received in the bids | |
uint public received_wei; | |
// Keep track of cumulative ETH funds for which the tokens have been claimed | |
uint public funds_claimed; | |
uint public token_multiplier; | |
// Total number of Rei (RDN * token_multiplier) that will be auctioned | |
uint public num_tokens_auctioned; | |
// Wei per RDN (Rei * token_multiplier) | |
uint public final_price; | |
mapping (address => uint) public bids; | |
Stages public stage; | |
/* | |
* Enums | |
*/ | |
enum Stages { | |
AuctionDeployed, | |
AuctionSetUp, | |
AuctionStarted, | |
AuctionEnded, | |
TokensDistributed | |
} | |
/* | |
* Modifiers | |
*/ | |
modifier atStage(Stages _stage) { | |
require(stage == _stage); | |
_; | |
} | |
modifier isOwner() { | |
require(msg.sender == owner_address); | |
_; | |
} | |
/* | |
* Events | |
*/ | |
event Deployed( | |
uint indexed _price_start, | |
uint indexed _price_constant, | |
uint32 indexed _price_exponent | |
); | |
event Setup(); | |
event AuctionStarted(uint indexed _start_time, uint indexed _block_number); | |
event BidSubmission( | |
address indexed _sender, | |
uint _amount, | |
uint _missing_funds | |
); | |
event ClaimedTokens(address indexed _recipient, uint _sent_amount); | |
event AuctionEnded(uint _final_price); | |
event TokensDistributed(); | |
/* | |
* Public functions | |
*/ | |
/// @dev Contract constructor function sets the starting price, divisor constant and | |
/// divisor exponent for calculating the Dutch Auction price. | |
/// @param _wallet_address Wallet address to which all contributed ETH will be forwarded. | |
/// @param _price_start High price in WEI at which the auction starts. | |
/// @param _price_constant Auction price divisor constant. | |
/// @param _price_exponent Auction price divisor exponent. | |
function DutchAuction( | |
address _wallet_address, | |
uint _price_start, | |
uint _price_constant, | |
uint32 _price_exponent) | |
public | |
{ | |
require(_wallet_address != 0x0); | |
wallet_address = _wallet_address; | |
owner_address = msg.sender; | |
stage = Stages.AuctionDeployed; | |
changeSettings(_price_start, _price_constant, _price_exponent); | |
Deployed(_price_start, _price_constant, _price_exponent); | |
} | |
/// @dev Fallback function for the contract, which calls bid() if the auction has started. | |
function () public payable atStage(Stages.AuctionStarted) { | |
bid(); | |
} | |
/// @notice Set `_token_address` as the token address to be used in the auction. | |
/// @dev Setup function sets external contracts addresses. | |
/// @param _token_address Token address. | |
function setup(address _token_address) public isOwner atStage(Stages.AuctionDeployed) { | |
require(_token_address != 0x0); | |
token = CalebCoin(_token_address); | |
// Get number of Rei (RDN * token_multiplier) to be auctioned from token auction balance | |
num_tokens_auctioned = token.balanceOf(address(this)); | |
// Set the number of the token multiplier for its decimals | |
token_multiplier = 10 ** uint(token.decimals()); | |
stage = Stages.AuctionSetUp; | |
Setup(); | |
} | |
/// @notice Set `_price_start`, `_price_constant` and `_price_exponent` as | |
/// the new starting price, price divisor constant and price divisor exponent. | |
/// @dev Changes auction price function parameters before auction is started. | |
/// @param _price_start Updated start price. | |
/// @param _price_constant Updated price divisor constant. | |
/// @param _price_exponent Updated price divisor exponent. | |
function changeSettings( | |
uint _price_start, | |
uint _price_constant, | |
uint32 _price_exponent) | |
internal | |
isOwner | |
{ | |
require(stage == Stages.AuctionDeployed || stage == Stages.AuctionSetUp); | |
require(_price_start > 0); | |
require(_price_constant > 0); | |
price_start = _price_start; | |
price_constant = _price_constant; | |
price_exponent = _price_exponent; | |
} | |
/// @notice Start the auction. | |
/// @dev Starts auction and sets start_time. | |
function startAuction() public isOwner atStage(Stages.AuctionSetUp) { | |
stage = Stages.AuctionStarted; | |
start_time = now; | |
start_block = block.number; | |
AuctionStarted(start_time, start_block); | |
} | |
/// @notice Finalize the auction - sets the final RDN token price and changes the auction | |
/// stage after no bids are allowed anymore. | |
/// @dev Finalize auction and set the final RDN token price. | |
function finalizeAuction() public atStage(Stages.AuctionStarted) | |
{ | |
// Missing funds should be 0 at this point | |
uint missing_funds = missingFundsToEndAuction(); | |
require(missing_funds == 0); | |
// Calculate the final price = WEI / RDN = WEI / (Rei / token_multiplier) | |
// Reminder: num_tokens_auctioned is the number of Rei (RDN * token_multiplier) that are auctioned | |
final_price = token_multiplier * received_wei / num_tokens_auctioned; | |
end_time = now; | |
stage = Stages.AuctionEnded; | |
AuctionEnded(final_price); | |
assert(final_price > 0); | |
} | |
/// --------------------------------- Auction Functions ------------------ | |
/// @notice Send `msg.value` WEI to the auction from the `msg.sender` account. | |
/// @dev Allows to send a bid to the auction. | |
function bid() public payable atStage(Stages.AuctionStarted) { | |
proxyBid(msg.sender); | |
} | |
/// @notice Send `msg.value` WEI to the auction from the `msg.sender` account | |
/// and the `receiver` account will receive the tokens if claimed. | |
/// @dev Allows to send a bid to the auction. | |
/// @param receiver_address Token receiver account address. | |
function proxyBid(address receiver_address) | |
public | |
payable | |
atStage(Stages.AuctionStarted) | |
{ | |
require(receiver_address != 0x0); | |
require(receiver_address != address(this)); | |
require(receiver_address != address(token)); | |
require(msg.value > 0); | |
assert(bids[receiver_address] + msg.value >= msg.value); | |
// Missing funds without the current bid value | |
uint missing_funds = missingFundsToEndAuction(); | |
// We require bid values to be less than the funds missing to end the auction | |
// at the current price. | |
require(msg.value <= missing_funds); | |
bids[receiver_address] += msg.value; | |
received_wei += msg.value; | |
// Send bid amount to wallet | |
wallet_address.transfer(msg.value); | |
BidSubmission(receiver_address, msg.value, missing_funds); | |
assert(received_wei >= msg.value); | |
} | |
/// @notice Claim auction tokens for `msg.sender` after the auction has ended. | |
/// @dev Claims tokens for `msg.sender` after auction. To be used if tokens can | |
/// be claimed by beneficiaries, individually. | |
function claimTokens() public atStage(Stages.AuctionEnded) returns (bool) { | |
return proxyClaimTokens(msg.sender); | |
} | |
/// @notice Claim auction tokens for `receiver_address` after the auction has ended. | |
/// @dev Claims tokens for `receiver_address` after auction has ended. | |
/// @param receiver_address Tokens will be assigned to this address if eligible. | |
function proxyClaimTokens(address receiver_address) | |
public | |
atStage(Stages.AuctionEnded) | |
returns (bool) | |
{ | |
// Waiting period after the end of the auction, before anyone can claim tokens | |
// Ensures enough time to check if auction was finalized correctly | |
// before users start transacting tokens | |
require(now > end_time + token_claim_waiting_period); | |
require(receiver_address != 0x0); | |
if (bids[receiver_address] == 0) { | |
return false; | |
} | |
// Number of Rei = bid_wei / Rei = bid_wei / (wei_per_RDN * token_multiplier) | |
uint num = token_multiplier * bids[receiver_address] / final_price; | |
// Update the total amount of funds for which tokens have been claimed | |
funds_claimed += bids[receiver_address]; | |
// Set receiver bid to 0 before assigning tokens | |
bids[receiver_address] = 0; | |
require(token.transfer(receiver_address, num)); | |
ClaimedTokens(receiver_address, num); | |
// After the last tokens are claimed, we change the auction stage | |
// Due to the above logic, rounding errors will not be an issue | |
if (funds_claimed == received_wei) { | |
stage = Stages.TokensDistributed; | |
TokensDistributed(); | |
} | |
assert(token.balanceOf(receiver_address) >= num); | |
assert(bids[receiver_address] == 0); | |
return true; | |
} | |
/// @notice Get the RDN price in WEI during the auction, at the time of | |
/// calling this function. Returns `0` if auction has ended. | |
/// Returns `price_start` before auction has started. | |
/// @dev Calculates the current RDN token price in WEI. | |
/// @return Returns WEI per RDN (token_multiplier * Rei). | |
function price() public constant returns (uint) { | |
if (stage == Stages.AuctionEnded || | |
stage == Stages.TokensDistributed) { | |
return 0; | |
} | |
return calcTokenPrice(); | |
} | |
/// @notice Get the missing funds needed to end the auction, | |
/// calculated at the current RDN price in WEI. | |
/// @dev The missing funds amount necessary to end the auction at the current RDN price in WEI. | |
/// @return Returns the missing funds amount in WEI. | |
function missingFundsToEndAuction() constant public returns (uint) { | |
// num_tokens_auctioned = total number of Rei (RDN * token_multiplier) that is auctioned | |
uint required_wei_at_price = num_tokens_auctioned * price() / token_multiplier; | |
if (required_wei_at_price <= received_wei) { | |
return 0; | |
} | |
// assert(required_wei_at_price - received_wei > 0); | |
return required_wei_at_price - received_wei; | |
} | |
/* | |
* Private functions | |
*/ | |
/// @dev Calculates the token price (WEI / RDN) at the current timestamp | |
/// during the auction; elapsed time = 0 before auction starts. | |
/// Based on the provided parameters, the price does not change in the first | |
/// `price_constant^(1/price_exponent)` seconds due to rounding. | |
/// Rounding in `decay_rate` also produces values that increase instead of decrease | |
/// in the beginning; these spikes decrease over time and are noticeable | |
/// only in first hours. This should be calculated before usage. | |
/// @return Returns the token price - Wei per RDN. | |
function calcTokenPrice() constant public returns (uint) { | |
uint elapsed; | |
if (stage == Stages.AuctionStarted) { | |
elapsed = now - start_time; | |
} | |
uint decay_rate = elapsed ** price_exponent / price_constant; | |
return price_start * (1 + elapsed) / (1 + elapsed + decay_rate); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.22; | |
contract exploit1 { | |
mapping(address => uint256) public balanceOf; | |
bool public youWin; // your goal is to get this to true | |
uint256 constant exchrate = 1 ether; | |
constructor() payable public { youWin = false; } | |
// specify the amount of tokens to buy | |
// function will check if sent in amount matches exchange rate | |
function buy(uint256 _amount) payable public { | |
// check to ensure exchange rate is correct | |
require(msg.value == _amount * exchrate); | |
balanceOf[msg.sender] = balanceOf[msg.sender] + _amount; | |
} | |
// specify the amount of tokens to sell | |
// function will check if amount to sell is lesser or equals to balance | |
function sell(uint256 _amount) public { | |
// check if we are allowed to withdraw this _amount | |
require(_amount <= balanceOf[msg.sender]); | |
balanceOf[msg.sender] = balanceOf[msg.sender] - _amount; | |
if (msg.sender.send(_amount * exchrate)) { | |
if (address(this).balance < 1 ether) { | |
// you win!! | |
youWin = true; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.22; | |
contract exploit2 { | |
address public commitOwner; | |
bytes32 public commitHash; | |
uint256 public futureblockNum; | |
bool public youWin; // set this to true to win! | |
constructor() payable public { youWin = false; } | |
// commit a guess | |
// each guess costs 1 ether | |
function commitGuess(bytes32 _hash) payable public { | |
require(commitOwner == 0 && msg.value == 1 ether); | |
commitOwner = msg.sender; | |
commitHash = _hash; | |
futureblockNum = block.number + 1; | |
} | |
// check if a committed guess is correct | |
// requires function caller to be person who committed the guess | |
// and current blocknum has passed | |
function checkGuess() public { | |
require(commitOwner == msg.sender && block.number > futureblockNum); | |
bytes32 tmp = blockhash(futureblockNum); | |
if (commitHash == tmp) { | |
if (msg.sender.send(2 ether)) { | |
youWin = true; | |
} | |
} else { | |
commitOwner = 0; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.24; | |
contract storingFunction { | |
string public stateStorage; | |
function storeIt(string _value) { | |
stateStorage = _value; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.22; | |
import "./SafeMath.sol"; | |
contract ERC20 { | |
function totalSupply() public view returns (uint256); | |
function balanceOf(address) public view returns (uint256); | |
function transfer(address, uint256) public returns (bool); | |
function transferFrom(address, address, uint256) public returns (bool); | |
function approve(address, uint256) public returns (bool); | |
function allowance(address, address) public view returns (uint256); | |
event Transfer(address indexed _from, address indexed _to, uint256 _value); | |
event Approval(address indexed _owner, address indexed _spender, uint256 _value); | |
} | |
contract Owned { | |
address public owner; | |
modifier onlyOwner { | |
require(msg.sender == owner); | |
_; | |
} | |
// allow transfer of ownership to another address in case shit hits the fan. | |
function transferOwnership(address newOwner) public onlyOwner { | |
owner = newOwner; | |
} | |
} | |
contract StandardToken is ERC20 { | |
using SafeMath for uint256; | |
mapping (address => uint256) balances; | |
mapping (address => mapping (address => uint256)) allowed; | |
function transfer(address _to, uint256 _value) public returns (bool) { | |
balances[msg.sender] = balances[msg.sender].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
emit Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { | |
require(_to != address(0)); | |
require(_value <= balances[_from]); | |
require(_value <= allowed[_from][msg.sender]); | |
balances[_from] = balances[_from].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); | |
emit Transfer(_from, _to, _value); | |
return true; | |
} | |
function balanceOf(address _owner) public view returns (uint256 balance) { | |
return balances[_owner]; | |
} | |
function approve(address _spender, uint256 _value) public returns (bool success) { | |
// Added to prevent potential race attack. | |
// forces caller of this function to ensure address allowance is already 0 | |
// ref: https://github.com/ethereum/EIPs/issues/738 | |
require((_value == 0) || (allowed[msg.sender][_spender] == 0)); | |
allowed[msg.sender][_spender] = _value; | |
emit Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
function allowance(address _owner, address _spender) public view returns (uint256 remaining) { | |
return allowed[_owner][_spender]; | |
} | |
} | |
//token contract | |
contract GalaxiumCoin is Owned, StandardToken { | |
event Burn(address indexed burner, uint256 value); | |
/* Public variables of the token */ | |
string public name; | |
uint8 public decimals; | |
string public symbol; | |
uint256 public totalSupply; | |
address public distributionAddress; | |
bool public isTransferable = false; | |
function GalaxiumCoin() { | |
name = "Galaxium Coin"; | |
decimals = 18; | |
symbol = "GXM"; | |
totalSupply = 50000000 * 10 ** uint256(decimals); | |
owner = msg.sender; | |
//transfer all to handler address | |
balances[msg.sender] = totalSupply; | |
emit Transfer(0x0, msg.sender, totalSupply); | |
} | |
function transfer(address _to, uint256 _value) public returns (bool) { | |
require(isTransferable); | |
return super.transfer(_to, _value); | |
} | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { | |
require(isTransferable); | |
return super.transferFrom(_from, _to, _value); | |
} | |
/** | |
* Get totalSupply of tokens - Minus any from address 0 if that was used as a burnt method | |
* Suggested way is still to use the burnSent function | |
*/ | |
function totalSupply() public view returns (uint256) { | |
return totalSupply; | |
} | |
/** | |
* unlocks tokens, only allowed once | |
*/ | |
function enableTransfers() public onlyOwner { | |
isTransferable = true; | |
} | |
/** | |
* Callable by anyone | |
* Accepts an input of the number of tokens to be burnt held by the sender. | |
*/ | |
function burnSent(uint256 _value) public { | |
require(_value > 0); | |
require(_value <= balances[msg.sender]); | |
address burner = msg.sender; | |
balances[burner] = balances[burner].sub(_value); | |
totalSupply = totalSupply.sub(_value); | |
emit Burn(burner, _value); | |
} | |
/** | |
* Allow distribution helper to help with distributeToken function | |
*/ | |
function setDistributionAddress(address _setAddress) public onlyOwner { | |
distributionAddress = _setAddress; | |
} | |
/** | |
* Called by owner to transfer tokens - Managing manual distribution. | |
* Also allow distribution contract to call for this function | |
*/ | |
function distributeTokens(address _to, uint256 _value) public { | |
require(distributionAddress == msg.sender || owner == msg.sender); | |
super.transfer(_to, _value); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.21; | |
contract testing { | |
int256 constant INT256_MIN = int256((uint256(1) << 255)); | |
int256 constant INT256_MAX = int256(~((uint256(1) << 255))); | |
uint256 constant UINT256_MIN = 0; | |
uint256 constant UINT256_MAX = ~uint256(0); | |
function returnMaxInt() public pure returns (int256) { | |
return INT256_MAX; | |
} | |
function returnMaxUInt() public pure returns (uint256) { | |
return UINT256_MAX; | |
} | |
function returnMinInt() public pure returns (int256) { | |
return INT256_MIN; | |
} | |
function returnMinUInt() public pure returns (uint256) { | |
return UINT256_MIN; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.18; | |
/** | |
* @title SafeMath | |
* @dev Math operations with safety checks that throw on error | |
*/ | |
library SafeMath { | |
/** | |
* @dev Multiplies two numbers, throws on overflow. | |
*/ | |
function mul(uint256 a, uint256 b) internal pure returns (uint256) { | |
if (a == 0) { | |
return 0; | |
} | |
uint256 c = a * b; | |
assert(c / a == b); | |
return c; | |
} | |
/** | |
* @dev Integer division of two numbers, truncating the quotient. | |
*/ | |
function div(uint256 a, uint256 b) internal pure returns (uint256) { | |
// assert(b > 0); // Solidity automatically throws when dividing by 0 | |
uint256 c = a / b; | |
// assert(a == b * c + a % b); // There is no case in which this doesn't hold | |
return c; | |
} | |
/** | |
* @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). | |
*/ | |
function sub(uint256 a, uint256 b) internal pure returns (uint256) { | |
assert(b <= a); | |
return a - b; | |
} | |
/** | |
* @dev Adds two numbers, throws on overflow. | |
*/ | |
function add(uint256 a, uint256 b) internal pure returns (uint256) { | |
uint256 c = a + b; | |
assert(c >= a); | |
return c; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"accounts": { | |
"account{0}": "0x6458eafc3076f104a25492552ddf98f224813348" | |
}, | |
"linkReferences": {}, | |
"transactions": [ | |
{ | |
"timestamp": 1527840734017, | |
"record": { | |
"value": "0", | |
"parameters": [ | |
"1", | |
"115792089237316195423570985008687907853269984665640564039457584007913129553535" | |
], | |
"to": "created{undefined}", | |
"name": "upsert", | |
"type": "function", | |
"from": "account{0}" | |
} | |
} | |
], | |
"abis": {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Test{ | |
function MinInt256() view public returns (int256){ | |
return int256((uint256(1) << 255)); | |
} | |
function MaxUint() view public returns (uint256) { | |
return 2**256 - 1; | |
} | |
function MaxInt256() view public returns (int256) { | |
return int256(~((uint256(1) << 255))); | |
} | |
//Pass a value, what is left to be the Max, and will return -1 | |
function OverflowInt256ByQuantity(int256 value, int256 valueToAddToMaxInt256) view public returns (int256) { | |
return (value + valueToAddToMaxInt256 + 1) + MaxInt256(); | |
} | |
//Pass a value, what is left to be the Min, and will return -1 | |
function UnderflowInt256ByQuantity(int256 value, int256 valueToAddToMinInt256) view public returns (int256) { | |
return (value + valueToAddToMinInt256 - 1) + MinInt256(); | |
} | |
//This is -1 | |
function OverflowInt256() view public returns (int256) { | |
return (MaxInt256() + 1) + MaxInt256(); | |
} | |
//This is -1 | |
function UnderflowInt256() view public returns (int256) { | |
return (MinInt256() - 1) + MinInt256(); | |
} | |
function OverflowUInt256() view public returns (uint256) { | |
return MaxUint() + 1; | |
} | |
//Pass a value, what is left to be the Max, and will return 0 | |
function OverflowUInt256ByQuantity(uint256 value, uint256 valueToAddToMaxUInt256) view public returns (uint256) { | |
return value + valueToAddToMaxUInt256 + 1; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Token { | |
/// @return total amount of tokens | |
function totalSupply() constant returns (uint256 supply) {} | |
/// @param _owner The address from which the balance will be retrieved | |
/// @return The balance | |
function balanceOf(address _owner) constant returns (uint256 balance) {} | |
/// @notice send `_value` token to `_to` from `msg.sender` | |
/// @param _to The address of the recipient | |
/// @param _value The amount of token to be transferred | |
/// @return Whether the transfer was successful or not | |
function transfer(address _to, uint256 _value) returns (bool success) {} | |
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` | |
/// @param _from The address of the sender | |
/// @param _to The address of the recipient | |
/// @param _value The amount of token to be transferred | |
/// @return Whether the transfer was successful or not | |
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {} | |
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens | |
/// @param _spender The address of the account able to transfer the tokens | |
/// @param _value The amount of wei to be approved for transfer | |
/// @return Whether the approval was successful or not | |
function approve(address _spender, uint256 _value) returns (bool success) {} | |
/// @param _owner The address of the account owning tokens | |
/// @param _spender The address of the account able to transfer the tokens | |
/// @return Amount of remaining tokens allowed to spent | |
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {} | |
event Transfer(address indexed _from, address indexed _to, uint256 _value); | |
event Approval(address indexed _owner, address indexed _spender, uint256 _value); | |
} | |
/* | |
This implements ONLY the standard functions and NOTHING else. | |
For a token like you would want to deploy in something like Mist, see HumanStandardToken.sol. | |
If you deploy this, you won't have anything useful. | |
Implements ERC 20 Token standard: https://github.com/ethereum/EIPs/issues/20 | |
.*/ | |
contract StandardToken is Token { | |
function transfer(address _to, uint256 _value) returns (bool success) { | |
//Default assumes totalSupply can't be over max (2^256 - 1). | |
//If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap. | |
//Replace the if with this one instead. | |
//if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) { | |
if (balances[msg.sender] >= _value && _value > 0) { | |
balances[msg.sender] -= _value; | |
balances[_to] += _value; | |
Transfer(msg.sender, _to, _value); | |
return true; | |
} else { return false; } | |
} | |
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) { | |
//same as above. Replace this line with the following if you want to protect against wrapping uints. | |
//if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) { | |
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) { | |
balances[_to] += _value; | |
balances[_from] -= _value; | |
allowed[_from][msg.sender] -= _value; | |
Transfer(_from, _to, _value); | |
return true; | |
} else { return false; } | |
} | |
function balanceOf(address _owner) constant returns (uint256 balance) { | |
return balances[_owner]; | |
} | |
function approve(address _spender, uint256 _value) returns (bool success) { | |
allowed[msg.sender][_spender] = _value; | |
Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
function allowance(address _owner, address _spender) constant returns (uint256 remaining) { | |
return allowed[_owner][_spender]; | |
} | |
mapping (address => uint256) balances; | |
mapping (address => mapping (address => uint256)) allowed; | |
uint256 public totalSupply; | |
} | |
/* | |
This Token Contract implements the standard token functionality (https://github.com/ethereum/EIPs/issues/20) as well as the following OPTIONAL extras intended for use by humans. | |
In other words. This is intended for deployment in something like a Token Factory or Mist wallet, and then used by humans. | |
Imagine coins, currencies, shares, voting weight, etc. | |
Machine-based, rapid creation of many tokens would not necessarily need these extra features or will be minted in other manners. | |
1) Initial Finite Supply (upon creation one specifies how much is minted). | |
2) In the absence of a token registry: Optional Decimal, Symbol & Name. | |
3) Optional approveAndCall() functionality to notify a contract if an approval() has occurred. | |
.*/ | |
contract HumanStandardToken is StandardToken { | |
function () { | |
//if ether is sent to this address, send it back. | |
throw; | |
} | |
/* Public variables of the token */ | |
/* | |
NOTE: | |
The following variables are OPTIONAL vanities. One does not have to include them. | |
They allow one to customise the token contract & in no way influences the core functionality. | |
Some wallets/interfaces might not even bother to look at this information. | |
*/ | |
string public name; //fancy name: eg Simon Bucks | |
uint8 public decimals; //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether. | |
string public symbol; //An identifier: eg SBX | |
string public version = 'H0.1'; //human 0.1 standard. Just an arbitrary versioning scheme. | |
function HumanStandardToken( | |
uint256 _initialAmount, | |
string _tokenName, | |
uint8 _decimalUnits, | |
string _tokenSymbol | |
) { | |
balances[msg.sender] = _initialAmount; // Give the creator all initial tokens | |
totalSupply = _initialAmount; // Update total supply | |
name = _tokenName; // Set the name for display purposes | |
decimals = _decimalUnits; // Amount of decimals for display purposes | |
symbol = _tokenSymbol; // Set the symbol for display purposes | |
} | |
/* Approves and then calls the receiving contract */ | |
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) { | |
allowed[msg.sender][_spender] = _value; | |
Approval(msg.sender, _spender, _value); | |
//call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this. | |
//receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData) | |
//it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead. | |
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; } | |
return true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.22; | |
contract addNumber { | |
uint256 sum; | |
function addNumber(uint256 startingNum) public { | |
sum = startingNum; | |
} | |
function set(uint256 input) public { | |
sum = sum + input; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.24; | |
contract helloworld { | |
event logTestDataSet( | |
bytes32 indexed _vID, // vehicle ID of the ride | |
bytes32 indexed _tripID, // trip ID | |
bytes32 indexed _DAOID, | |
bytes32 _checkSum, // hash of total collected data per QIQ's service layer | |
bytes32 _currency, | |
uint256 _cost, | |
uint256 _startTime, // start time | |
uint256 _endTime, // end time | |
uint256 _distance // distance of travel | |
); | |
function uploadData(bytes32[] _vID, bytes32[] _tripID, bytes32[] _DAOID, bytes32[] _checkSum, bytes32[] _currency, uint256[] _cost, uint256[] _startTime, uint256[] _endTime, uint256[] _distance, uint256 x) public { | |
for(uint i = 0; i < x; i++) { | |
emit logTestDataSet(_vID[i], _tripID[i], _DAOID[i], _checkSum[i], _currency[i], _cost[i], _startTime[i], _endTime[i], _distance[i]); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.24; | |
import "./function.sol"; | |
contract testStorage { | |
storingFunction x = new storingFunction(); | |
function storeSomething() public { | |
string memory stringToStore = "0x12345678901234678 and stuff"; | |
x.storeIt(stringToStore); | |
} | |
function show() public view returns (string) { | |
string memory tmp = x.stateStorage(); | |
return tmp; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.24; | |
contract testDecay { | |
uint public start_time = block.timestamp; | |
uint price_start = 2000000000000000000; | |
uint price_exponent = 3; | |
uint price_constant = 1574640000; | |
function calcTokenPrice() constant public returns (uint) { | |
uint elapsed; | |
elapsed = now - start_time; | |
uint decay_rate = elapsed ** price_exponent / price_constant; | |
return price_start * (1 + elapsed) / (1 + elapsed + decay_rate); | |
} | |
function getcurrentTime() view public returns (uint) { | |
return block.timestamp; | |
} | |
function getElapsed() view public returns (uint) { | |
uint elapsed; | |
elapsed = now - start_time; | |
return elapsed; | |
} | |
function getDecayRate() constant public returns (uint) { | |
uint elapsed; | |
elapsed = now - start_time; | |
uint decay_rate = elapsed ** price_exponent / price_constant; | |
return decay_rate; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.21; | |
import "./SafeMath.sol"; | |
contract ERC20 { | |
function totalSupply() public view returns (uint256); | |
function balanceOf(address) public view returns (uint256); | |
function transfer(address, uint256) public returns (bool); | |
function transferFrom(address, address, uint256) public returns (bool); | |
function approve(address, uint256) public returns (bool); | |
function allowance(address, address) public view returns (uint256); | |
event Transfer(address indexed _from, address indexed _to, uint256 _value); | |
event Approval(address indexed _owner, address indexed _spender, uint256 _value); | |
} | |
contract Owned { | |
address public owner; | |
modifier onlyOwner { | |
require(msg.sender == owner); | |
_; | |
} | |
// allow transfer of ownership to another address in case shit hits the fan. | |
function transferOwnership(address newOwner) public onlyOwner { | |
owner = newOwner; | |
} | |
} | |
contract StandardToken is ERC20 { | |
using SafeMath for uint256; | |
mapping (address => uint256) balances; | |
mapping (address => mapping (address => uint256)) allowed; | |
function transfer(address _to, uint256 _value) public returns (bool) { | |
balances[msg.sender] = balances[msg.sender].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
emit Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { | |
require(_to != address(0)); | |
require(_value <= balances[_from]); | |
require(_value <= allowed[_from][msg.sender]); | |
balances[_from] = balances[_from].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); | |
emit Transfer(_from, _to, _value); | |
return true; | |
} | |
function balanceOf(address _owner) public view returns (uint256 balance) { | |
return balances[_owner]; | |
} | |
function approve(address _spender, uint256 _value) public returns (bool success) { | |
// Added to prevent potential race attack. | |
// forces caller of this function to ensure address allowance is already 0 | |
// ref: https://github.com/ethereum/EIPs/issues/738 | |
require((_value == 0) || (allowed[msg.sender][_spender] == 0)); | |
allowed[msg.sender][_spender] = _value; | |
emit Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
function allowance(address _owner, address _spender) public view returns (uint256 remaining) { | |
return allowed[_owner][_spender]; | |
} | |
} | |
//token contract | |
contract CalebCoin is StandardToken, Owned { | |
event Burn(address indexed burner, uint256 value); | |
/* Public variables of the token */ | |
string public name; | |
uint8 public decimals; | |
string public symbol; | |
uint256 public totalSupply; | |
address public distributionAddress; | |
bool public isTransferable; | |
constructor(string _name, uint8 _decimals, string _sym, uint256 _totalSupply) public { | |
name = _name; | |
decimals = _decimals; | |
symbol = _sym; | |
totalSupply = _totalSupply * 10 ** uint256(decimals); | |
owner = msg.sender; | |
//transfer all to handler address | |
balances[msg.sender] = totalSupply; | |
emit Transfer(0x0, msg.sender, totalSupply); | |
isTransferable = false; | |
} | |
function transfer(address _to, uint256 _value) public returns (bool) { | |
require(isTransferable); | |
return super.transfer(_to, _value); | |
} | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { | |
require(isTransferable); | |
return super.transferFrom(_from, _to, _value); | |
} | |
/** | |
* Get totalSupply of tokens - Minus any from address 0 if that was used as a burnt method | |
* Suggested way is still to use the burnSent function | |
*/ | |
function totalSupply() public view returns (uint256) { | |
return totalSupply; | |
} | |
function setTransferable() public onlyOwner { | |
isTransferable = true; | |
} | |
function distributeTokens(address _to, uint256 _value) public returns (bool) { | |
require(msg.sender == owner || msg.sender == distributionAddress); | |
return super.transfer(_to, _value); | |
} | |
function setdistributionAddress(address _set) public onlyOwner { | |
distributionAddress = _set; | |
} | |
/** | |
* Callable by anyone | |
* Accepts an input of the number of tokens to be burnt held by the sender. | |
*/ | |
function burnSent(uint256 _value) public { | |
require(_value > 0); | |
require(_value <= balances[msg.sender]); | |
address burner = msg.sender; | |
balances[burner] = balances[burner].sub(_value); | |
totalSupply = totalSupply.sub(_value); | |
emit Burn(burner, _value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment