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/builtins.md
+176-3Lines changed: 176 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,19 +41,39 @@ For example:
41
41
let hash = sha256_inline("hello");
42
42
```
43
43
44
-
### `calculate_coin_id`
44
+
### `keccak256`
45
+
46
+
Calculates the [Keccak-256](https://en.wikipedia.org/wiki/SHA-3) hash of the bytes provided. This hash is calculated at runtime.
47
+
48
+
For example:
49
+
50
+
```rue
51
+
let hash = keccak256("hello");
52
+
```
53
+
54
+
### `keccak256_inline`
55
+
56
+
The same as `keccak256`, except the value will be calculated at compile time and inserted into the program. In some rare scenario, this may be an important optimization to avoid hashing the same large constant value many times. However, in most cases, you should just use the regular `keccak256` function.
57
+
58
+
For example:
59
+
60
+
```rue
61
+
let hash = keccak256_inline("hello");
62
+
```
63
+
64
+
### `coinid`
45
65
46
66
A builtin CLVM opcode for hashing the parent coin id, puzzle hash, and amount of a coin into its coin id. See the [Security](/docs/security.md#untrusted-values) section for an explanation of why this opcode exists. Essentially, it adds runtime checks to make sure that the length of the parent coin id and puzzle hash are 32.
Returns a substring of a byte value, given a range of indices.
76
+
Returns a substring of a byte value, given a range of indices. Note that if either index is out of bounds, this will raise an error.
57
77
58
78
For example:
59
79
@@ -62,3 +82,156 @@ substr("hello", 1, 4)
62
82
```
63
83
64
84
This would return `"ell"`
85
+
86
+
### `substr_start`
87
+
88
+
Returns a substring of a byte value, given a starting index. Note that if the index is out of bounds, this will raise an error.
89
+
90
+
For example:
91
+
92
+
```rue
93
+
substr_start("hello", 1)
94
+
```
95
+
96
+
This would return `"ello"`
97
+
98
+
### `g1_map`
99
+
100
+
Hashes the data to a BLS public key, with sha256 and ExpandMsgXmd.
101
+
102
+
For example:
103
+
104
+
```rue
105
+
g1_map("hello")
106
+
```
107
+
108
+
### `g1_map_dist`
109
+
110
+
Hashes the data to a BLS public key, with sha256 and ExpandMsgXmd. This function allows you to add a DST.
111
+
112
+
For example:
113
+
114
+
```rue
115
+
g1_map_dst("hello", "dst")
116
+
```
117
+
118
+
### `g2_map`
119
+
120
+
Hashes the data to a BLS signature, with sha256 and ExpandMsgXmd.
121
+
122
+
For example:
123
+
124
+
```rue
125
+
g2_map("hello")
126
+
```
127
+
128
+
### `g2_map_dst`
129
+
130
+
Hashes the data to a BLS signature, with sha256 and ExpandMsgXmd. This function allows you to add a DST.
131
+
132
+
For example:
133
+
134
+
```rue
135
+
g2_map_dst("hello", "dst")
136
+
```
137
+
138
+
### `pubkey_for_exp`
139
+
140
+
Maps an exponent (secret key) to a G1 point (public key).
141
+
142
+
For example:
143
+
144
+
```rue
145
+
pubkey_for_exp("hello")
146
+
```
147
+
148
+
### `modpow`
149
+
150
+
Computes `(base ^ exponent) % modulus`. Base may be negative, exponent must not be, modulus must not be 0.
151
+
152
+
For example:
153
+
154
+
```rue
155
+
modpow(5, 50, 45)
156
+
```
157
+
158
+
## Verifications
159
+
160
+
The following CLVM operators return `nil` on success, and raise if they fail:
161
+
162
+
1.`bls_pairing_identity`
163
+
2.`bls_verify`
164
+
3.`secp256k1_verify`
165
+
4.`secp256r1_verify`
166
+
167
+
As such, they would be difficult to use if they were implemented as builtin functions. Instead, Rue provides verification **statements**, which can be called similarly to functions but can't directly be used as an expression. You can think of these like specialized `assert` statements, since they will raise if the verification fails, and continue on if not.
168
+
169
+
These are automatically optimized such that ordinary references to `nil` after the verification statements in the block are replaced with the verification expression (since it returns `nil` anyways). If there aren't any possible substitutions, the rest of the block will be wrapped in a cons pair, with the verifications happening first, and then unwrapped back into the expression value of the block. And finally, if multiple verifications need to be done in a group, the `all` operator will be used, since it will always return `nil` as well.
170
+
171
+
All of this is to say that the compiler will pick the most efficient way to insert these verifications into your program without disrupting its behavior at runtime.
172
+
173
+
:::note
174
+
It's not currently possible to dynamically construct the arguments to these verifications from a list at runtime. This is a limitation that seems to exist in Chialisp as well. This may be possible in the future.
175
+
:::
176
+
177
+
### `bls_pairing_identity`
178
+
179
+
Accepts a flattened sequence of public key and signature pairs, and verifies that the pairing of all pairs is the identity. Otherwise, this will raise.
Accepts a signature followed by a flattened sequence of public key and message pairs, and verifies that the aggregate signature is valid. Otherwise, this will raise.
Copy file name to clipboardExpand all lines: docs/operators.md
+16-5Lines changed: 16 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,18 +16,22 @@ slug: /operators
16
16
|`/`|`4 / 2`| Divides two `Int` values and returns the quotient. |
17
17
|`%`|`3 % 2`| Divides two `Int` values and returns the remainder. |
18
18
19
+
:::note
20
+
The `+` operator can be used with `Bytes` values to concatenate them together.
21
+
22
+
The `+`, `-`, and `*` operators can be used with `PublicKey` or `Signature` values to perform the corresponding BLS math operations (ie point addition, subtraction, or multiplication).
|`+`|`"A" + "B"`| Concatenates two values with the `Bytes` together. |
32
+
:::note
33
+
The `-` operator can be used with `PublicKey` or `Signature` values to negate them.
34
+
:::
31
35
32
36
## Bitwise
33
37
@@ -62,3 +66,10 @@ slug: /operators
62
66
:::note
63
67
The comparison operators can also be used with `Bytes` values, and the special byte-specific `>s` operator is used to implement this in [CLVM](https://chialisp.com/operators/#comparison).
0 commit comments