You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ftso/guides/build-first-app.mdx
+28-20Lines changed: 28 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -224,27 +224,27 @@ This guide is for developers who want to build an FTSOv2 application using eithe
224
224
forge test
225
225
```
226
226
227
-
You should see a successful test result like this:
227
+
You should see a successful test result:
228
228
229
-
```plaintext
230
-
[⠊] Compiling...
231
-
[⠘] Compiling 27 files with Solc 0.8.27
232
-
[⠃] Solc 0.8.27 finished in 797.51ms
233
-
Compiler run successful!
229
+
```plaintext
230
+
[⠊] Compiling...
231
+
[⠘] Compiling 27 files with Solc 0.8.27
232
+
[⠃] Solc 0.8.27 finished in 797.51ms
233
+
Compiler run successful!
234
234
235
-
Ran 2 tests for test/FtsoV2FeedConsumer_foundry.t.sol:FtsoV2FeedConsumerTestFoundry
236
-
[PASS] testCheckFees() (gas: 21085)
237
-
[PASS] testGetFlrUsdPrice() (gas: 25610)
238
-
Logs:
239
-
msg.value matches fee
240
-
feedValue 150000
241
-
decimals 7
242
-
timestamp 1
235
+
Ran 2 tests for test/FtsoV2FeedConsumer_foundry.t.sol:FtsoV2FeedConsumerTestFoundry
236
+
[PASS] testCheckFees() (gas: 21085)
237
+
[PASS] testGetFlrUsdPrice() (gas: 25610)
238
+
Logs:
239
+
msg.value matches fee
240
+
feedValue 150000
241
+
decimals 7
242
+
timestamp 1
243
243
244
-
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 7.72ms (2.91ms CPU time)
244
+
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 7.72ms (2.91ms CPU time)
245
245
246
-
Ran 1 test suite in 122.65ms (7.72ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)
247
-
```
246
+
Ran 1 test suite in 122.65ms (7.72ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)
247
+
```
248
248
249
249
</TabItem>
250
250
<TabItemvalue="hardhat"label="Hardhat">
@@ -308,15 +308,20 @@ This guide is for developers who want to build an FTSOv2 application using eithe
308
308
4. The final step before deploying is to set the constructor arguments with the address of [`FtsoV2`](/ftso/solidity-reference) and [`FeeCalculator`](/ftso/solidity-reference) on Flare Testnet Coston2 and the [feed ID](/ftso/feeds) of FLR/USD:
309
309
310
310
```bash
311
+
# see https://dev.flare.network/ftso/solidity-reference
@@ -479,7 +487,7 @@ This guide is for developers who want to build an FTSOv2 application using eithe
479
487
480
488
3. Interact with the contract:
481
489
482
-
Copy and paste the deployed contract address into the [Coston2 explorer](https://coston2-explorer.flare.network/) to view and interact with the contract.
490
+
Copy and paste the deployed contract address into the [Coston2 explorer](https://coston2.testnet.flarescan.com) to view and interact with the contract.
483
491
484
492
Congratulations! You've built your first FTSOv2 app using Hardhat.
This guide explains how to obtain secure random numbers on Flare. Secure randomness is generated by the [Scaling](/ftso/scaling/overview) protocol, which leverages a decentralized network of approximately 100 data providers who generate random numbers every 90 seconds.
35
+
This guide shows how to obtain secure, uniform random numbers on Flare.
36
+
Secure randomness is generated by the [Scaling](/ftso/scaling/overview) protocol, where approximately 100 independent data providers generate local randomness every 90 seconds (a voting round), commit onchain, then reveal.
37
+
The protocol aggregates these values into a final, uniformly distributed random number.
37
38
38
-
The protocol aggregates these individual random numbers to produce a final random number that is both uniform and resistant to manipulation. The uniformity of this random number is ensured as long as at least one of the data providers remains honest, i.e. 1-of-N.
39
-
The protocol has an in-built security mechanism to detect manipulation attempts, and will warn the end user if such an attempt is detected.
39
+
As long as **any one provider** generates an honest, hidden $n$-bit random value, the sum modulo $2^n$ remains uniform.
40
+
If manipulation is detected (e.g., a reveal omission), the round's `isSecure` flag is set to false, offenders are penalized, and their values are excluded for subsequent rounds.
40
41
41
42
<details>
42
-
<summary>**Understand the mechanism behind secure random numbers on Flare.**</summary>
43
+
<summary>Understand the secure random mechanism.</summary>
43
44
44
45
As described in the [FTSOv2 whitepaper](/pdf/whitepapers/20240223-FlareTimeSeriesOracleV2.pdf), the Scaling protocol consists of the following phases:
45
46
46
47
1.**Commit:** During the Commit phase, data providers prepare their submissions for each of the data feeds and encode them into a 4-byte vector. Then, each data provider publishes on chain a hash commitment obtained as:
-**Random Number**: This commit includes a locally generated random number.
50
-
-**Purpose**: The random number blinds the commit hash of the user from a search attack and is used later (once revealed) to contribute to onchain randomness.
50
+
-**Random Number**: This Commit includes a locally generated random number.
51
+
-**Purpose**: The random number blinds the Commit hash of the user from a search attack and is used later (once revealed) to contribute to onchain randomness.
51
52
52
53
2.**Reveal:** During the Reveal phase, each data provider reveals all inputs to their hash commitment. As such, all locally produced random numbers become available onchain.
53
54
@@ -61,33 +62,21 @@ As described in the [FTSOv2 whitepaper](/pdf/whitepapers/20240223-FlareTimeSerie
61
62
62
63
**Secure Random Numbers**
63
64
64
-
For each voting epoch (90 seconds), an overall random number is generated from the local random numbers:
65
+
For each voting round (90 seconds), let each provider's random value be $r_i \in [0, 2^n -1]$. The voting round's random number is:
65
66
66
67
$$
67
-
R = \sum_{i} r_i \pmod{N}
68
+
R = \left( \sum_{i} r_i \right) \mod{2^n}
68
69
$$
69
70
70
-
where $r_i$ is the local random number generated by the $i^{th}$ data provider, and $ N = 2^n $ denotes the maximum possible size of the individual $n$-bit random numbers.
71
-
This mechanism ensures that the resultant $R$ is a uniformly generated random number as long as at least any one of the inputs was an honestly generated uniformly random number.
72
-
73
-
Importantly, the Merkle root published by the data providers contains a Boolean value that tracks whether the generated random number for the current voting epoch is secure.
74
-
75
-
**Security Mechanism**
76
-
77
-
The security mechanism behind the random number generator protects the protocol against withholding attacks. An adversary could wait until all submissions are known and then choose whether or not to reveal their own commit data to influence the final result. This security mechanism measures the quality of the random number as follows:
78
-
79
-
-**True**: If there are no omissions of reveals for the commits provided by the data providers.
80
-
-**False**: If any omission exists, or if a reveal does not match the committed value.
81
-
82
-
If a data provider causes an omission (or false reveal), they will be penalized, and their random number will not be included in the random number calculation for a number of voting rounds.
71
+
Because commits are fixed before reveals, if any one $r_i$ is uniformly random and not chosen adaptively after seeing others, $R$ is uniformly random over $[0, 2^n -1]$.
83
72
84
73
</details>
85
74
86
75
## Use secure random onchain
87
76
88
77
:::tip
89
78
90
-
You can integrate secure random numbers into your application on Flare for no cost (not even gas!).
79
+
You can integrate secure random numbers into your application on Flare for no cost.
91
80
92
81
:::
93
82
@@ -101,36 +90,21 @@ You can integrate secure random numbers into your application on Flare for no co
101
90
102
91
In addition to the `randomNumber` itself, two other variables are retrieved:
103
92
104
-
-`isSecure`: A boolean flag indicating whether the random number was generated securely. If the protocol detects any attempt to manipulate the random number, this flag is set to `false`.
93
+
-`isSecure`: A boolean flag indicating whether the random number was generated securely:
94
+
-**True**: All providers that committed also revealed, and every reveal matched its commit.
95
+
-**False**: at least one omission or mismatch occurred for the round.
96
+
Offending providers are penalized and excluded for a number of future rounds; the voting round's randomness is flagged as unsafe.
105
97
106
-
-`timestamp`: The UNIX timestamp marking the end of the voting epoch during which data was collected from data providers to generate the specific number. Each voting epoch lasts for a fixed 90-second window.
98
+
-`timestamp`: The UNIX timestamp marking the end of the voting round during which data was collected from data providers to generate the specific number.
99
+
Each voting round lasts for a fixed 90-second window.
107
100
108
101
:::warning[Set EVM Version to Shanghai]
109
102
110
-
-**Using Remix:** Set EVM version to `shanghai` in the **Advanced Configurations** section of the **Solidity Compiler** tab:
-**Using Remix:** Set EVM version to `shanghai` under **Solidity Compiler** → **Advanced Configurations**.
113
104
114
105
-**Using Hardhat or Foundry:** Set EVM version to `shanghai` in [hardhat.config.ts](https://github.com/flare-foundation/flare-hardhat-starter/blob/master/hardhat.config.ts#L34) or [foundry.toml](https://github.com/flare-foundation/flare-foundry-starter/blob/master/foundry.toml).
115
-
116
-
-**Using Standard Solidity JSON:** Set `evmVersion` to `shanghai`:
117
-
118
-
```json
119
-
{
120
-
"settings": {
121
-
"optimizer": {
122
-
/* ... */
123
-
},
124
-
"evmVersion": "shanghai"
125
-
}
126
-
}
127
-
```
128
-
129
-
-**Using `solc` CLI:** Set `--evm-version` to `shanghai`:
130
-
131
-
```bash
132
-
solc --evm-version shanghai <args>
133
-
```
106
+
-**Using Standard Solidity JSON:** Set `"evmVersion": "shaghai"` in `settings`.
107
+
-**Using `solc`:** Add `--evm-version shanghai` flag to your command.
134
108
135
109
:::
136
110
@@ -164,9 +138,10 @@ To obtain a secure random number offchain, you need two key pieces of informatio
This example uses the Go API from [Geth](https://geth.ethereum.org) to retrieve FTSOv2 feed data for FLR/USD, BTC/USD, and ETH/USD from Flare Testnet Coston2.
215
+
This example uses the Go API from [Geth](https://geth.ethereum.org) to retrieve a secure random number on Flare Testnet Coston2.
240
216
241
217
```bash
242
218
go get github.com/ethereum/go-ethereum/ethclient
@@ -270,4 +246,4 @@ All examples in this guide are available at [developer-hub/examples](https://git
0 commit comments