All Projects → axiomzen → Eth Random

axiomzen / Eth Random

Licence: mit
commit-reveal RNG method in Ethereum

Programming Languages

solidity
1140 projects

Projects that are alternatives of or similar to Eth Random

Ethlist
The Comprehensive Ethereum Reading List
Stars: ✭ 3,576 (+4426.58%)
Mutual labels:  ethereum, ethereum-contract
Augur Core
Augur back-end (Ethereum contracts)
Stars: ✭ 575 (+627.85%)
Mutual labels:  ethereum, ethereum-contract
Colonynetwork
Colony Network smart contracts
Stars: ✭ 351 (+344.3%)
Mutual labels:  ethereum, ethereum-contract
Augur
Augur - Prediction Market Protocol and Client
Stars: ✭ 294 (+272.15%)
Mutual labels:  ethereum, ethereum-contract
Smart Contracts Example
Simple example of token market. Based on blockchain technology using Ethereum platform.
Stars: ✭ 37 (-53.16%)
Mutual labels:  ethereum, ethereum-contract
Bamboo
Bamboo see https://github.com/cornellblockchain/bamboo
Stars: ✭ 300 (+279.75%)
Mutual labels:  ethereum, ethereum-contract
React Ethereum Dapp Example
A starter boilerplate for an Ethereum dapp using web3.js v1.0, truffle, react, and parity
Stars: ✭ 384 (+386.08%)
Mutual labels:  ethereum, ethereum-contract
Eth Vue
Featured in Awesome Vue [https://github.com/vuejs/awesome-vue], a curated list maintained by vuejs of awesome things related to the Vue.js framework, and Awesome List [https://awesomelists.net/150-Vue.js/3863-Open+Source/18749-DOkwufulueze-eth-vue], this Truffle Box provides everything you need to quickly build Ethereum dApps that have authentication features with vue, including configuration for easy deployment to the Ropsten Network. It's also Gravatar-enabled. Connecting to a running Ganache blockchain network from Truffle is also possible -- for fast development and testing purposes. Built on Truffle 5 and Vue 3, eth-vue uses vuex for state management, vuex-persist for local storage of app state, and vue-router for routing. Authentication functionalities are handled by Smart Contracts running on the Ethereum blockchain.
Stars: ✭ 171 (+116.46%)
Mutual labels:  ethereum, ethereum-contract
Daox Contracts
Smart contracts for creating Daox-based fundraising organization
Stars: ✭ 31 (-60.76%)
Mutual labels:  ethereum, ethereum-contract
Textmessage.eth
Send SMS Text Messages within the Ethereum Blockchain - TextMessage.ETH
Stars: ✭ 11 (-86.08%)
Mutual labels:  ethereum, ethereum-contract
Yearn Protocol
Yearn smart contracts
Stars: ✭ 277 (+250.63%)
Mutual labels:  ethereum, ethereum-contract
Ethereum Ico Contract
Tested Ethereum ICO Contract for Token Crowdsales
Stars: ✭ 59 (-25.32%)
Mutual labels:  ethereum, ethereum-contract
Ethereum Graph Debugger
Ethereum solidity graph plain debugger. To have the whole picture when debugging.
Stars: ✭ 177 (+124.05%)
Mutual labels:  ethereum, ethereum-contract
Nmr
The Numeraire Ethereum Smart Contract
Stars: ✭ 316 (+300%)
Mutual labels:  ethereum, ethereum-contract
Angular Truffle Starter Dapp
Angular CLI + Truffle Starter Dapp; write, compile & deploy smart contracts on Ethereum blockchains
Stars: ✭ 174 (+120.25%)
Mutual labels:  ethereum, ethereum-contract
Ethereum voting dapp
Simple Ethereum Voting dapp using Truffle framework
Stars: ✭ 355 (+349.37%)
Mutual labels:  ethereum, ethereum-contract
Basic Attention Token Crowdsale
Basic Attention Token
Stars: ✭ 160 (+102.53%)
Mutual labels:  ethereum, ethereum-contract
Tokenbalance
Simple Ethereum API to get your ERC20 Token Balance along with useful information
Stars: ✭ 163 (+106.33%)
Mutual labels:  ethereum, ethereum-contract
Stromdao Businessobject
Abstract BusinessObject for StromDAO Energy Blockchain. Abstraction layer between blockchain technology and business logic providing energy market related entities and use cases.
Stars: ✭ 10 (-87.34%)
Mutual labels:  ethereum, ethereum-contract
Solidity
🔐 Ethereum smart contracts developed for the Hanzo Platform.
Stars: ✭ 46 (-41.77%)
Mutual labels:  ethereum, ethereum-contract

RNG on Ethereum blockchain

Obtaining a reliable source of randomness on Ethereum is no easy task. The best pattern we chose to ultimately implement on CryptoKitties is known as commit-reveal. See original GeneScience contract here for an example

The main constraints we conformed to are:

  1. Get an arbitrary amount of random numbers per block
  2. Run cheaply
  3. Be unpredictable and not manipulable

At the time a kitty gets pregnant we know from which block it will be able to be born, let's call the block height DDB. Therefore we save DDB to the kitty struct at time of pregnancy.
Then after DDB is achieved, a birther will call the give birth function, which is roughly: R = uint256(block.blockhash(DDB-1)) [1].

For Cryptokitties purposes, other elements go into this hash as well, BUT it's important that any elements that go into that hashing are unable to be changed.

Then R can be bitsliced to make power of 2 numbers that make random slices of it [2]. If more random numbers are necessary, it's possible to continually re-hash R and obtain equaly strong random numbers.

[1] Can only get the last 256 block hashes, otherwise it will return 0, which sucks. Cryptokitties implement 2 fallbacks: first an economic measure, anyone is able to give birth to kitties and get an Ether reward for that. The second one is to check if R==0, and (loosely speaking) add 256 until we get a R != 0.

[2] May use a bit slicing function and keep an index of how many bits have been used so far as a variable that you increment.

Analysis

In addition to good quality of number generation, several concerns play when harvesting random numbers from blockchains, so let's address the main points.

Predictability

Since the block hash in the future is unknown, it's unpredictable at the time of commit.

User manipulation

No user should be able to seed or tamper with the RNG input. As we discussed in item [1] above, counter measures must be in place to prevent "re-rolls".

Miner manipulation

Miners are a powerful force in every aspect that comes into play when creating a block, because well, they create the blocks. Block hashes happen to be the hardest element to meddle with due to how PoW functions, miners are lucky to mine a block and get it's reward, by essentially finding a fitting hash, and if a miner is to keep on re-hashing the block until it's satisfied with the hashing result, it will end up failing to be the winner for that block height, as other miners will propose a block before them.

Given the current state of Ethereum, the described RNG method seems safe, as long as the possible reward from the RNG result is not big enough to have miners altering their mining behaviour. Such value is estimated at 0.25ETH.

With Casper PoS changes in 2020, RNG methods that rely on blockhash entropy might become more easily exploitable.

Low cost

This technique gas cost is pretty low. The most costly element requires the cost of 1 update in an existing storage word, and that would happen anyways as kitties get pregnant. Hashing and bit manipulation operations are not expensive.

Links of interest:

  1. Presentation at Ethdenver 2019 about random-number generation
  2. Cryptokitties blog post on GeneScience
  3. @Razor talk on the topic
  4. Consensys Smart contract recommendations
  5. A multi input based random generation

Contributing

PR > new issue. Welcome pull requests that:

  1. Improve the quality of the information
  2. Adds an example in solidity #8
  3. Adds links of interest

Acknowledgement

While the final mechanism implemented in Cryptokitties was developed and implemented by @dete and @flockonus, @Arachnid had a major contribution to the mechanism. Also thanks to constructive criticism by @MicahZoltu and @Raz0r, among others.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].