Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): warn that dump() is computationally expensive #1189

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Enabled compilation of examples in `data-structures.mdx` and across Cookbook: PR [#917](https://github.com/tact-lang/tact/pull/917)
- Removed the Programmatic API page due to frequent changes. To use the API, please refer to the compiler sources: PR [#1184](https://github.com/tact-lang/tact/pull/1184)
- Added a link to the article by CertiK to Security best practices page: PR [#1185](https://github.com/tact-lang/tact/pull/1185)
- Added a note on `dump()` being computationally expensive: PR [#1189](https://github.com/tact-lang/tact/pull/1189)

### Release contributors

Expand Down
6 changes: 6 additions & 0 deletions docs/src/content/docs/book/debug.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ it('should deploy', async () => {

### Debug with `dump()` {#tests-dump}

:::note

Calling [`dump(){:tact}`][dump] is computationally expensive and consumes a lot of gas. Be sure to always supply enough Toncoins in your tests to avoid [exit code -14](/book/exit-codes#-14).

:::

To see results of [`dump(){:tact}`][dump] function calls and use ["printf debugging"](#approach) approach, one has to:

1. Put calls to [`dump(){:tact}`][dump] and other [common debugging functions](#debug-functions) in relevant places of the code.
Expand Down
8 changes: 6 additions & 2 deletions docs/src/content/docs/book/structs-and-messages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ title: Structs and Messages
description: "Structs can define complex data types that contain multiple fields of different types, while Messages also have a 32-bit header and are convenient to receive and sent message bodies on TON Blockchain"
---

import { Badge } from '@astrojs/starlight/components';

Tact supports a number of [primitive data types](/book/types#primitive-types) that are tailored for smart contract use. However, using individual means of storage often becomes cumbersome, so there are [Structs](#structs) and [Messages](#messages) which allow combining types together.

:::caution
Expand Down Expand Up @@ -108,17 +110,19 @@ Messages are almost the same thing as [Structs](#structs) with the only differen
Tact automatically generates those unique ids (opcodes) for every received Message, but this can be manually overwritten:

```tact
// This Message overwrites its unique id with 0x7362d09c
// This Message overwrites its unique id (opcode) with 0x7362d09c
message(0x7362d09c) TokenNotification {
forwardPayload: Slice as remaining;
}
```

This is useful for cases where you want to handle certain opcodes of a given smart contract, such as [Jetton standard](https://github.com/ton-blockchain/TEPs/blob/master/text/0074-jettons-standard.md). The short-list of opcodes this contract is able to process is [given here in FunC](https://github.com/ton-blockchain/token-contract/blob/main/ft/op-codes.fc). They serve as an interface to the smart contract.

A message opcode can be any compile-time (constant) expression which evaluates to a strictly positive integer that fits into 32-bits, so the following is also a valid message declaration:
<Badge text="Available since Tact 1.6" variant="tip" size="small"/> A message opcode can be any [compile-time](/ref/core-comptime) expression that evaluates to a positive $32$-bit integer, so the following is also valid:

```tact
// This Message overwrites its unique id (opcode) with 898001897,
// which is the evaluated integer value of the specified compile-time expression
message((crc32("Tact") + 42) & 0xFFFF_FFFF) MsgWithExprOpcode {
field: Int as uint4;
}
Expand Down
7 changes: 6 additions & 1 deletion docs/src/content/docs/ref/core-debug.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ fun dump(arg);

Prints the argument `arg` to the contract's debug console. Evaluated only if the `debug` option in the [configuration file](/book/config) is set to `true{:json}`, otherwise does nothing.

This function is computationally expensive and consumes a lot of gas because it prints the location from which it was called, i.e. the filename, line and column numbers, and the original expression that was the `arg` argument.

Can be applied to the following list of types and values:

* [`Int{:tact}`][int]
Expand All @@ -65,7 +67,10 @@ Usage examples:

```tact
// Int
dump(42);
dump(42); // prints:
// File filename.tact:2:1
// dump(42)
// 42

// Bool
dump(true);
Expand Down
Loading