Skip to content

Commit

Permalink
feat: remove __tact_verify_address to save gas (#1207)
Browse files Browse the repository at this point in the history
There is no more automatic address validation, so the user
is supposed to do it manually if it's needed.

Also, removed the masterchain enabling config option.
  • Loading branch information
anton-trunov authored Dec 18, 2024
1 parent b3e88c2 commit 9156921
Show file tree
Hide file tree
Showing 32 changed files with 97 additions and 761 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Optional types for `self` argument in `extends mutates` functions are now allowed: PR [#854](https://github.com/tact-lang/tact/pull/854)
- Error codes in the report are now formatted as a list: PR [#1051](https://github.com/tact-lang/tact/pull/1051)
- Clarify error message for bounced types from which accessed a field that does not fit in 224 bytes: PR [#1111](https://github.com/tact-lang/tact/pull/1111)
- Do not automatically validate all addresses when receiving/sending messages or using address manipulating functions: PR [#1207](https://github.com/tact-lang/tact/pull/1207)
- Remove `enabledMasterchain` compiler config option from `tact.config.json`: PR [#1207](https://github.com/tact-lang/tact/pull/1207)
- Remove `org.ton.chain.any.v0` interface: PR [#1207](https://github.com/tact-lang/tact/pull/1207)

### Fixed

Expand Down
1 change: 0 additions & 1 deletion docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ export default defineConfig({
{ slug: 'book/upgrades' },
{ slug: 'book/import' },
{ slug: 'book/config' },
{ slug: 'book/masterchain' },
{ slug: 'book/func' },
{ slug: 'book/security-best-practices' },
],
Expand Down
1 change: 0 additions & 1 deletion docs/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@
"lvalue",
"lvalues",
"masterchain",
"masterchain",
"mathrm",
"maxint",
"minmax",
Expand Down
3 changes: 2 additions & 1 deletion docs/src/content/docs/book/cells.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Kinds (or subtypes) of all cells are encoded by an integer between $-1$ and $255

[TVM][tvm] currently supports the following exotic cell subtypes:
* [Pruned branch cell][c-pruned], with subtype encoded as $1$ — they represent deleted subtrees of cells.
* [Library reference cell][c-library], with subtype encoded as $2$ — they are used for storing libraries, and usually, in [masterchain](/book/masterchain) contexts.
* [Library reference cell][c-library], with subtype encoded as $2$ — they are used for storing libraries, and usually, in [masterchain][masterchain] contexts.
* [Merkle proof cell][c-mproof], with subtype encoded as $3$ — they are used for verifying that certain portions of other cell's tree data belong to the full tree.
* [Merkle update cell][c-mupdate], with subtype encoded as $4$ — they always have two references and behave like a [Merkle proof][mproof] for both of them.

Expand All @@ -40,6 +40,7 @@ Kinds (or subtypes) of all cells are encoded by an integer between $-1$ and $255
[c-mproof]: https://docs.ton.org/develop/data-formats/exotic-cells#merkle-proof
[c-mupdate]: https://docs.ton.org/develop/data-formats/exotic-cells#merkle-update
[mproof]: https://docs.ton.org/develop/data-formats/exotic-cells#simple-proof-verifying-example
[masterchain]: https://docs.ton.org/v3/documentation/smart-contracts/shards/shards-intro#masterchain

### Levels {#cells-levels}

Expand Down
34 changes: 0 additions & 34 deletions docs/src/content/docs/book/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -149,39 +149,6 @@ If set to `true{:json}`, enables debug output of a contract and allows usage of

:::

#### `masterchain` {#options-masterchain}

`false{:json}` by default.

If set to `true{:json}`, enables [masterchain](/book/masterchain) support.

```json filename="tact.config.json" {8,14}
{
"projects": [
{
"name": "some_prefix",
"path": "./contract.tact",
"output": "./contract_output",
"options": {
"masterchain": true
}
},
{
"name": "ContractUnderBlueprint",
"options": {
"masterchain": true
}
}
]
}
```

:::note

Read more on the dedicated page: [Masterchain](/book/masterchain).

:::

#### `external` {#options-external}

`false{:json}` by default.
Expand Down Expand Up @@ -399,7 +366,6 @@ In [Blueprint][bp], `mode` is always set to `"full"{:json}` and cannot be overwr
"name": "ContractUnderBlueprint",
"options": {
"debug": false,
"masterchain": false,
"external": false,
"ipfsAbiGetter": true,
"interfacesGetter": true,
Expand Down
1 change: 0 additions & 1 deletion docs/src/content/docs/book/contracts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ Tact has a small set of interfaces provided under specific conditions:
* `"org.ton.abi.ipfs.v0"{:tact}`, in accordance to [OTP-003: Self-ABI Reporting](/ref/evolution/otp-003) — opt-in via [`ipfsAbiGetter`](/book/config#options-ipfsabigetter) config property
* `"org.ton.deploy.lazy.v0"{:tact}`, in accordance to [OTP-005: Argument-addressable contracts](/ref/evolution/otp-005)
* `"org.ton.debug.v0"{:tact}`, but only if [debug mode](/book/debug#debug-mode) is enabled
* `"org.ton.chain.any.v0"{:tact}` if [masterchain](/book/masterchain) support is enabled, and `"org.ton.chain.workchain.v0"{:tact}` otherwise

Some [traits][trait] in [standard libraries](/ref/standard-libraries) define their interfaces too:

Expand Down
16 changes: 11 additions & 5 deletions docs/src/content/docs/book/exit-codes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ title: Exit codes
description: "An exit code is a 32-bit signed integer, which indicates whether the compute or action phase of the transaction was successful, and if not — holds the code of the exception occurred"
---

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

Each transaction on TON Blockchain consists of [multiple phases](https://docs.ton.org/learn/tvm-instructions/tvm-overview#transactions-and-phases). An _exit code_ is a $32$-bit signed integer, which indicates whether the [compute](#compute) or [action](#action) phase of the transaction was successful, and if not — holds the code of the exception occurred. Each exit code represents its own exception or resulting state of the transaction.

Exit codes $0$ and $1$ indicate normal (successful) execution of the [compute phase](#compute). Exit (or [result](#action)) code $0$ indicates normal (successful) execution of the [action phase](#action). Any other exit code indicates that a certain exception has occurred and that the transaction wasn't successful in one way or another, i.e. transaction was reverted or the inbound message has bounced back.
Expand Down Expand Up @@ -60,8 +62,8 @@ Exit code | Origin | Brief description
[$133$](#133) | Tact compiler ([Compute phase][c]) | Contract stopped. Reserved, but never thrown.
[$134$](#134) | Tact compiler ([Compute phase][c]) | Invalid argument.
[$135$](#135) | Tact compiler ([Compute phase][c]) | Code of a contract was not found.
[$136$](#136) | Tact compiler ([Compute phase][c]) | Invalid address.
[$137$](#137) | Tact compiler ([Compute phase][c]) | Masterchain support is not enabled for this contract.
~~[$136$](#136)~~ | ~~Tact compiler ([Compute phase][c])~~ | ~~Invalid address.~~ Removed since Tact 1.6
~~[$137$](#137)~~ | ~~Tact compiler ([Compute phase][c])~~ | ~~Masterchain support is not enabled for this contract.~~ Removed since Tact 1.6

:::note

Expand Down Expand Up @@ -526,7 +528,7 @@ If the configuration is absent, default values are:
* `ext_msg_limits.max_depth` is equal to $2^{9}$ — maximum external message [depth](/book/cells#cells-representation).
* `max_acc_state_cells` is equal to $2^{16}$ — maximum number of [cells][cell] that an account state can occupy.
* `max_acc_state_bits` is equal to $2^{16} * 1023$ — maximum account state size in bits.
* `max_acc_public_libraries` is equal to $2^{8}$ — maximum number of [library reference cells](/book/cells#cells-kinds) that an account state can use on the [masterchain](/book/masterchain).
* `max_acc_public_libraries` is equal to $2^{8}$ — maximum number of [library reference cells](/book/cells#cells-kinds) that an account state can use on the masterchain.
* `defer_out_queue_size_limit` is equal to $2^{8}$ — maximum number of outbound messages to be queued (regards validators and collators).

## Tact compiler
Expand Down Expand Up @@ -623,10 +625,12 @@ If the code of the contract doesn't match the one saved in TypeScript wrappers,

### 136: Invalid address {#136}

<Badge text="Removed since Tact 1.6" variant="tip" size="medium"/><p/>

A value of type [`Address{:tact}`][p] is valid in Tact when:

* It occupies $267$ bits: $11$ bits for the chain ID prefix and $256$ bits for the [address itself](https://docs.ton.org/learn/overviews/addresses#address-of-smart-contract).
* It belongs to either: basechain (ID $0$) or masterchain (ID $-1$), with the latter requiring [masterchain support](/book/masterchain#support) to be enabled.
* It belongs to either basechain (ID $0$) or masterchain (ID $-1$).

If the [`Address{:tact}`][p] isn't valid, the error with exit code $136$ will be thrown: `Invalid address`.

Expand All @@ -644,7 +648,9 @@ try {

### 137: Masterchain support is not enabled for this contract {#137}

Any attempts to point to masterchain (ID $-1$) or otherwise interact with it without [enabling masterchain support](/book/masterchain#support) throw an exception with exit code $137$: `Masterchain support is not enabled for this contract`.
<Badge text="Removed since Tact 1.6" variant="tip" size="medium"/><p/>

Prior to removal, any attempts to point to masterchain (ID $-1$) or otherwise interact with it without enabling masterchain support were throwing an exception with exit code $137$: `Masterchain support is not enabled for this contract`.

```tact
let masterchainID = -1;
Expand Down
57 changes: 0 additions & 57 deletions docs/src/content/docs/book/masterchain.mdx

This file was deleted.

2 changes: 1 addition & 1 deletion docs/src/content/docs/ref/core-advanced.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ parsedVarAddr.address.loadUint(123); // 345
[int]: /book/integers
[slice]: /book/cells#slices
[s]: /book/structs-and-messages#structs
[masterchain]: /book/masterchain
[masterchain]: https://docs.ton.org/v3/documentation/smart-contracts/shards/shards-intro#masterchain
[cell-hash]: /ref/core-cell#cellhash
[nanotoncoin]: /book/integers#nanotoncoin

Expand Down
4 changes: 2 additions & 2 deletions docs/src/content/docs/ref/core-common.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ let oldTonFoundationAddr: Address =

:::caution

This method throws an error with [exit code 136](/book/exit-codes#136) if `chain` is invalid or with [exit code 137](/book/exit-codes#137) if `chain` points to the masterchain ($-1$) without [masterchain support](/book/masterchain) enabled.
Make sure your specify only supported chain IDs: $0$ for the basechain and $-1$ for the masterchain.

:::

Expand Down Expand Up @@ -181,7 +181,7 @@ let hereBeDragons: Address = contractAddressExt(0, initPkg.code, initPkg.data);

:::caution

This method throws an error with [exit code 136](/book/exit-codes#136) if `chain` is invalid or with [exit code 137](/book/exit-codes#137) if `chain` points to the masterchain ($-1$) without [masterchain support](/book/masterchain) enabled.
Make sure your specify only supported chain IDs: $0$ for the basechain and $-1$ for the masterchain.

:::

Expand Down
1 change: 0 additions & 1 deletion docs/src/content/docs/zh-cn/book/contracts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ Tact 有一小套在特定条件下提供的接口:
- `"org.ton.abi.ipfs.v0"{:tact}`,根据 [OTP-003: Self-ABI Reporting](/zh-cn/ref/evolution/otp-003) - 通过 [`ipfsAbiGetter`](/zh-cn/book/config#options-ipfsabigetter)配置属性选择加入
- `"org.ton.deploy.lazy.v0"{:tact}`,符合[OTP-005:参数可寻址合约](/zh-cn/ref/evolution/otp-005)
- `"org.ton.debug.v0"{:tact}`,但只有在启用了[调试模式](/zh-cn/book/debug#debug-mode)时才会这样做
- `"org.ton.chain.any.v0"{:tact}` 如果启用了 [masterchain](/zh-cn/book/masterchain) 支持,否则为 `"org.ton.chain.workchain.v0"{:tact}`

[标准库](/zh-cn/ref/standard-libraries)中的一些[traits][trait]也定义了它们的接口:

Expand Down
5 changes: 0 additions & 5 deletions schemas/configSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@
"default": false,
"description": "False by default. If set to true, enables debug output of a contract and allows usage of `dump()` function, which is useful for debugging purposes. With this option enabled, the contract will report that it was compiled in debug mode using the supported_interfaces method.\n\nRead more on debugging Tact code: https://docs.tact-lang.org/book/debug."
},
"masterchain": {
"type": "boolean",
"default": false,
"description": "False by default. If set to true, enables masterchain support.\n\nRead more about masterchain: https://docs.tact-lang.org/book/masterchain."
},
"external": {
"type": "boolean",
"default": false,
Expand Down
5 changes: 0 additions & 5 deletions src/abi/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,4 @@ export const contractErrors = {
contractStopped: { id: 133, message: "Contract stopped" },
invalidArgument: { id: 134, message: "Invalid argument" },
codeNotFound: { id: 135, message: "Code of a contract was not found" },
invalidAddress: { id: 136, message: "Invalid address" },
masterchainNotEnabled: {
id: 137,
message: "Masterchain support is not enabled for this contract",
},
};
10 changes: 1 addition & 9 deletions src/abi/global.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Address, beginCell, Cell, toNano } from "@ton/core";
import { enabledDebug, enabledMasterchain } from "../config/features";
import { enabledDebug } from "../config/features";
import {
writeAddress,
writeCell,
Expand Down Expand Up @@ -163,14 +163,6 @@ export const GlobalFunctions: Map<string, AbiFunction> = new Map([
ref,
);
}
if (!enabledMasterchain(ctx.ctx)) {
if (address.workChain !== 0) {
throwCompilationError(
`Address ${str} from masterchain are not enabled for this contract`,
ref,
);
}
}

// Generate address
const res = writeAddress(address, ctx);
Expand Down
8 changes: 4 additions & 4 deletions src/benchmarks/benchmarks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ describe("benchmarks", () => {
.description as TransactionDescriptionGeneric
).computePhase as TransactionComputeVm
).gasUsed;
expect(gasUsed).toMatchInlineSnapshot(`3648n`);
expect(gasUsed).toMatchInlineSnapshot(`3146n`);

// Verify code size
const codeSize = functions.init!.code.toBoc().length;
expect(codeSize).toMatchInlineSnapshot(`281`);
expect(codeSize).toMatchInlineSnapshot(`241`);
});

it("benchmark functions (inline)", async () => {
Expand All @@ -57,10 +57,10 @@ describe("benchmarks", () => {
.description as TransactionDescriptionGeneric
).computePhase as TransactionComputeVm
).gasUsed;
expect(gasUsed).toMatchInlineSnapshot(`3517n`);
expect(gasUsed).toMatchInlineSnapshot(`3015n`);

// Verify code size
const codeSize = functionsInline.init!.code.toBoc().length;
expect(codeSize).toMatchInlineSnapshot(`274`);
expect(codeSize).toMatchInlineSnapshot(`234`);
});
});
1 change: 0 additions & 1 deletion src/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export function check(args: {
const stdlib = createVirtualFileSystem("@stdlib/", files);
let ctx: CompilerContext = new CompilerContext();
ctx = featureEnable(ctx, "debug"); // Enable debug flag (does not affect type checking in practice)
ctx = featureEnable(ctx, "masterchain"); // Enable masterchain flag to avoid masterchain-specific errors
ctx = featureEnable(ctx, "external"); // Enable external messages flag to avoid external-specific errors

const ast = getAstFactory();
Expand Down
4 changes: 0 additions & 4 deletions src/config/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ export function enabledDebug(ctx: CompilerContext) {
return featureEnabled(ctx, "debug");
}

export function enabledMasterchain(ctx: CompilerContext) {
return featureEnabled(ctx, "masterchain");
}

export function enabledExternals(ctx: CompilerContext) {
return featureEnabled(ctx, "external");
}
Expand Down
6 changes: 0 additions & 6 deletions src/config/parseConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ export const optionsSchema = z
* Read more: https://docs.tact-lang.org/book/debug
*/
debug: z.boolean().optional(),
/**
* If set to true, enables masterchain support.
*
* Read more: https://docs.tact-lang.org/book/masterchain
*/
masterchain: z.boolean().optional(),
/**
* If set to true, enables support of external message receivers.
*
Expand Down
Loading

0 comments on commit 9156921

Please sign in to comment.