
{"id":98913,"date":"2025-09-23T08:40:51","date_gmt":"2025-09-23T08:40:51","guid":{"rendered":"https:\/\/mycryptomania.com\/?p=98913"},"modified":"2025-09-23T08:40:51","modified_gmt":"2025-09-23T08:40:51","slug":"secure-on-chain-randomness-by-oasis-is-a-great-way-to-answer-the-blockchain-need-for-rng","status":"publish","type":"post","link":"https:\/\/mycryptomania.com\/?p=98913","title":{"rendered":"Secure On-chain Randomness By Oasis Is A Great Way To Answer The Blockchain Need For RNG"},"content":{"rendered":"<p>There is a lot of advantages of blockchain technology but its transparency, combined with the deterministic nature of computers is a stumbling block in creating true on-chain randomness. Yet, random number generators (RNGs) are essential tools for solving various algorithmic problems. Here we will discuss the approach Oasis has adopted to ensure smart contract developers can integrate randomness into their applications in a hassle-free manner.<\/p>\n<h3>What is\u00a0RNG<\/h3>\n<p>As deterministic machines, computers function by following predictable instructions. So, randomness is never truly possible. However, almost random numbers can be generated with external inputs or complex algorithms. But how feasible is\u00a0this?<\/p>\n<p>Not very. For example, a <strong>deterministic RNG<\/strong> can only mimic randomness and produce pseudo-random outputs using algorithms transforming a starting \u201cseed\u201d value into sequences. If the \u201cseed\u201d is known, it all becomes predictable.<\/p>\n<p>On the other hand, <strong>non-deterministic RNG<\/strong> can generate completely random numbers by using erratic physical phenomena, like dice rolls or photon scattering, as a workaround for the computer reading predictable patterns.<\/p>\n<h3>Why blockchains need\u00a0RNG?<\/h3>\n<p>When you try to replicate RNG in the smart contract framework, it gets interesting. Whether you are developing dApps for the web3 at large or the cryptoAI space, you will need provable fairness or unbiased and tamperproof outcomes based on unpredictable inputs.<\/p>\n<p>Even from a core blockchain point of view, RNG plays a crucial role in cryptographic operations. It produces the unique keys or values needed for securing transactions, encrypting data, or authenticating users, ensuring that outputs cannot be guessed or replicated. Without secure on-chain RNG, reverse engineering of keys, outcome manipulation and all kinds of exploits become possible.<\/p>\n<p>Now, blockchain technology also use deterministic rules, and all nodes reaching a consensus is a non-negotiable criteria. This makes on-chain randomness tricky but it is still doable. For example, verifiable random functions, commit-reveal schemes, or the method Oasis has adopted\u200a\u2014\u200ausing Verifiable Random Function (VRF) and some other cryptographic primitives. Let\u2019s now take a closer look into\u00a0Oasis.<\/p>\n<h3>How Oasis RNG\u00a0works?<\/h3>\n<p>With its default focus on smart privacy and scalability, Oasis uses its confidential EVM runtime, <strong>Sapphire<\/strong> to streamline RNG through its <strong>randomBytes<\/strong> precompile. By abstracting a simple Solidity function, any smart contract developer can integrate randomness into their applications without dealing with the complexities of blockchain RNG.<\/p>\n<p>It basically works like\u00a0this.<\/p>\n<p><strong>Generating the Per-Block Root\u00a0RNG<\/strong><\/p>\n<p>Sapphire communicates with a key manager runtime to generate secret keys. The key manager supports multiple kinds of keys, some of which are long-term and some of which are ephemeral.The ephemeral keys are used for encrypting transactions and also the RNG. To improve security, these keys are never persisted anywhere and are rotated each epoch. This means fresh keys are generated, and after a while, old keys get securely erased and cannot be recovered even if any component is later compromised.The RNG exposed to Sapphire contracts is initialized on every block. Each block uses private ephemeral entropy obtained from the key manager runtime. Only remotely attested Sapphire instances can obtain this private entropy inside the TEE, which ensures that no external observers can learn anything about the RNG\u00a0state.Next, this entropy is processed and used as a root VRF key. To turn this entropy into a usable key, Sapphire employs SHA-3-derived algorithms like TupleHash, KMAC256, and cSHAKE. These functions process the epoch-specific entropy from the key manager runtime, producing a unique per-block root RNG that anchors all subsequent randomness in the block with consistency and security.<\/p>\n<p><strong>Domain Separation for Per-Transaction RNGs<\/strong><\/p>\n<p>The per-block root RNG alone isn\u2019t enough. Each transaction needs its own private RNG, which is where domain separation comes in. Sapphire builds on the key manager\u2019s output by using Merlin transcripts to initialize per-transaction RNGs from the root RNG, customizing randomness for individual interactions using transaction-specific data.This customization is implemented in the Rust Runtime SDK used to build Sapphire, which handles the VRF and domain separation schemes. Together with the key manager\u2019s private entropy, it ensures private, unbiased, and unpredictable outputs are exposed to developers via the randomBytes precompile.<\/p>\n<h3>Code examples<\/h3>\n<p><strong>Basic Random Number Generation<\/strong><br \/>This snippet shows how to generate a 32-byte random value, ideal for straightforward RNG needs in a dApp like a poker\u00a0game.<\/p>\n<p>bytes memory randomPad = Sapphire.randomBytes(32, &#8220;&#8221;);<\/p>\n<p><strong>Random Number for Signing Key Pair<\/strong><br \/>This snippet uses randomBytes to seed a signing key pair generation, which you can use as a part of a more complex RNG-driven mechanism while ensuring cryptographic security.<\/p>\n<p>Sapphire.SigningAlg alg = Sapphire.SigningAlg.Ed25519Pure;<br \/>bytes memory pk;<br \/>bytes memory sk;<br \/>(pk, sk) = Sapphire.generateSigningKeyPair(alg, Sapphire.randomBytes(32, &#8220;&#8221;));<\/p>\n<h3><strong>Key Resources:<\/strong><\/h3>\n<p><a href=\"https:\/\/docs.oasis.io\/dapp\/sapphire\/\"><strong>Sapphire docs<\/strong><\/a><br \/><a href=\"https:\/\/github.com\/oasisprotocol\/sapphire-paratime\"><strong>Sapphire repository<\/strong><\/a><br \/><a href=\"https:\/\/api.docs.oasis.io\/sol\/sapphire-contracts\/contracts\/Sapphire.sol\/library.Sapphire.html#randombytes\"><strong>randomBytes<\/strong><\/a><br \/><a href=\"https:\/\/docs.oasis.io\/build\/rofl\/\"><strong>Oasis ROFL<\/strong><\/a><br \/><a href=\"https:\/\/playground.oasis.io\/\"><strong>Oasis playground for demo\u00a0dApps<\/strong><\/a><\/p>\n<p>Have a question or need help? Join our <a href=\"https:\/\/oasis.io\/discord\">Discord<\/a> and head over to the <strong>#dev-central<\/strong> channel.<\/p>\n<p><em>Originally published at <\/em><a href=\"https:\/\/dev.to\/dc600\/secure-on-chain-randomness-by-oasis-is-a-great-way-to-answer-the-blockchain-need-for-rng-10j8\"><em>https:\/\/dev.to<\/em><\/a><em> on September 22,\u00a02025.<\/em><\/p>\n<p><a href=\"https:\/\/medium.com\/coinmonks\/secure-on-chain-randomness-by-oasis-is-a-great-way-to-answer-the-blockchain-need-for-rng-6b3d51287c4b\">Secure On-chain Randomness By Oasis Is A Great Way To Answer The Blockchain Need For RNG<\/a> was originally published in <a href=\"https:\/\/medium.com\/coinmonks\">Coinmonks<\/a> on Medium, where people are continuing the conversation by highlighting and responding to this story.<\/p>","protected":false},"excerpt":{"rendered":"<p>There is a lot of advantages of blockchain technology but its transparency, combined with the deterministic nature of computers is a stumbling block in creating true on-chain randomness. Yet, random number generators (RNGs) are essential tools for solving various algorithmic problems. Here we will discuss the approach Oasis has adopted to ensure smart contract developers [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-98913","post","type-post","status-publish","format-standard","hentry","category-interesting"],"_links":{"self":[{"href":"https:\/\/mycryptomania.com\/index.php?rest_route=\/wp\/v2\/posts\/98913"}],"collection":[{"href":"https:\/\/mycryptomania.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mycryptomania.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/mycryptomania.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=98913"}],"version-history":[{"count":0,"href":"https:\/\/mycryptomania.com\/index.php?rest_route=\/wp\/v2\/posts\/98913\/revisions"}],"wp:attachment":[{"href":"https:\/\/mycryptomania.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=98913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mycryptomania.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=98913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mycryptomania.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=98913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}