@@ -60,14 +60,35 @@ Feel free to discover other convenient libraries for Solidity inside the
60
60
* Gas cost: 10,000 minimum plus 240 per output word plus 60 per word of
61
61
the personalization string.
62
62
63
- Generate ` num_bytes ` pseudo-random bytes, with an optional
64
- personalization string added into the hashing algorithm to increase
65
- domain separation when needed.
63
+ Generate ` num_bytes ` pseudo-random bytes, with an optional personalization
64
+ string ( ` pers ` ) added into the hashing algorithm to increase domain separation
65
+ when needed.
66
66
67
67
``` solidity
68
68
bytes memory randomPad = Sapphire.randomBytes(64, "");
69
69
```
70
70
71
+ ### Implementation Details
72
+
73
+ :::danger Prior to 0.6.0
74
+ All view queries and simulated transactions (via ` eth_call ` ) would receive the
75
+ same entropy in-between blocks if they use the same ` num_bytes ` and ` pers ` parameters.
76
+ If your contract requires confidentiality you should generate a secret in the constructor
77
+ to be used with view calls:
78
+
79
+ ``` solidity
80
+ Sapphire.randomBytes(64, abi.encodePacked(msg.sender, this.perContactSecret));
81
+ ```
82
+ :::
83
+
84
+ The mode (e.g. simulation or 'view call' vs transaction execution) is fed to TupleHash (among other
85
+ block-dependent components) to derive the "key id", which is then used to derive a per-block VRF key
86
+ from epoch-ephemeral entropy (using KMAC256 and cSHAKE) so a different "key id" will result in a
87
+ unique per-block VRF key. This per-block VRF key is then used to create the per-block root RNG which
88
+ is then used to derive domain-separated (using Merlin transcripts) per-transaction random RNGs which
89
+ are then exposed via this precompile. The KMAC, cSHAKE and TupleHash algorithms are SHA-3 derived functions
90
+ defined in [ NIST Special Publication 800-185] ( https://nvlpubs.nist.gov/nistpubs/specialpublications/nist.sp.800-185.pdf ) .
91
+
71
92
## X25519 Key Derivation
72
93
73
94
### Overview
0 commit comments