Alright so I've started a new project...
If you're like me you're thinking:
Maybe you should stop starting new projects and actually finish one!
Yeah, Trust Me...
We are on the same page.
However,
This project is more of a subset for one or more of my other projects.
The code I write on this project will certainly be used more than once.
Modular code is the best code.
So what's the project, you ask?
Well, I've already technically mentioned it.
Using the escrow smart contracts provided in hardfork 14, I intend to create the most basic peer-to-peer gambling game humanly possible.
Flipping a coin and betting on the outcome.
Here is some testing I'm doing to see how it works.
What we are seeing here are blocks being imported and the witness signatures logged in the console. Under the witness signature I've isolated the last hex digit (shill: vote @hextech witness). Under that I've created an array that adds +1 to the position that got "rolled" by the witness signature.
D16 Dice
What I've essentially done here is turned the witness block signatures into D16 dice so we can use them to determine the winner in our game. I needed to test it a few times to make sure that these "D16 dice rolls" are indeed 'random'. It looks like they are.
- 0 was rolled 50 times.
- 1 was rolled 57 times.
- 2 was rolled 54 times.
- ...
- D was rolled 56 times. (D == 14)
- F was rolled 52 times. (F == 15)
So far so good.
Seems pretty random. Under this D16 die array we can see another much smaller array of 2.
This is the consolidated coin flip.
- If the roll was 0-7 we get 'heads'
- If the roll was 8-F we get 'tails'
- We can see we flipped 415 'heads' and 419 'tails'.
Therefore, this method appears to be perfect for coin flips.
Granted, it assumes that witnesses will not manipulate their signature (by modifying block info) and cheat at the game to turn a profit. At the same time, blocks happen so quickly on Hive that creating a block and broadcasting it to the network is a race to make sure your node doesn't miss one. There isn't a ton of time to mess around with blocks, although the time a server would need to modify the outcome is probably trivial and near instant for this kind of coin flip.
There are also several other issues at play here as well. If you're playing against users that you trust (or simply aren't colluding with witnesses) there is no reason why a witness would risk their reputation to mess around with block creation. Also, if we are talking $1 bets per flip, is that really worth the risk of a witness endangering their position in the top 20 to cheat? Probably not. All the more reason to vote @hextech witness so we can guarantee the blocks that we create will have random signatures.
Shilling it up
If certain witnesses started not including transactions in their blocks for some reason and this caused certain accounts to win more coin flips than they should have, this would be evidence of corruption and reason to smear campaign the perpetrating witness.
There's also the issue of some witnesses not really having the technical knowledge or even the ability to modify blocks in this way. @hextech witness is currently an out-of-the-box Privex node, so this would be an example of a situation where we don't even really have the power to do such a thing.
Is the entire witness signature random?
Definitively, no. It appears that all signatures begin with either '20' or '1F'. I'll have to look more into it. However, the witness signature is 130 hex variables long, so it would make sense if the first two numbers were static, because that would leave 128 random hash variables left, and 128 is a classic power-of-two number seen time and time again in computing (2^7).
That's 128 D16 dice rolls every 3 seconds!
Imagine what we could be doing with these random numbers, but just aren't!
I don't trust the witnesses, are there other options?
Indeed!
All POW coins are pumping out random numbers just like this that we could be using for D16 RNG dice rolls. The most secure one is obviously Bitcoin, but other coins like Litecoin are also very secure and produce blocks much faster than Bitcoin (x4). There are also other POW coins I'm looking at like Dogecoin and DigiByte that crank out blocks much faster than even Litecoin. However, the faster a POW coin creates blocks, the less expensive it is to hack the RNG.
Hacking the RNG of a POW coin.
This is honestly something that I never expect to happen, but it is possible. Imagine setting up mining equipment (or renting hash power as that is much more likely) and then throwing away good blocks just to hack the RNG of a side project. Doesn't seem very likely, does it?
Mining a Bitcoin block is currently worth $120k. Can you imagine throwing away $120k in the hope that you find a better block that has better RNG for the game you are playing? It's just not going to happen!
Difficulty + HashPower = Security
It's also important to note that the value of a coin also comes into play in addition to the difficulty level (average time it takes to generate a block). A long time is more secure, but a higher coin value is also more secure. A higher coin value gives more incentive to mine, which in turn increases the hash power of the network, which in turn makes the difficulty greater. This loop increases the security of the network and the price one would have to pay to attack it.
The drawback of using POW coins for RNG on Hive.
We would be forced to use centralized arbiters to tell us what the block information was of other chains. This is why I've suggested that our witnesses should not only be providing price feeds for the network, but also block hash fees from popular POW networks like Bitcoin and Litecoin.
Why not other Bitcoin forks like BCH or BSV?
These forks of Bitcoin use the same hashing algorithm as Bitcoin. This makes them less secure because a big Bitcoin miner could turn their hashpower against these networks for very little cost. They would not be able to do the same against Litecoin because Litecoin uses the Scrypt algorithm and not SHA-256.
This is one of the reasons I'm interested in DigiByte, because they are the one POW coin I know of that uses 5 different hashing algorithms. Plus, if there are any others, Digibyte has the highest market cap of them all making it more secure by difficulty level alone.
Escrow Law.
https://www.stimmel-law.com/en/articles/basics-law-and-practice-escrow
Conclusion:
The underlying purpose of an escrow is to establish a repository for monies or assets that will hold them in safe keeping until events occur as agreed upon by the parties contracting for the escrow. It often involves real estate but is not restricted to that type of transaction nor is it restricted to licensed escrow holders minus state or federal law being involved. Indeed, the simplest escrow is simply asking a friend to hold the stake when two people are betting on the outcome of an event.
I'm still not certain how escrow law applies to this "simplest version" where a friend holds the money while two others bet on the outcome. However, as a poker player, I do know that home-games are legal if the "house" doesn't take a rake. This means that poker is 100% legal if there is no centralized entity turning a profit. I assume the same may be true for an escrow service like the one I'm looking to provide, but I'll need to look into it further.
Conclusion
Trusted Hive witnesses are generating 128 random D16 dice rolls every 3 seconds and no one is using that functionality to create frictionless gambling services, or any other type of gaming RNG. I plan to change that.
Not only will this be good for Hive, but it will be devastating to the Tron Foundation and perhaps even EOS as well. All these developers are running around wondering how they can scrape money off the top; asking themselves: "What's in it for me?"
I plan to show the cryptosphere how this emergent open-source economy actually works: acquire stake in the network and then create value for everyone, instead of just yourself. Reputation is the new hard currency.
Return from New dapp in the works & more on escrow to edicted's Web3 Blog