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/language/attachments.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: Attachments
3
-
sidebar_position: 17
3
+
sidebar_position: 18
4
4
---
5
5
6
6
Attachments are a feature of Cadence designed to allow developers to extend a struct or resource type (even one that they did not create) with new functionality, without requiring the original author of the type to plan or account for the intended behavior.
The following describes Cadence's built in functions. Examples are also provided.
7
+
6
8
## `panic`
7
-
#
8
9
9
10
```cadence
10
11
view fun panic(_ message: String): Never
11
12
```
12
13
13
-
Terminates the program unconditionally
14
-
and reports a message which explains why the unrecoverable error occurred.
14
+
Terminates the program unconditionally and reports a message, which explains why the unrecoverable error occurred.
15
15
16
16
```cadence
17
17
panic("something went wrong: ...")
@@ -23,9 +23,7 @@ panic("something went wrong: ...")
23
23
view fun assert(_ condition: Bool, message: String)
24
24
```
25
25
26
-
Terminates the program if the given condition is false,
27
-
and reports a message which explains how the condition is false.
28
-
Use this function for internal sanity checks.
26
+
Terminates the program if the given condition is false, and reports a message that explains how the condition is false. Use this function for internal sanity checks.
29
27
30
28
The message argument is optional.
31
29
@@ -36,48 +34,25 @@ view fun revertibleRandom<T: FixedSizeUnsignedInteger>(modulo: T): T
36
34
```
37
35
Returns a pseudo-random integer.
38
36
39
-
`T` can be any fixed-size unsigned integer type (`FixedSizeUnsignedInteger`, i.e.
If provided, the returned integer is between `0` and `modulo -1`.
45
-
If not provided, the returned integer is between `0` and the maximum value of `T`.
46
-
The function errors if `modulo` is equal to 0.
37
+
`T` can be any fixed-size unsigned integer type (`FixedSizeUnsignedInteger`, i.e., `UInt8`, `UInt16`, `UInt32`, `UInt64`, `UInt128`, `UInt256`, `Word8`, `Word16`, `Word32`, `Word64`, `Word128`, or `Word256`).
47
38
39
+
The modulo argument is optional. If provided, the returned integer is between `0` and `modulo -1`. If not provided, the returned integer is between `0` and the maximum value of `T`. The function errors if `modulo` is equal to 0.
48
40
49
-
The sequence of returned random numbers is independent for
50
-
every transaction in each block.
51
-
Under the hood, Cadence instantiates a cryptographically-secure pseudo-random number
52
-
generator (CSPRG) for each transaction independently, where the seeds of any two transactions
53
-
are different with near certainty.
41
+
The sequence of returned random numbers is independent for every transaction in each block. Under the hood, Cadence instantiates a cryptographically-secure pseudo-random number generator (CSPRG) for each transaction independently, where the seeds of any two transactions are different with near certainty.
54
42
55
-
The random numbers returned are unpredictable
56
-
(unpredictable for miners at block construction time,
57
-
and unpredictable for cadence logic at time of call),
58
-
verifiable, as well as unbiasable by miners and previously-running Cadence code.
59
-
See [Secure random number generator for Flow’s smart contracts](https://forum.flow.com/t/secure-random-number-generator-for-flow-s-smart-contracts/5110)
60
-
and [FLIP120](https://github.com/onflow/flips/pull/120) for more details.
43
+
The random numbers returned are unpredictable (unpredictable for miners at block construction time, and unpredictable for cadence logic at time of call), verifiable, as well as _unbiasable_ by miners and previously-running Cadence code. See [Secure random number generator for Flow’s smart contracts] and [FLIP120] for more details.
61
44
62
-
Nevertheless, developers need to be mindful to use `revertibleRandom()` correctly:
45
+
Nevertheless, developers need to be mindful to use `revertibleRandom()` correctly.
63
46
64
-
:::warning
47
+
:::danger
65
48
66
-
A transaction can atomically revert all its action.
67
-
It is possible for a transaction submitted by an untrusted party
68
-
to post-select favorable results and revert the transaction for unfavorable results.
49
+
A transaction can atomically revert all of its action. This means that if you're letting users submit transactions, as opposed to you submitting them on your backend with a wallet you control, those users can submit the transaction in such a way that it reverts if the user doesn't like the outcome.
69
50
70
51
:::
71
52
72
-
The function usage remains safe when called by a trusted party that does not
73
-
perform post-selection on the returned random numbers.
53
+
The function usage remains safe when called by a trusted party that does not perform post-selection on the returned random numbers.
74
54
75
-
This limitation is inherent to any smart contract platform that allows transactions to roll back atomically
76
-
and cannot be solved through safe randomness alone.
77
-
In cases where a non-trusted party can interact through their own transactions
78
-
with smart contracts generating random numbers,
79
-
it is recommended to use [commit-reveal schemes](https://github.com/onflow/flips/pull/123)
80
-
as outlined in this [tentative example](https://github.com/onflow/flips/blob/main/protocol/20230728-commit-reveal.md#tutorials-and-examples) (full tutorial coming soon).
55
+
This limitation is inherent to any smart contract platform that allows transactions to roll back atomically and cannot be solved through safe randomness alone. In cases where a non-trusted party can interact through their own transactions with smart contracts generating random numbers, it is recommended to use [commit-reveal schemes].
81
56
82
57
## `RLP`
83
58
@@ -91,10 +66,10 @@ Cadence provides RLP decoding functions in the built-in `RLP` contract, which do
91
66
view fun decodeString(_ input: [UInt8]): [UInt8]
92
67
```
93
68
94
-
Decodes an RLP-encoded byte array. RLP calls this a "string."
95
-
The byte array should only contain of a single encoded value for a string.
96
-
If the encoded value type does not match, or it has trailing unnecessary bytes, the program aborts.
97
-
If the function encounters any error while decoding, the program aborts.
69
+
Decodes an RLP-encoded byte array. RLP calls this a _string_. The byte array should only contain a single encoded value for a string.
70
+
71
+
-If the encoded value type does not match or if it has trailing unnecessary bytes, the program aborts.
72
+
-If the function encounters any error while decoding, the program aborts.
98
73
99
74
### `decodeList`
100
75
@@ -104,7 +79,15 @@ view fun decodeList(_ input: [UInt8]): [[UInt8]]`
104
79
105
80
Decodes an RLP-encoded list into an array of RLP-encoded items.
106
81
107
-
Note that this function does not recursively decode, so each element of the resulting array is RLP-encoded data.
108
-
The byte array should only contain of a single encoded value for a list.
109
-
If the encoded value type does not match, or it has trailing unnecessary bytes, the program aborts.
110
-
If the function encounters any error while decoding, the program aborts.
82
+
Note that this function does not recursively decode, so each element of the resulting array is RLP-encoded data. The byte array should only contain a single encoded value for a list.
83
+
84
+
- If the encoded value type does not match or if it has trailing unnecessary bytes, the program aborts.
85
+
- If the function encounters any error while decoding, the program aborts.
Copy file name to clipboardExpand all lines: docs/language/contract-updatability.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: Contract Updatability
3
-
sidebar_position: 19
3
+
sidebar_position: 20
4
4
---
5
5
6
6
A [contract] is a collection of data (its state) and code (its functions) that lives in the contract storage area of an account. When a contract is _updated_, it is important to make sure that the changes introduced do not lead to runtime inconsistencies for already stored data.
Copy file name to clipboardExpand all lines: docs/language/core-events.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: Core Events
3
-
sidebar_position: 22
3
+
sidebar_position: 23
4
4
---
5
5
6
6
Core events are events emitted directly from the Flow Virtual Machine (FVM). The events have the same name on all networks and do not follow the standard naming (they have no address).
0 commit comments