Skip to content

Commit 3b57ec0

Browse files
authored
Merge pull request #247 from onflow/built-in-functions-environment-info
Edit Built-in Functions and Environment Information articles
2 parents e1b9f8b + 4cb9fd2 commit 3b57ec0

19 files changed

Lines changed: 57 additions & 75 deletions

docs/language/access-control.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Access Control
3-
sidebar_position: 10
3+
sidebar_position: 12
44
---
55

66
Access control allows making certain parts of a program accessible/visible and making other parts inaccessible/invisible.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"position": 16
2+
"position": 6
33
}

docs/language/attachments.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Attachments
3-
sidebar_position: 17
3+
sidebar_position: 18
44
---
55

66
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.
Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
22
title: Built-in Functions
3-
sidebar_position: 23
3+
sidebar_position: 8
44
---
55

6+
The following describes Cadence's built in functions. Examples are also provided.
7+
68
## `panic`
7-
#
89

910
```cadence
1011
view fun panic(_ message: String): Never
1112
```
1213

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.
1515

1616
```cadence
1717
panic("something went wrong: ...")
@@ -23,9 +23,7 @@ panic("something went wrong: ...")
2323
view fun assert(_ condition: Bool, message: String)
2424
```
2525

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.
2927

3028
The message argument is optional.
3129

@@ -36,48 +34,25 @@ view fun revertibleRandom<T: FixedSizeUnsignedInteger>(modulo: T): T
3634
```
3735
Returns a pseudo-random integer.
3836

39-
`T` can be any fixed-size unsigned integer type (`FixedSizeUnsignedInteger`, i.e.
40-
(`UInt8`, `UInt16`, `UInt32`, `UInt64`, `UInt128`, `UInt256`,
41-
`Word8`, `Word16`, `Word32`, `Word64`, `Word128`, `Word256`).
42-
43-
The modulo argument is optional.
44-
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`).
4738

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.
4840

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.
5442

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.
6144

62-
Nevertheless, developers need to be mindful to use `revertibleRandom()` correctly:
45+
Nevertheless, developers need to be mindful to use `revertibleRandom()` correctly.
6346

64-
:::warning
47+
:::danger
6548

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.
6950

7051
:::
7152

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.
7454

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].
8156

8257
## `RLP`
8358

@@ -91,10 +66,10 @@ Cadence provides RLP decoding functions in the built-in `RLP` contract, which do
9166
view fun decodeString(_ input: [UInt8]): [UInt8]
9267
```
9368

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.
9873

9974
### `decodeList`
10075

@@ -104,7 +79,15 @@ view fun decodeList(_ input: [UInt8]): [[UInt8]]`
10479

10580
Decodes an RLP-encoded list into an array of RLP-encoded items.
10681

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.
86+
87+
<!-- Relative links. Will not render on the page -->
88+
89+
[Secure random number generator for Flow’s smart contracts]: https://forum.flow.com/t/secure-random-number-generator-for-flow-s-smart-contracts/5110
90+
[FLIP120]: https://github.com/onflow/flips/pull/120
91+
[commit-reveal schemes]: https://developers.flow.com/tutorials/native-vrf/commit-reveal-cadence
92+
[tentative example]: https://github.com/onflow/flips/blob/main/protocol/20230728-commit-reveal.md#tutorials-and-examples
93+

docs/language/capabilities.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Capabilities
3-
sidebar_position: 11
3+
sidebar_position: 13
44
---
55

66
Cadence supports [capability-based security] through the [object-capability model].

docs/language/contract-updatability.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Contract Updatability
3-
sidebar_position: 19
3+
sidebar_position: 20
44
---
55

66
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.

docs/language/contracts.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Contracts
3-
sidebar_position: 18
3+
sidebar_position: 19
44
---
55

66
A contract is a collection of type definitions, data (its state), and code (its functions) that is stored in the contract storage area of an account.

docs/language/control-flow.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Control Flow
3-
sidebar_position: 7
3+
sidebar_position: 9
44
---
55

66
Control flow statements control the flow of execution in a function.

docs/language/core-events.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Core Events
3-
sidebar_position: 22
3+
sidebar_position: 23
44
---
55

66
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).

docs/language/enumerations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Enumerations
3-
sidebar_position: 13
3+
sidebar_position: 15
44
---
55

66
Enumerations are sets of symbolic names bound to unique, constant values, which can be compared by identity.

0 commit comments

Comments
 (0)