LogoLogo
WebsiteDiscordTelegramTwitter
  • ๐Ÿ Witnet Oracle Docs
  • Introduction
    • โ“What is Witnet?
      • โš™๏ธOracle Architecture
      • ๐Ÿช™The Witnet Coin (Wit)
      • ๐Ÿ‘›Wallets
      • ๐Ÿค”Frequently Asked Questions
      • ๐Ÿ˜ŽAwesome Witnet
    • ๐Ÿš€Quick Tutorials
      • ๐Ÿ“ˆPrice Feeds
      • ๐ŸŽฒRandomness
      • ๐ŸŒAPIs and HTTP GET/POST
      • โ›๏ธMining Wit
  • Smart contracts developers
    • โ›“๏ธSupported chains
    • ๐Ÿ”ฎWit/Oracle
      • HTTP GET Requests in Solidity
      • HTTP POST Requests in Solidity
      • Query GraphQL APIs in Solidity
      • Dynamic Requests in Solidity
      • UsingWitnet Inheritance
      • API Reference
        • Solidity API
          • Solidity Contracts
            • WitnetRequestBoard
        • Javascript API
        • RADON API
          • RADON Type System
          • RADON Errors
      • Multi-chain Addresses
    • ๐Ÿ’นWit/Price Feeds
      • How To Use Witnet Price Feeds
      • Update Conditions
      • Code Examples
      • API Reference
      • Multi-chain Addresses
        • Arbitrum Price Feeds
        • Avalanche Price Feeds
        • Base Price Feeds
        • Boba Price Feeds
        • Celo Price Feeds
        • Conflux Price Feeds
        • Cronos Price Feeds
        • Dogechain Price Feeds
        • Elastos Price Feeds
        • Ethereum Price Feeds
        • Gnosis Chain Price Feeds
        • Kaia Price Feeds
        • Kava Price Feeds
        • KCC Price Feeds
        • Mantle Price Feeds
        • Meter Price Feeds
        • Metis Price Feeds
        • Moonbeam Price Feeds
        • OKX Price Feeds
        • Optimism Price Feeds
        • Polygon Price Feeds
        • Reef Price Feeds
        • Scroll Price Feeds
        • Syscoin Price Feeds
        • Ultron Price Feeds
        • Request new price feed or chain support
    • ๐ŸŽฒWit/Randomness
      • Generating Randomness
      • WitnetRandomness Contract
      • Low-level Requests
      • Code Examples
      • API Reference
      • Multi-chain Addresses
    • ๐Ÿ—๏ธGuides
      • ๐Ÿ“–Solidity Contracts
        • Appliances
          • ๐Ÿ“ƒWitnetPriceFeeds
          • ๐Ÿ“ƒWitnetRandomness
        • Core
          • ๐Ÿ“ƒWitnetOracle
          • ๐Ÿ“ƒWitnetRadonRegistry
          • ๐Ÿ“ƒWitnetRequest
          • ๐Ÿ“ƒWitnetRequestFactory
          • ๐Ÿ“ƒWitnetRequestTemplate
        • Mockups
          • ๐Ÿ“ƒUsingWitnet
          • ๐Ÿ“ƒUsingWitnetRandomness
          • ๐Ÿ“ƒUsingWitnetRequest
          • ๐Ÿ“ƒUsingWitnetRequestTemplate
          • ๐Ÿ“ƒWitnetRandomnessRequestConsumer
          • ๐Ÿ“ƒWitnetRequestConsumer
          • ๐Ÿ“ƒWitnetRequestTemplateConsumer
      • ๐Ÿง™Solidity Wizard
    • ๐ŸŽ“Tutorials
      • Building a Satoshi/Wei custom price feed
  • Witnet Node Operators
    • ๐Ÿ–ฅ๏ธRequirements
    • ๐Ÿš€Witnet Node Quick Start Guide (Docker)
    • ๐Ÿ”ŽNext steps
    • ๐Ÿ“„CLI Reference
    • ๐Ÿค“Advanced Setups
      • Run Witnet as a systemd service
      • Run Witnet as a docker compose service
      • Paranoid mode (Witnet over proxies and Tor)
      • Configuration file
  • Witnet Node Developers
    • ๐Ÿ—๏ธIntegration Guide
      • Node API Reference
      • Wallet API Reference
    • ๐Ÿ—œ๏ธCompile witnet-rust from Source Code
