最新活动: 2018年10月4日,纽约游戏大会见

How the WAX RNG smart contract solves common problems for dApp developers

5月 24, 2019

When the WAX Blockchain launches on June 30, 2019, dApp developers will have access to a variety of new features. Today we would like to share details about one of our forthcoming WAX Blockchain features, the WAX RNG (random number generator) smart contract.

What is an RNG?

A random number generator is an algorithm that generates values in an unpredictable manner. Developers use RNGs when they need to introduce random outcomes in their dApps, such as the generation of a digital collectible or non-fungible token (NFT). Yet the current method for integrating random values into smart contracts has numerous process flaws. These flaws create potential vectors for unfair, or non-random results, and undermine customer’s confidence in dApps.

Problems with RNGs today:

There are three main problems that developers experience when trying to generate and ingest random values into their dApp smart contracts:

  1. There are no blockchain-native RNG smart contracts. Developers must build their own, replicating work that would be better directed towards other areas of their dApp, like designs and features that improve the customer experience.
  2. Because most dApp developers are not RNG process experts, most dApp-specific RNG smart contracts have design weaknesses.
  3. dApp customers have difficulty determining whether a dApp smart contract is actually generating a random result. This diminishes customer confidence.

How the WAX RNG smart contract solves these problems:

The WAX RNG smart contract:

  1. is open source and is a blockchain-native smart contract that developers can easily integrate into their dApps.
  2. is based on the Signidice algorithm and RSA verification. Signidice was chosen for its excellent randomization and non-gameablity characteristics, in addition to yielding a cleaner workflow for dApp developers and being provably fair. RSA verification ensures uniqueness of the signature and removes the ability for the results to be manipulated (if any other type of signing algorithm were used, it would allow many valid signatures for the same signing_value which could result in manipulation).
  3. can easily be established as provably fair. The self-verifying WAX RNG smart contract confirms that the RSA signature that comes back from the WAX RNG oracle is valid and authentic before being utilized by the dApp. When dApp customers can easily establish fairness, they have a higher degree of confidence in using the dApp.

How easy it is to use? See the simple smart contract API below.

How the WAX RNG smart contract works:

In this scenario, when a customer decides to play a video game dApp on the WAX Blockchain that incorporates a random outcome, the video game dApp smart contract prompts the customer to submit a seed value. The customer’s seed value will be used to generate a random value that will be utilized in the customer’s game as follows:

Click to enlarge

Note: The WAX RNG smart contract is provably fair, so customers can verify the random value generated (see “WAX RNG smart contract simplified developer flow” below for details).


Below is a sequence diagram of the scenario described above. It shows the interactions between the customer, the dApp, the WAX RNG smart contract and the WAX RNG oracle:

Sample implementation of a smart contract calling the WAX RNG:

 
#include <eosio eosio.hpp="">
 
#include <string>
#include <tuple>
 
using namespace eosio;
 
CONTRACT sample: public contract {
public:
 WAX_CONTRACT_NAME(name receiver, name code, datastream<const char*=""> ds)
 : contract(receiver, code, ds) {
 }
 
 ACTION printrand(uint64_t assoc_id, uint64_t signing_value) {
 action(
 { get_self(), "active"_n },
 "orng.wax"_n,
 "requestrand"_n,
 std::tuple{ assoc_id, signing_value, get_self() })
 .send();
 }
 
 /// Called automatically by 'orng.wax' smart contract when the RNG Oracle
 /// has generated the random value. wax.orng, before calling this action,
 /// verifies that the generated random value was signed with the
 /// provided "signing_value"
 ACTION receiverand(uint64_t assoc_id, const std::string& random_value) {
 print_f("Assoc ID = %, Random value = %\n", assoc_id, random_value);
 }
 
}; // CONTRACT sample
 
EOSIO_DISPATCH(WAX_CONTRACT_NAME, (printrand)(receiverand))
</const></tuple></string></eosio>

WAX RNG smart contract simplified developer flow:

The diagram below shows the difference in the number of actions required when using a dApp-specific RNG smart contract (left) versus the WAX RNG smart contract (right). The WAX RNG smart contract simplifies developer flow by reducing the number of transactions and eliminates the need for seed values to be hashed. The result is a transaction time of just 1-2 seconds.

Click to enlarge

As shown in the diagram above, a dApp customer can verify that his seed value - sent to the WAX RNG smart contract - is the same seed value used by the WAX RNG oracle to generate a random value. This is because every value the WAX RNG smart contract receives and every value the WAX RNG oracle generates is recorded on the WAX Blockchain, making it fully transparent for dApp customers and developers. The WAX Blockchain permanently stores an auditable multi-index table containing:

  • Every WAX RNG signing value
  • Every WAX RNG oracle signing result

As stated previously, you can verify that these results are correct by performing an RSA signature verification against the signing values and signing results.

Two high volume dApps are already using the WAX RNG smart contract:

Two high volume dApps, VGO and vIRL, have been using the WAX RNG smart contract for many months on the beta WAX Blockchain. Both of these dApps are using the WAX RNG smart contract to create thousands of randomly generated NFTs every day. You can learn more about VGO and vIRL here:

Conclusion:

The open source WAX RNG smart contract provides a simple way for WAX Blockchain-based dApps to acquire random values. Given the number of smart contracts incorporating RNGs, the WAX RNG smart contract is a huge time saver for developers and simultaneously gives WAX Blockchain dApp customers more confidence in the results of random outcomes. We invite dApp developers to begin experimenting with our easy to integrate and provably fair WAX RNG smart contract when it is open sourced at mainnet launch June 30, 2019. Sign up for our newsletter at wax.io to get notified of future updates and releases.

---

Let us know what you think by joining the WAX community:

Twitter

Telegram

Reddit

Disclaimer: WAX reserves the right, at its sole discretion, to modify, change, edit, alter, delete and/or replace the terms of the launch of, and other information concerning, the WAX Mainnet found in this post at any time and without notice. You are encouraged to check the latest information on the launch of the WAX Mainnet on the WAX website at https://wax.io/.

Facebook Twitter Email Linked In

相关文章

Blog Image

The WAX Blockchain mainnet is live! Here are the 7 things you need to know.

The WAX Blockchain mainnet and WAX Protocol Tokens are now live! Here are the 7 things you need to know about what comes next

展开阅读
Blog Image

How to launch an EOS dApp on WAX in just six easy steps

EOS dApp developers easily duplicate their dApp onto WAX with just a few clicks, and immediately gain access to WAX Token holders and millions of OPSkins customers.

展开阅读

注册获取WAX团队最新动态