Ethereum Roulette – 以太坊轮盘赌区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,Ethereum Roulette – 以太坊轮盘赌区块链毕设代写 是一篇很好的国外资料

Ethereum Roulette

A Proof of Concept casino roulette, deployed on the ropsten network.

http://ethereum-roulette.ga

Table of contents

  • Motivation
  • How to play
  • Randomness
  • Security
  • Clone repo

Motivation

I decided to learn more about developing smart contracts, and since I learn by building stuff, I decided to implement a casino roulette, with the business logic being implemented in Solidity, the language of choice to develop smart contracts in the Ethereum blockchain.

The frontend is a regular html page, with the web3 javascript library, which makes it possible to interact with the Ethereum blockchain via javascript. The web3 library is injected in the page by the Chrome extension Metamask.

How to play

You’ll have to use the Metamask Chrome extension installed, have an account on the ropsten network, have some ether (get some here or here), and visit the dapp url:

http://ethereum-roulette.ga

Every bet has a fixed amount of 0.01 ether (around €6) and you can bet by clicking on the board:

  • On a number (0 to 36), with a payout of 36;
  • On a dozen (1-12, 13-24, 25-36), with a payout of 3;
  • On a color (black or red), with a payout of 2;
  • If the number is even or odd, with a payout of 2;
  • On a column (left, middle or right), with a payout of 3.

The roulette just accepts a bet when has sufficient funds to pay for it and every other active bet.

Different people can be playing at the same time.

One of the players will click the “Spin Wheel” button, which will generate a random number and all bets will be dealt with accordingly.

When a player wins a bet, the payout is credited on his personal account. The player can, at any moment, click the “Cash out” button and receive their winnings. Be advised that, at a particular moment, the roulette could have insufficient funds to pay winnings for all players. Continue reading to understand why this could happen.

Randomness

True randomness is not possible in the Ethereum Virtual Machine (EVM), due to the way the virtual machine operates. When a smart contract is called, every node in the network will have to run the code, to validate it, and at the end the state must be the same for every node (consensus). If, hypothetically, there would be a true random function available, then, when every node call it, it would spill a different value, making it impossible to achieve consensus.

So, we have to use the current state of the blockchain to find a fair random number, and the formula I choose was to calculate the hash of several factors, and use the reminder of the division of that hash by 37. The factors used in the hash are:

  • The blockhash of the previous block
  • The current block timestamp
  • The current block difficulty
  • The last accepted bet

The problem with this approach is that everyone who can see the state of the blockchain, can calculate (“guess”) the future random number, and bet on that number.

Security

So, the first security measure implemented was to make the random number dependable on the last bet. So, if for example, an attacker calculates that the random number will be13, by betting on 13 he will change the outcome of the random number, making this type of attack ineffective.

But an attacker could make an inverted attack, by betting on a number and then waiting for the state of the blockchain to be one that generates that specific number. For this attack to work, the attacker must fulfill 2 conditions:

  1. be able to control when is the spin of the wheel;
  2. be able to accurately guess the next random number.

Condition one is difficult, because anyone can spin the wheel, but there will be times where the attacker will be the only one on the roulette, making it possible. With an average time per block of 14.4 seconds, and for a bet with a payout of 36, on average the attacker will have to be alone in the roulette for 37 * 14.4 / 60 ~= 9 minutes.

Condition two, is harder. Two of the factors used in calculating the “random” number refer to the current block, that will only be known with the spinning of the wheel, thus making it impossible to guess the “random” number. The problem is that, even unknown, the values of the current block timestamp and difficulty are strongly predictable, and even worse, can be manipulated by a miner.

In a nutshell, for a regular player will be very hard to guess the random number, but the system is vulnerable to attacks by miners. So additional security measures were put in place.

Balance cap

Every time the wheel is spinned, and all payouts credited in the players accounts, the system verifies if the roulette balance is higher than 2 ether. If so, it send the excess to the contract owner (me). This way, the maximum amount of ether an attacker could steal is of 3 ether (a full roulette with 2 ether, plus 100 bets of 0.01 ether).

Bear in mind that the personal accounts of players (their respective winnings) are not taking in consideration when calculating the balance. In other words, a player could have more than 2 ether in their winnings accounts, but be unable to cash out since the roulette hasn’t sufficient funds to pay.

