Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

README.md

Random number generation using system contract

Pre-compiled functions are executed by the Hedera nodes, and are typically lower-level constituent parts of the wider Hedera services.

In the context of smart contracts, access to these pre-compiled functions comes in the form of system contracts. These are assigned an address, and have an exposed interface (ABI or Solidity interface), however they are not actual smart contracts that have been deployed. Rather they can be thought of as aliases for those pre-compield functions.

PrngSystemContract is one of these system contracts, and is used to generate pseudo random numbers. However this is not considered to be cryptographically secure.

Code

In the prng.sol file in this directory, there is an interface for the system contract IPrngSystemContract, and the pre-compiled functions for this are assigned the address 0x169.

The smart contract Prng invokes getPseudorandomSeed and gets a bytes32 result back from it. It then uses this random value to do whatever it wants to do with it.

In this case, the getPseudorandomNumber makes use of the generated bytes to convert it to a uint256 number, and then finds a number between am input range using modulo arithmetic.

References