Powered by GitBook
On this page
  • Best practices
  • Security concerns

Was this helpful?

Edit on GitHub
  1. Smart contracts developers
  2. Wit/Randomness

WitnetRandomness Contract

PreviousGenerating RandomnessNextLow-level Requests

Last updated 1 year ago

Was this helpful?

The , also known as the ยซWitnet Randomness Oracleยป, is the easiest and most convenient way to generate EVM-agnostic and realiable randomness for your smart contracts.

The Witnet Foundation sponsors a pre-deployed instance of WitnetRandomness in practically all the .

While the WitnetRandomness contract internally uses an instance of the low-level WitnetRequestRandomness , this contract implements also the whole request/resolution asynchronous flow involved in the resolution of a data request in the context of the Witnet side-chain.

Moreover, the same instance can be safely and concurrently used by any number of indepent applications running within the same EVM-chain.

Because of this, you may even have the chance to reuse randomness previously requested by others, at no cost (๐ŸŽ‰), while having the certainty that the acquired randmoness was independently generated by the Witnet side-chain strictly after any given block number.

And therefore, depending on the time-response constraints of your own app, the Witnet Randomness Oracle may become the cheapest EVM-agnostic mechanism to generate reliable randomness in the whole crypto arena (๐Ÿ’ฃ).

In a nutshell, by using a WitnetRandomness you just need to:

  1. Eventually, care for requesting and paying for new randomness at any given time: see randomize() payable.

  2. Eventually, fetching a randomness value generated by Witnet after any given block number: see isRandomized(uint256) and getRandomnessAfter(uint256).

As simple as that ;-)

Best practices

  • The WitnetRandomness contract is not owned, so anyone is actually allowed to either request new randomness (i.e. randomize()), or get previously solved randomness from storage (i.e. isRandomized(uint _blockNumber), getRandomnessAfter(uint _blockNumber)).

  • Besides, you or your contract will be able to request for new randomness (i.e. randomize() payable), even if other previous randomness requests (either coming from you, or other apps) were still pending to be solved.

  • The WitnetRandomnesscontract is Clonable, which means that you, or your contract, may cheaply create your own cloned copy as a means to gain ownership of the self-contained WitnetRequestRandomness contract. Only the owner of a cloned copy will be allowed to change the witnessing parameters of the low-level Randomness Request.

  • The WitnetRandomnesscontract provides the random(uint32 _range, uint256 _nonce, uint256 _block) and random(uint32 _range, uint256 _nonce, bytes32 _seed) helper functions.

These random(..) functions guarantee that different contracts/apps reading from same randomness request will actually get completely different random sequences of uniformly distributed numbers, within a given range, and doing so while keeping complexity under O(1) (๐ŸŽ‰).

  • Most of all, the WitnetRandomness contract guarantees that the received randomness is the one requested for a given block number, or the subsequent randomness request posted after the given block if there was none posted back then, or if the ones posted after that got reverted for whatever reason at the Witnet side-chain level.

This logic alone protects the Witnet Randomness Oracle against front-running attacks from mallicious miners at the EVM-chain level (๐Ÿ’ฃ).

Security concerns

Once you call on randomize() payable, you should not allow any change in your smart contract state that alters the outcome of whatever the requested randomness is planned to be used for.

Just call on the isRandomized(uint256) method, passing the block number at which the randomize() payable call got mined, as to check for readiness of the requested randomness.

The witnessing parameters part of the self-containedWitnetRequestRandomness instance may eventually turn immutable at the time the WitnetRandomness operator decides to renounce its ownership.

This back door of letting the WitnetRandomness operator modify the underlying witnessing parameters of the randomness request, is left open as to provide a means for adapting to eventual high-load situations within the Witnet oracle's side-chain.

While the WitnetRandomness contract is not owned, the self-contained WitnetRequestRandomness instance it is (i.e. ). This enables the operator of aWitnetRandomness instance to eventually update the witnessing parameters of the underlying low-level Randomenss Request that gets posted to the Witnet side-chain.

The RAD bytecode of the self-contained WitnetRequestRandomness instance (accesible via the ), will foerever remain immutable, though.

๐ŸŽฒ
EVM-compatible chains supported by the Witnet oracle
formarly explained
API Reference
WitnetRandomness contract
witnetRandomnessRequest()
template() method