This is intended to prevent a Denial of Service attack, where a player could have all the roulette money in his winnings account, preventing other players to play. It’s players responsability to be aware of this, and cash out frequently.

Clone repo

You can clone the repo and running it on your own private network.

What you’ll need

  • Ganache: you can download a self-contained prebuilt Ganache binary for your platform of choice using the “Download” button on the Ganache website. After, run it and keep it running, this will deploy a private Ethereum network on your machine, port 7545.
  • npm: follow this instructions to install npm
  • Metamask Chrome extension installed and running

How to lunch the ethereum roulette on your machine

Run Ganache and keep it running.

Clone the repo from github:

git clone https://github.com/bordalix/ethereum-roulette.git cd ethereum-roulette npm install 

Deploy the contract to your private blockchain (provided by Ganache):

truffle deploy --reset 

Run the webserver

npm run dev 

You now have the ethereum roulette on http://localhost:3000.

Have fun.

We use optional third-party analytics cookies to understand how you use GitHub.com so we can build better products. Learn more.


以太坊eth轮盘赌

动机

如何玩

随机性

安全性

克隆回购

基本cookies
分析cookies
  • 动机
  • 如何玩
  • 随机性
  • 安全性
  • 在一个数字(0到36)上克隆回购,
  • 支付36;
  • 在一打(1-12、13-24、25-36)上,支付3;
  • 在颜色(黑色或红色)上,支付2;
  • 如果数字是偶数或奇数,则支付2;
  • 在列(左、中或右)上,支付3。
  • 上一个区块的区块散列
  • 当前区块时间戳
  • 当前区块难度
  • 最后接受的赌注
  • 能够控制何时是转轮;
  • 能够准确猜测下一个随机数。
  • Ganache:您可以使用Ganache网站上的“download”按钮为您选择的平台下载一个独立的预构建的Ganache二进制文件。之后,运行它并保持运行,这将在您的机器上部署一个私有的以太坊eth网络,端口7545。
  • npm:按照以下说明安装并运行Metamask Chrome扩展
  • ropsten网络上部署的赌场轮盘赌概念验证。

    http://ethereum-roulette.ga

    目录

    • 动机
    • 如何玩
    • 随机性
    • 安全性
    • 在一个数字(0到36)上克隆回购,

    动机

    我决定学习更多关于开发智能合约的知识,而且由于我是通过构建东西来学习的,所以我决定实施赌场轮盘赌,业务逻辑在Solidity中实现,Solidity是以太坊eth区块链blockchain中开发智能合约的首选语言。

    前端是一个普通的html页面,带有web3 javascript库,这使得通过javascript与以太坊eth区块链blockchain交互成为可能。web3库由Chrome扩展元掩码注入到页面中。

    如何玩

    您必须使用安装的Metamask Chrome扩展,在ropsten网络上有一个帐户,有一些乙醚(在这里或这里获得一些),并访问dapp网址:

    http://ethereum-roulette.ga

    每次下注都有固定的0.01以太币(约6欧元),您可以点击棋盘下注:

    • 支付36;
    • 在一打(1-12、13-24、25-36)上,支付3;
    • 在颜色(黑色或红色)上,支付2;
    • 如果数字是偶数或奇数,则支付2;
    • 在列(左、中或右)上,支付3。

    轮盘赌只有在有足够的资金来支付它和其他所有活跃的赌注时才接受下注。

    不同的人可以同时玩。

    其中一名玩家将单击“旋转轮子”按钮,该按钮将生成一个随机数,所有赌注都将相应地进行处理。

    当一个玩家赢了一个赌注,支付的钱会记入他的个人帐户。玩家可以在任何时候,点击“提款”按钮,获得他们的奖金。请注意,在特定时刻,轮盘赌可能没有足够的资金来支付所有玩家的赢款。继续阅读,了解为什么会发生这种情况。

    随机性

    由于虚拟机的运行方式,在以太坊eth虚拟机(EVM)中不可能实现真正的随机性。当智能合约被调用时,网络中的每个节点都必须运行代码,以验证代码,最后每个节点的状态必须相同(一致)。如果假设有一个真正的随机函数可用,那么,当每个节点调用它时,它会溢出一个不同的值,从而不可能达成一致。

    因此,我们必须使用区块链blockchain的当前状态来找到一个公平的随机数,我选择的公式是计算几个因素的哈希值,并使用该哈希值除以37的提示。所有人都可以用这个方法来计算未来的随机数。

    • 上一个区块的区块散列
    • 当前区块时间戳
    • 当前区块难度
    • 最后接受的赌注

    因此,实施的第一个安全措施是使随机数在最后一次下注时可靠。因此,例如,如果攻击者计算出随机数将是13,那么他将通过下注13来改变随机数的结果,使这种类型的攻击无效。

    安全性

    但是攻击者可以进行反向攻击,方法是下注一个数字,然后等待区块链blockchain的状态成为生成该特定数字的状态。要使此攻击生效,攻击者必须满足两个条件:

    条件一很困难,因为任何人都可以旋转轮子,但有时攻击者将是轮盘赌上的唯一一个,使其成为可能。平均每格时间为14.4秒,如果下注的赔率是36,那么攻击者在轮盘赌中的平均时间是37*14.4/60~=9分钟。

    1. 能够控制何时是转轮;
    2. 能够准确猜测下一个随机数。

    条件二更难。在计算“随机”数时使用的两个因子指的是当前块,这只在车轮旋转时才知道,因此无法猜测“随机”数。问题是,即使未知,当前块时间戳和难度的值也是强可预测的,更糟糕的是,它可以被矿工操纵。简而言之,对于一个普通玩家来说,很难猜出随机数,但系统很容易受到矿工的攻击。所以采取了额外的安全措施。

    余额上限

    每当轮盘旋转,并且所有支付都记入玩家账户时,系统都会验证轮盘赌余额是否高于2以太。如果是这样的话,它会把多余的部分寄给合同所有人(我)。这样,攻击者可以盗取的最大乙醚量是3乙醚(2乙醚的全轮盘赌,加上100注0.01乙醚)。

    请记住,在计算余额时,不考虑玩家的个人账户(他们各自的赢款)。换句话说,一个玩家的赢款账户中可能有2个以上的以太币,但由于轮盘赌没有足够的资金支付,所以无法兑现。

    这是为了防止拒绝服务攻击,在这种攻击中,一个玩家可以将所有的轮盘赌钱存在他的赢款帐户中,从而阻止其他玩家玩。这是球员的责任意识到这一点,并经常兑现。

    您可以克隆repo并在您自己的专用网络上运行它。

    您需要什么

    克隆回购

    如何在您的机器上使用以太坊eth轮盘赌

    运行Ganache并保持其运行。

    • Ganache:您可以使用Ganache网站上的“download”按钮为您选择的平台下载一个独立的预构建的Ganache二进制文件。之后,运行它并保持运行,这将在您的机器上部署一个私有的以太坊eth网络,端口7545。
    • npm:按照以下说明安装并运行Metamask Chrome扩展
    • Metamask Chrome extension installed and running

    从github克隆回购:

    将合约部署到您的私有区块链blockchain(由Ganache提供):

    运行Web服务器

    git clone https://github.com/bordalix/ethereum-roulette.git cd ethereum-roulette npm install 

    现在您已经有了以太坊eth轮盘赌了http://localhost:3000。

    truffle deploy --reset 

    玩得开心。

    npm run dev 

    我们使用可选的第三方分析cookies来了解您如何使用GitHub.com网站所以我们可以制造更好的产品。了解更多。

    我们使用可选的第三方分析cookies来了解您如何使用GitHub.com网站所以我们可以制造更好的产品。
    您可以随时通过单击页面底部的Cookie首选项来更新您的选择。有关更多信息,请参阅我们的隐私声明。

    我们使用基本Cookie来执行基本的网站功能,例如,它们用于让您登录。了解更多

    部分转自网络,侵权联系删除区块链源码网

    www.interchains.cc

    https://www.interchains.cc/18561.html

    区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 !
    区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » Ethereum Roulette – 以太坊轮盘赌区块链毕设代写

    提供最优质的资源集合

    立即查看 了解详情