Skip to content

Commit

Permalink
fix(doc): correct description of sha256() and warn users of potenti…
Browse files Browse the repository at this point in the history
…al issues
  • Loading branch information
novusnota committed Oct 3, 2024
1 parent 1744a02 commit 6ace01b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/src/content/docs/book/operators.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ Unary here means that they are applied only to one operand of the given expressi

Unary operators can be one of the two types:

* prefix — placed before the expression.
* postfix (or suffix) — placed after the expression.
* Prefix — placed before the expression.
* Postfix (or suffix) — placed after the expression.

### Non-null assert, `!!` {#unary-non-null-assert}

Expand Down
10 changes: 7 additions & 3 deletions docs/src/content/docs/ref/core-math.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,15 @@ fun sha256(data: Slice): Int;
fun sha256(data: String): Int;
```

Computes and returns the [SHA-256][sha-2] hash as an $256$-bit unsigned [`Int{:tact}`][int] from a passed [`Slice{:tact}`][slice] or [`String{:tact}`][p] `data`.
Computes and returns the [SHA-256][sha-2] hash as a $256$-bit unsigned [`Int{:tact}`][int] from a passed [`Slice{:tact}`][slice] or [`String{:tact}`][p] `data`.

In case `data` is a [`String{:tact}`][p] it should have a number of bits divisible by $8$, and in case it's a [`Slice{:tact}`][slice] it must **also** have no references (i.e. only up to 1023 bits of data in total).
In case `data` is a [`String{:tact}`][p] it should have a number of bits divisible by $8$, and in case it's a [`Slice{:tact}`][slice] it must **also** have no references (i.e. only up to $1023$ bits of data in total). This function tries to resolve constant string values in [compile-time](/ref/core-comptime) whenever possible.

This function tries to resolve constant string values in [compile-time](/ref/core-comptime) whenever possible.
:::caution

If there are more than $128$ bytes in the provided [`String{:tact}`][p] or [`Slice{:tact}`][slice], a compilation error is raised if the compiler can track it, and if not — the hashes of such long arguments would be the same on TON, which might cause collisions. Prefer to hash smaller arguments to prevent such cases.

:::

Usage examples:

Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/ref/stdlib-dns.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Source code (FunC): [dns.fc#L1](https://github.com/tact-lang/tact/blob/e69c7fc99
native dnsInternalNormalize(src: Slice): Slice;
```

Normalizes the internal DNS representation of the [`Slice{:tact}`][slice]. The passed [`Slice{:tact}`][slice] must not have any references, otherwise an exception wit [exit code 134](/book/exit-codes#134) will be thrown: `Invalid argument`.
Normalizes the internal DNS representation of the [`Slice{:tact}`][slice]. The passed [`Slice{:tact}`][slice] must not have any references, otherwise an exception with [exit code 134](/book/exit-codes#134) will be thrown: `Invalid argument`.

Source code (FunC): [dns.fc#L125](https://github.com/tact-lang/tact/blob/e69c7fc99dc9be3fa5ff984456c03ffe8fed3677/stdlib/libs/dns.fc#L125)

Expand Down

0 comments on commit 6ace01b

Please sign in to comment.