diff --git a/CHANGELOG.md b/CHANGELOG.md index 7adda2edc..ed59a4c82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The `parseImports` function now returns AST import nodes instead of raw strings: PR [#966](https://github.com/tact-lang/tact/pull/966) - Optional types for `self` argument in `extends mutates` functions are now allowed: PR [#854](https://github.com/tact-lang/tact/pull/854) +- Docs: complete overhaul of the exit codes page: PR [#978](https://github.com/tact-lang/tact/pull/978) ### Fixed diff --git a/cspell-fift-words-adjusted.txt b/cspell-fift-words-adjusted.txt index 3ec53abab..53d734641 100644 --- a/cspell-fift-words-adjusted.txt +++ b/cspell-fift-words-adjusted.txt @@ -29,6 +29,7 @@ Pos Split abort abs +addop allot and anon diff --git a/cspell.json b/cspell.json index 382c2ef3a..fdbd9dac6 100644 --- a/cspell.json +++ b/cspell.json @@ -106,6 +106,8 @@ "Tarjan", "testdata", "Topup", + "Toncoin", + "Toncoins", "Trunov", "typechecker", "uintptr", diff --git a/docs/README.md b/docs/README.md index b78cb8fc1..4b626ddbd 100644 --- a/docs/README.md +++ b/docs/README.md @@ -101,6 +101,10 @@ All commands are run from the root of the project, from a terminal: | `yarn astro ...` | Run CLI commands like `astro add`, `astro check`, etc. | `yarn astro -- --help` | Get help using the Astro CLI. +### ⚠️ Gotchas + +- When updating TextMate grammars in `grammars/` (for example, `grammar-tact.json`), make sure that the value for the `"name"` property is written all lowercase, otherwise highlighting will break. + ### πŸ‘€ Want to learn more about the framework behind Tact docs? Check out [Starlight’s docs](https://starlight.astro.build/), read [the Astro documentation](https://docs.astro.build), or jump into the [Astro Discord server](https://astro.build/chat). diff --git a/docs/astro.config.mjs b/docs/astro.config.mjs index 30d746bf8..a2c581828 100644 --- a/docs/astro.config.mjs +++ b/docs/astro.config.mjs @@ -33,7 +33,8 @@ export default defineConfig({ behavior: "append", properties: { class: "autolink-header", - ariaHidden: true, + ariaHidden: "true", + ariaLabel: "Link to this header", tabIndex: -1, }, }], diff --git a/docs/cspell.json b/docs/cspell.json index 1f53904be..006f966d6 100644 --- a/docs/cspell.json +++ b/docs/cspell.json @@ -2,55 +2,39 @@ "$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json", "version": "0.2", "language": "en", + "dictionaryDefinitions": [ + { + "name": "fift-words", + "path": "../cspell-fift-words-adjusted.txt" + }, + { + "name": "tvm-instructions", + "path": "../cspell-tvm-instructions.txt" + } + ], + "dictionaries": ["fift-words", "tvm-instructions"], "words": [ "ADDRAND", "BBITS", "BREFS", "Brujin", - "CHKSIGNS", - "CHKSIGNU", - "CONFIGOPTPARAM", - "CTOS", "Cheatsheet", "Cheatsheets", "Comptime", - "DEBUGSTR", - "DUEPAYMENT", "Daniil", "Decompilation", "Decompiled", "Descr", "DomΓ­nguez", - "ENDC", "Epva", - "Fift", - "Fift", - "GASCONSUMED", - "GETFORWARDFEE", - "GETFORWARDFEESIMPLE", - "GETGASFEE", - "GETGASFEESIMPLE", - "GETORIGINALFWDFEE", - "GETSTORAGEFEE", "Georgiy", - "HASHCU", - "HASHEXT", - "HASHSU", "HΓ©ctor", "IPFS", "JesΓΊs", "Jetton", "Jettons", - "KECCAK", "Komarov", "Korshakov", - "LDDICT", - "LDIX", - "LDREF", - "LDSLICEX", - "LDUX", - "LDVARUINT", - "LTIME", "Laika", "MYADDR", "Masterchain", diff --git a/docs/src/content/docs/book/exit-codes.mdx b/docs/src/content/docs/book/exit-codes.mdx index dc5c78744..8ede3e76a 100644 --- a/docs/src/content/docs/book/exit-codes.mdx +++ b/docs/src/content/docs/book/exit-codes.mdx @@ -3,323 +3,671 @@ 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 β€” signals the code of the exception occurred" --- -:::caution - THis page is under re-construction as per [#106](https://github.com/tact-lang/tact-docs/issues/106). All anchor links (`#`) may change in the future! +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. + +TON Blockchain reserves exit code values from $0$ to $127$, while Tact utilizes exit codes from $128$ to $255$. Note, that exit codes used by Tact indicate contract errors which can occur when using Tact-generated FunC code, and are therefore thrown in the transaction's [compute phase](#compute) and not during the compilation. + +The range from $256$ to $65535$ is free for developer-defined exit codes. + +:::note + + While an exit (or [result](#action)) code is a $32$-bit signed integer on TON Blockchain, an attempt to [throw](/ref/core-debug) an exit code out of bounds of the $16$-bit unsigned integer ($0 - 65535$) will cause an error with [exit code 5](#5). That's done intentionally to prevent some exit codes from being produced artificially, such as the [exit code -14](#-14). + ::: -An exit code is a $16$-bit unsigned integer which ranges between $0$ to $65535$ (or $2_{16} - 1$). - -Codes from $0$ to $127$ are allocated for FunC (TVM), $128$ to $255$ for Tact. The range from $256$ to $65535$ is free for developer-defined exit codes. - -List of pre-allocated exit codes: - -Exit Code | phase | Description -:--------- | :----------------- | -------------------------------------------------------------------------------------------------------------------------- -$0$ | [Compute phase][c] | Standard successful execution exit code -$2$ | [Compute phase][c] | Stack underflow. Last op-code consumed more elements than there are on the stacks -$3$ | [Compute phase][c] | Stack overflow. More values have been stored on a stack than allowed by this version of TVM -$4$ | [Compute phase][c] | Integer overflow. Integer does not fit into βˆ’2256 ≀ x < 2256 or a division by zero has occurred -$5$ | [Compute phase][c] | Integer out of expected range -$6$ | [Compute phase][c] | Invalid opcode. Instruction is unknown in the current TVM version -$7$ | [Compute phase][c] | Type check error. An argument to a primitive is of an incorrect value type -$8$ | [Compute phase][c] | Cell overflow. Writing to builder is not possible since after operation there would be more than 1023 bits or 4 references -$9$ | [Compute phase][c] | Cell underflow. Read from slice primitive tried to read more bits or references than there are -$10$ | [Compute phase][c] | Dictionary error. Error during manipulation with dictionary (hashmaps) -$13$ | [Compute phase][c] | Out of gas error. Thrown by TVM when the remaining gas becomes negative -$-14$ | [Compute phase][c] | It means out of gas error, same as $13$. Negative, because it cannot be faked -$32$ | [Action phase][a] | Action list is invalid. Set during action phase if c5 register after execution contains unparsable object -$34$ | [Action phase][a] | Action is invalid or not supported. Set during action phase if current action cannot be applied -$37$ | [Action phase][a] | Not enough TON. Message sends too much TON (or there is not enough TON after deducting fees) -$38$ | [Action phase][a] | Not enough extra-currencies -$128$ | Tact (Compiler) | Null reference exception β€” compiler expects an integer or cell but a null value has been passed -$129$ | Tact (Compiler) | Invalid serialization prefix β€” if there is any inconsistency with the previous op-code check, this exit code will be thrown -$130$ | Tact (Compiler) | Invalid incoming message β€” no suitable operation is found -$131$ | Tact (Compiler) | Constraints error -$132$ | Tact (Compiler) | Access denied β€” someone other than the owner sent a message to the contract -$133$ | Tact (Compiler) | Contract stopped β€” a message has been sent to a stopped contract -$134$ | Tact (Compiler) | Invalid argument β€” invalid Base64 string -$135$ | Tact (Compiler) | Code of a contract was not found β€” false flag for a dictionary call -$136$ | Tact (Compiler) | Invalid Address β€” Non $267$-bit Address or invalid chain id (other than 0 or -1) -$137$ | Tact (Compiler) | Masterchain support is not enabled for this contract +## Table of exit codes {#table} + +The following table lists exit codes with an origin (where it can occur) and a short description for each. + +The table doesn't list the exit code of the [`require()`](/ref/core-debug#require), as it generates it depending on the concrete `error` message [String][p]. + +Exit code | Origin | Brief description +:------------ | :---------------------------------- | :---------------- +[$0$](#0) | [Compute][c] and [action][a] phases | Standard successful execution exit code. +[$1$](#1) | [Compute phase][c] | Alternative successful execution exit code. Reserved, but doesn't occur. +[$2$](#2) | [Compute phase][c] | Stack underflow. +[$3$](#3) | [Compute phase][c] | Stack overflow. +[$4$](#4) | [Compute phase][c] | Integer overflow. +[$5$](#5) | [Compute phase][c] | Range check error β€” some integer is out of its expected range. +[$6$](#6) | [Compute phase][c] | Invalid [TVM][tvm] opcode. +[$7$](#7) | [Compute phase][c] | Type check error. +[$8$](#8) | [Compute phase][c] | Cell overflow. +[$9$](#9) | [Compute phase][c] | Cell underflow. +[$10$](#10) | [Compute phase][c] | Dictionary error. +[$11$](#11) | [Compute phase][c] | Described in [TVM][tvm] docs as "Unknown error, may be thrown by user programs". +[$12$](#12) | [Compute phase][c] | Fatal error. Thrown by [TVM][tvm] in situations deemed impossible. +[$13$](#13) | [Compute phase][c] | Out of gas error. +[$-14$](#-14) | [Compute phase][c] | Same as $13$. Negative, so that it [cannot be faked](#13). +[$14$](#14) | [Compute phase][c] | VM virtualization error. Reserved, but never thrown. +[$32$](#32) | [Action phase][a] | Action list is invalid. +[$33$](#33) | [Action phase][a] | Action list is too long. +[$34$](#34) | [Action phase][a] | Action is invalid or not supported. +[$35$](#35) | [Action phase][a] | Invalid source address in outbound message. +[$36$](#36) | [Action phase][a] | Invalid destination address in outbound message. +[$37$](#37) | [Action phase][a] | Not enough Toncoin. +[$38$](#38) | [Action phase][a] | Not enough extra currencies. +[$39$](#39) | [Action phase][a] | Outbound message does not fit into a cell after rewriting. +[$40$](#40) | [Action phase][a] | Cannot process a message β€” not enough funds, the message is too large or its Merkle depth is too big. +[$41$](#41) | [Action phase][a] | Library reference is null during library change action. +[$42$](#42) | [Action phase][a] | Library change action error β€” error during an attempt of the library change action. +[$43$](#43) | [Action phase][a] | Exceeded maximum number of cells in the library or the maximum depth of the Merkle tree. +[$50$](#50) | [Action phase][a] | Account state size exceeded limits. +[$128$](#128) | Tact compiler ([Compute phase][c]) | Null reference exception. +[$129$](#129) | Tact compiler ([Compute phase][c]) | Invalid serialization prefix. +[$130$](#130) | Tact compiler ([Compute phase][c]) | Invalid incoming message β€” there's no receiver for the opcode of the received message. +[$131$](#131) | Tact compiler ([Compute phase][c]) | Constraints error. Reserved, but never thrown. +[$132$](#132) | Tact compiler ([Compute phase][c]) | Access denied β€” someone other than the owner sent a message to the contract. +[$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. + +:::note + + Often enough you might encounter the exit code $65535$ (or `0xffff`), which usually means the same as the [exit code 130](#130) β€” the received opcode is unknown to the contract as there were no receivers expecting it. When writing contracts, the exit code $65535$ is set by the developers and not by [TVM][tvm]or the Tact compiler. + +::: [c]: https://docs.ton.org/learn/tvm-instructions/tvm-overview#compute-phase [a]: https://docs.ton.org/learn/tvm-instructions/tvm-overview#transactions-and-phases -Q: **Where to observe the list of all auto-generated exit codes in your project?**\ -A: The Tact Compiler collects all exit codes at the end of a *.md file and you can track them in the directory along -the path "./ProjectFolder/build/ProjectName/tact_ProjectName.md" +## Exit codes in Blueprint projects {#blueprint} -Q: **How to observe a thrown exit code?**\ -A: In Tact, it's not wise to print the transactions to see the results because they are not easy to read. If you want to see the exit code of a transaction, -use the below template in your Typescript local tests: +In [Blueprint][bp] tests, exit codes from the [compute phase](#compute) are specified in the `exitCode` field of the object argument for `toHaveTransaction(){:typescript}` method of `expect(){:typescript}` matcher. The field for the [result](#action) codes (exit codes from the [action phase](#action)) in the same `toHaveTransaction(){:typescript}` method is called `actionResultCode`. -```typescript -const sender = await blockchain.treasury('sender'); -const result = await contractName.send(sender.getSender(), { value: toNano('0.05'), }, { transactionData }); +:::note + + Read more about expecting specific exit codes: [Transactions with intentional errors](/book/debug#tests-errors). + +::: + +Additionally, one can take a look at the result of [sending a message to a contract](/book/debug#tests-send) and discover the phases of each transaction and their values, including exit (or result) codes for [compute phase](#compute) (or [action phase](#action)). -expect(result.transactions).toHaveTransaction( - { from: sender.address, to: contractName.address, exitCode: YOUR_DESIRED_EXIT_CODE } -); +Note, that in order to do so, you'll have to do a couple of type checks before that: + +```typescript +it('tests something, you name it', async () => { + // Send a specific message to our contract and store the results + const res = await your_contract_name.send(…); + + // Now, we have an access to array of executed transactions, + // with the second one (index 1) being the one that we look for + const tx = res.transactions[1]!; + + // To do something useful with it, let's ensure that it's type is 'generic' + // and that the compute phase in it wasn't skipped + if (tx.description.type === "generic" + && tx.description.computePhase.type === "vm") { + // Finally, we're able to freely peek into the transaction for general details, + // such as printing out the exit code of the compute phase if we so desire + console.log(tx.description.computePhase.exitCode); + } + + // ... +}); ``` -* First line defines the sender. -* Second line sends the transaction. -* In the third line, you check if the result has a transaction from sender to your contract with your desired exit code. -## Compute phase +## Compute and action phases + +### 0: Normal termination {#0} + +This exit (or [result](#action)) code indicates a successful completion of the [compute](#compute) (or [action](#action)) phase of the transaction. + +## Compute phase {#compute} + +[TVM][tvm] initialization and all computations occur in the [compute phase][c]. -### $0$: Successful execution {#0} +If the compute phase fails (the resulting exit code isn't [$0$](#0) or [$1$](#1)), the transaction skips the [action phase](#action) and goes to the bounce phase. In it, the bounce message is formed for the transactions initiated by the inbound message. -This exit code means that the Compute phase of the transaction was completed successfully. +### 1: Alternative termination {#1} -### $4$: Integer overflow {#4} +This is an alternative exit code for the successful execution of the [compute phase](#compute). Reserved, but never occurs. -In TVM, integer can be in the range -2256 < x < 2256. -If the value during the calculation went beyond this range, then 4 exit code is thrown. +### 2: Stack underflow {#2} -Example: +If some operation consumed more elements than there were on the stacks, the error with exit code $2$ is thrown: `Stack underflow`. ```tact -self.id = 1; // force not to ignore it by using storage variables -repeat(256) { - self.id = 2 * self.id; +asm fun drop() { DROP } + +contract Loot { + receive("I solemnly swear that I'm up to no good") { + try { + // Removes 100 elements from the stack, causing an underflow + repeat (100) { drop() } + } catch (exitCode) { + // exitCode is 2 + } + } } ``` -### $5$: Integer out of expected range {#5} +:::note[Useful links:] + + [TVM is a stack machine](https://docs.ton.org/learn/tvm-instructions/tvm-overview#tvm-is-a-stack-machine) in TON Docs. + +::: -If the integer value went beyond the expected range, then 5 exit code is thrown. -For example, if a negative value was used in the .store_uint() function. In Tact, there are some other new situations such as:\ -1- As you know, you can define more limited integers in Tact (integers with less than 257 bits). -If you try to store a number in this kind of integers and the number doesn't fit to this limited range, you will face this exit code.\ -2- according to ```storeUint(self: Builder, value: Int, bits: Int)``` function, it's not possible to use ```storeUint(0, 257)``` because ```0 ≀ bits ≀ 256```. +### 3: Stack overflow {#3} -Example: +If there are too many elements copied into a closure continuation or stored on the stack, an error with exit code $3$ is thrown: `Stack overflow`. Occurs rarely, unless you're deep in [Fift and TVM assembly](https://docs.ton.org/develop/fift/fift-and-tvm-assembly) trenches: ```tact -// option 1 -> id: Int as uint32 -self.id = 1; // force not to ignore it by using storage variables -repeat(32) { - self.id = 2 * self.id; +// Remember kids, don't try to overflow the stack at home! +asm fun stackOverflow() { + <{ + }>CONT // c + 0 SETNUMARGS // c' + 2 PUSHINT // c' 2 + SWAP // 2 c' + 1 -1 SETCONTARGS // <- this blows up } -// option 2 -> according to storeUint(self: Builder, value: Int, bits: Int) function, it's not possible to use storeUint(0, 1024) because 0 ≀ bits ≀ 256 -let s: Slice = beginCell().storeUint(0, 257).asSlice(); +contract ItsSoOver { + receive("I solemnly swear that I'm up to no good") { + try { + stackOverflow(); + } catch (exitCode) { + // exitCode is 3 + } + } +} ``` -### $8$: Cell overflow {#8} -A cell has the capacity to store 1023 bits of data and 4 references to other cells. -If you try to write more than 1023 bits or more than 4 references, 8 exit code is thrown. +:::note[Useful links:] -Example: + [TVM is a stack machine](https://docs.ton.org/learn/tvm-instructions/tvm-overview#tvm-is-a-stack-machine) in TON Docs. + +::: + +### 4: Integer overflow {#4} + +If the value in calculation goes beyond the range from $-2^{256}$ to $2^{256} - 1$ inclusive, or there's an attempt to [divide](/book/operators#binary-divide) or [modulo](/book/operators#binary-modulo) by zero, an error with exit code $4$ is thrown: `Integer overflow`. ```tact -// according to storeUint(self: Builder, value: Int, bits: Int) function, it's not possible to use storeUint(0, 1024) because 0 ≀ bits ≀ 256 -let s: Slice = beginCell().storeUint(0, 256).storeUint(0, 256).storeUint(0, 256).storeUint(0, 256).asSlice(); +let x = -pow(2, 255) - pow(2, 255); // -2^{256} + +try { + -x; // integer overflow by negation + // since the max positive value is 2^{256} - 1 +} catch (exitCode) { + // exitCode is 4 +} + +try { + x / 0; // division by zero! +} catch (exitCode) { + // exitCode is 4 +} + +try { + x * x * x; // integer overflow! +} catch (exitCode) { + // exitCode is 4 +} + +// There can also be an integer overflow when doing: +// addition (+), +// subtraction (-), +// division (/) by a negative number or modulo (%) by zero ``` -### $9$: Cell underflow {#9} +### 5: Integer out of range {#5} -If you try to read more data from a slice than it contains, then 9 exit code is thrown. +Range check error β€” some integer is out of its expected range. I.e. any attempt to store an unexpected amount of data or specify an out-of-bounds value throws an error with exit code $5$: `Integer out of range`. -Example: +Examples of specifying an out-of-bounds value: ```tact -let s: Slice = emptySlice(); -self.id = s.loadUint(1); // force not to ignore it by using storage variables +try { + // Repeat only operates on inclusive range from 1 to 2^{31} - 1 + // and any valid integer value greater than that causes an error with exit code 5 + repeat (pow(2, 55)) { + dump("smash. logs. I. must."); + } +} catch (exitCode) { + // exitCode is 5 +} + +try { + // Builder.storeUint() function can only use up to 256 bits, so 512 is too much: + let s: Slice = beginCell().storeUint(-1, 512).asSlice(); +} catch (exitCode) { + // exitCode is 5 +} ``` -### $13$: Out of gas error {#13} +### 6: Invalid opcode {#6} -If there isn't enough TON to handle compute phase, this error is thrown. +If you specify an instruction that is not defined in the current [TVM][tvm] version, an error with exit code $6$ is thrown: `Invalid opcode`. -During processing, the NOT operation is applied to this value, which changes this value to -14. This is done so that this exit code cannot be faked using the throw function, since all such functions accept only positive values for the exit code as it was discussed previously. +```tact +// No such thing +asm fun invalidOpcode() { x{D7FF} @addop } + +contract OpOp { + receive("I solemnly swear that I'm up to no good") { + try { + invalidOpcode(); + } catch (exitCode) { + // exitCode is 6 + } + } +} +``` -Example: +### 7: Type check error {#7} + +If an argument to a primitive is of an incorrect value type or there's any other mismatch in types during the [compute phase](#compute), an error with exit code $7$ is thrown: `Type check error`. ```tact -repeat(10000) { - self.id += 1; +// The actual returned value type doesn't match the declared one +asm fun typeCheckError(): map { 42 PUSHINT } + +contract VibeCheck { + receive("I solemnly swear that I'm up to no good") { + try { + // The 0th index doesn't exist + typeCheckError().get(0)!!; + } catch (exitCode) { + // exitCode is 7 + } + } } ``` -## Action phase +### 8: Cell overflow {#8} + +From [Cells, Builders and Slices page](/book/cells#cells) of the Book: -### $34$: Action is invalid or not supported {#34} +> [`Cell{:tact}`][cell] is a [primitive][p] and a data structure, which [ordinarly](/book/cells#cells-kinds) consists of up to $1023$ continuously laid out bits and up to $4$ references (refs) to other cells. -This exit code is responsible for most of the errors when working with actions: invalid message, incorrect action, and so on. +To construct a [`Cell{:tact}`][cell], a [`Builder{:tact}`][builder] is used. If you try to store more than $1023$ bits of data or more than $4$ references to other cells, an error with exit code $8$ is thrown: `Cell overflow`. -Example: +This error can be triggered by [manual construction](/book/cells#cnp-manually) of the cells via [relevant `.loadSomething()` methods](/ref/core-cells) or when [using Structs and Messages and their convenience methods](/book/cells#cnp-structs). ```tact -nativeSendMessage(emptyCell(), 0); +// Too much bits +try { + let data = beginCell() + .storeInt(0, 250) + .storeInt(0, 250) + .storeInt(0, 250) + .storeInt(0, 250) + .storeInt(0, 24) // 1024 bits! + .endCell(); +} catch (exitCode) { + // exitCode is 8 +} + +// Too much refs +try { + let data = beginCell() + .storeRef(emptyCell()) + .storeRef(emptyCell()) + .storeRef(emptyCell()) + .storeRef(emptyCell()) + .storeRef(emptyCell()) // 5 refs! + .endCell(); +} catch (exitCode) { + // exitCode is 8 +} ``` -### $37$: Not enough TON {#37} +### 9: Cell underflow {#9} + +From [Cells, Builders and Slices page](/book/cells#cells) of the Book: + +> `Cell{:tact}` is a [primitive][p] and a data structure, which [ordinarly](/book/cells#cells-kinds) consists of up to $1023$ continuously laid out bits and up to $4$ references (refs) to other cells. -It means that there isn't enough TON to send the specified amount of it. +To parse a [`Cell{:tact}`][cell], a [`Slice{:tact}`][slice] is used. If you try to load more data or references than `Slice{:tact}` contains, an error with exit code $9$ is thrown: `Cell underflow`. -Example: +The most common cause of this error is a mismatch between the expected and actual memory layouts of the cells, so it's recommended to [use Structs and Messages for parsing](/book/cells#cnp-structs) of the cells instead of [manual parsing](/book/cells#cnp-manually) via [relevant `.loadSomething()` methods](/ref/core-cells). ```tact -send(SendParameters{to: context().sender, value: ton("10")}); +// Too few bits +try { + emptySlice().loadInt(1); // 0 bits! +} catch (exitCode) { + // exitCode is 9 +} + +// Too few refs +try { + emptySlice().loadRef(); // 0 refs! +} catch (exitCode) { + // exitCode is 9 +} ``` -## Tact (Compiler) +### 10: Dictionary error {#10} -### 128: Null reference exception {#128} +In Tact, the [`map{:tact}`](/book/maps) type is an abstraction over the ["hash" map dictionaries of FunC](https://docs.ton.org/develop/func/dictionaries#hashmap) and underlying [`HashmapE` type](https://docs.ton.org/develop/data-formats/tl-b-types#hashmap) of [TL-B][tlb] and [TVM][tvm]. -If there's a non-null assertion, such as the [`!!{:tact}`](/book/operators#unary-non-null-assert) operator, and the checked value is [`null{:tact}`](/book/optionals), an error with exit code $128$ is thrown: `Null reference exception`. +If there is an incorrect manipulation of dictionaries, such as improper assumptions about their memory layout, an error with exit code $10$ is thrown: `Dictionary error`. Note, that Tact prevents you from getting this error unless you do [Fift and TVM assembly](https://docs.ton.org/develop/fift/fift-and-tvm-assembly) work yourself: ```tact -let gotcha: String? = null; +/// Pre-computed Int to Int dictionary with two entries β€” 0: 0 and 1: 1 +const cellWithDictIntInt: Cell = cell("te6cckEBBAEAUAABAcABAgPQCAIDAEEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMLMbT1U="); + +/// Tries to preload a dictionary from a Slice as a map +asm fun toMapIntCell(x: Slice): map { PLDDICT } + +contract DictPic { + receive("I solemnly swear that I'm up to no good") { + try { + // The Int to Int dictionary is being misinterpreted as a map + let m: map = toMapIntCell(cellWithDictIntInt.beginParse()); + + // And the error happens only when we touch it + m.get(0)!!; + } catch (exitCode) { + // exitCode is 10 + } + } +} +``` + +### 11: "Unknown" error {#11} + +Described in [TVM][tvm] docs as "Unknown error, may be thrown by user programs", although most commonly used for problems with queueing a message send or problems with [get-methods](https://docs.ton.org/develop/smart-contracts/guidelines/get-methods). +```tact try { - // Asserting that the value isn't null, which isn't the case! - dump(gotcha!!); + // Unlike nativeSendMessage which uses SENDRAWMSG, this one uses SENDMSG, + // and therefore fails in Compute phase when the message is ill-formed + nativeSendMessageReturnForwardFee(emptyCell(), 0); } catch (exitCode) { - exitCode; // 128 + // exitCode is 11 } ``` -### $130$: Invalid incoming message {#130} +### 12: Fatal error {#12} -When you send a message to a contract, the first 32 bits of message body is the op code. It determines the operation that must be done. -In FunC, if no op code is found, 0xffff will be thrown. In Tact, 130 exit code will be thrown. +Fatal error. Thrown by TVM in situations deemed impossible. -Example: +### 13: Out of gas error {#13} -1. First, define an empty contract like below: +If there isn't enough gas to end computations in the [compute phase](#compute), the error with exit code $13$ is thrown: `Out of gas error`. + +But this code isn't immediately shown as is β€” instead, the bitwise NOT operation is applied, which changes the value from $13$ to $-14$. And only then the code is shown. + +That's done in order to prevent the resulting code ($-14$) from being produced artificially in user contracts, since all functions that can [throw an exit code](/ref/core-debug) can only specify integers in the range from $0$ to $65535$ inclusive. ```tact -contract Fireworks {} +try { + repeat (pow(2, 31) - 1) {} +} catch (exitCode) { + // exitCode is -14 +} ``` -2. Then, send a message to this contract. Because no suitable operation is found, you will get this exit code. +### -14: Out of gas error {#-14} -### $132$: Access denied {#132} +See [exit code 13](#13). -First, you should import and inherit from Ownable Trait. After it, your contract will have an owner. -You can ask for a check by calling ```self.requireOwner();``` in your functions. It will ensure that only the owner can send message to your contract. +### 14: Virtualization error {#14} -Example: +Virtualization error, related to [prunned branch cells](/book/cells#cells-kinds). Reserved, but never thrown. -```tact -import "@stdlib/deploy"; -import "@stdlib/ownable"; +## Action phase {#action} -message FakeLaunch { +The [action phase][a] is processed after the successful execution of the [compute phase](#compute). It attempts to perform the actions stored into the action list by [TVM][tvm] during the compute phase. -} +Some actions may fail during processing, in which case those actions may be skipped or the whole transaction may revert depending on the mode of actions. The code indicating the resulting state of the [action phase][a] is called a _result code_. Since it's also a $32$-bit signed integer that essentially serves the same purpose as _exit code_ of [compute phase](#compute), it's common to call the result code an exit code too. -contract Fireworks with - Deployable, - Ownable, -{ - owner: Address; +### 32: Action list is invalid {#32} - init(){ - self.owner = sender(); - } +If the list of actions contains [exotic cells](/book/cells#cells-kinds), an action entry cell does not have references or some action entry cell couldn't be parsed, an error with exit code $32$ is thrown: `Action list is invalid`. - receive(msg: FakeLaunch){ - self.requireOwner(); - } -} +:::note + + Aside from this exit code there's a boolean flag `valid`, which you can find under `description.actionPhase.valid` in the transaction results when working with [Sandbox and Blueprint](#blueprint). Transaction can set this flag to `false` even when there is some other exit code thrown from the action phase. -fun requireOwner() { - nativeThrowUnless(132, sender() == self.owner); +::: + +### 33: Action list is too long {#33} + +If there are more than $255$ actions queued for execution, the [action phase](#action) will throw an error with an exit code $33$: `Action list is too long`. + +```tact +// For example, let's attempt to queue reservation of specific amount of nanoToncoins +// This won't fail in compute phase, but will result in exit code 33 in Action phase +repeat (256) { + nativeReserve(ton("0.001"), ReserveAtMost); } ``` -### $133$: Contract stopped {#133} - -The stoppable trait allows to stop the contract. -If you send a message to a stopped contract, and the contract asks for a check by running ```self.requireNotStopped();```, this exit code will be thrown. -In the current version of Tact, 40368 exit code will be thrown instead of 133. +### 34: Invalid or unsupported action {#34} -Example: +There are only four supported actions at the moment: changing the contract code, sending a message, reserving a specific amount of [nanoToncoins](/book/integers#nanotoncoin) and changing the library cell. If there's any issue with the specified action (invalid message, unsupported action, etc.), an error with exit code $34$ is thrown: `Invalid or unsupported action`. ```tact -import "@stdlib/deploy"; -import "@stdlib/ownable"; -import "@stdlib/stoppable"; +// For example, let's try to send an ill-formed message: +nativeSendMessage(emptyCell(), 0); // won't fail in compute phase, + // but will result in exit code 34 in Action phase +``` -message FakeLaunch {} +### 35: Invalid source address in outbound message {#35} -contract Fireworks with - Deployable, - Ownable, - Stoppable, -{ - owner: Address; - stopped: Bool; +If the source address in the outbound message isn't equal to [`addr_none`](https://docs.ton.org/develop/data-formats/msg-tlb#addr_none00) or to the address of the contract that initiated this message, an error with exit code $35$ is thrown: `Invalid source address in outbound message`. - init() { - self.owner = sender(); - self.stopped = false; - } +### 36: Invalid destination address in outbound message {#36} - receive(msg: FakeLaunch) { - self.stopped = true; - self.requireNotStopped(); - } -} +If the destination address in the outbound message is invalid, e.g. it doesn't conform to the relevant [TL-B][tlb] schemas, contains unknown workchain ID or it has invalid length for the given workchain, an error with exit code $36$ is thrown: `Invalid destination address in outbound message`. + +:::note + + If the [optional flag +2](/book/message-mode#optional-flags) is set, this error won't be thrown and the given message won't be sent. + +::: + +### 37: Not enough Toncoin {#37} + +If all funds of the inbound message with [base mode 64](/book/message-mode#base-modes) set had been already consumed and there's not enough funds to pay for the failed action, or the [TL-B][tlb] layout of the provided value ([`CurrencyCollection`](https://docs.ton.org/develop/data-formats/msg-tlb#currencycollection)) is invalid, or there's not enough funds to pay [forward fees](https://docs.ton.org/develop/smart-contracts/guidelines/processing) or not enough funds after deducting fees, an error with exit code $37$ is thrown: `Not enough Toncoin`. + +:::note + + If the [optional flag +2](/book/message-mode#optional-flags) is set, this error won't be thrown and the given message won't be sent. + +::: + +### 38: Not enough extra currencies {#38} + +Besides the native currency, Toncoin, TON Blockchain supports up to $2^{32}$ extra currencies. They differ from making new [Jettons](/cookbook/jettons) because extra currencies are natively supported β€” one can potentially just specify an extra [`HashmapE`](https://docs.ton.org/develop/data-formats/tl-b-types#hashmap) of extra currency amounts in addition to the Toncoin amount in the internal message to another contract. Unlike Jettons, extra currencies can only be stored and transferred and do not have any other functionality. + +At the moment, **there are no extra currencies** on TON Blockchain, but the exit code $38$ in cases when there is not enough extra currency to send the specified amount of it is already reserved: `Not enough extra currencies`. + +:::note[Useful links:] + + [Extra currencies](https://docs.ton.org/develop/dapps/defi/coins) in TON Docs.\ + [Extra currency mining](https://docs.ton.org/develop/research-and-development/minter-flow) in TON Docs. + +::: + +### 39: Outbound message doesn't fit into a cell {#39} + +When processing the message, TON Blockchain tries to pack it according to the [relevant TL-B schemas](https://docs.ton.org/develop/data-formats/msg-tlb), and if it cannot an error with exit code $39$ is thrown: `Outbound message doesn't fit into a cell`. + +:::note + + If attempts at sending the message fail multiple times and the [optional flag +2](/book/message-mode#optional-flags) is set, this error won't be thrown and the given message won't be sent. + +::: + +### 40: Cannot process a message {#40} + +If there would not be enough funds to process all the cells in a message, the message is too large or its Merkle depth is too big, an error with exit code $40$ is thrown: `Cannot process a message`. + +### 41: Library reference is null {#41} + +If the library reference was required during library change action, but it was null, an error with exit code $41$ is thrown: `Library reference is null`. + +### 42: Library change action error {#42} + +If there's an error during an attempt at library change action, an error with exit code $42$ is thrown: `Library change action error`. + +### 43: Library limits exceeded {#43} + +If the maximum number of cells in the library is exceeded or the maximum depth of the Merkle tree is exceeded, an error with exit code $43$ is thrown: `Library limits exceeded`. + +### 50: Account state size exceeded limits {#50} + +If the account state (contract storage, essentially) exceeds any of the limits specified in [config param 43 of TON Blockchain](https://docs.ton.org/develop/howto/blockchain-configs#param-43) by the end of the [action phase](#action), an error with exit code $50$ is thrown: `Account state size exceeded limits`. + +If the configuration is absent, default values are: + +* `max_msg_bits` is equal to $2^{21}$ β€” maximum message size in bits. +* `max_msg_cells` is equal to $2^{13}$ β€” maximum number of [cells][cell] a message can occupy. +* `max_library_cells` is equal to $1000$ β€” maximum number of [cells][cell] that can be used as [library reference cells](/book/cells#cells-kinds). +* `max_vm_data_depth` is equal to $2^{9}$ β€” maximum [cells][cell] depth in messages and account state. +* `ext_msg_limits.max_size` is equal to $65535$ β€” maximum external message size in bits. +* `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). +* `defer_out_queue_size_limit` is equal to $2^{8}$ β€” maximum number of outbound messages to be queued (regards validators and collators). + +## Tact compiler -fun requireNotStopped() { - require(!self.stopped, "Contract stopped"); +Tact utilizes exit codes from $128$ to $255$. Note, that exit codes used by Tact indicate contract errors which can occur when using Tact-generated FunC code, and are therefore thrown in the transaction's [compute phase](#compute) and not during the compilation. + +### 128: Null reference exception {#128} + +If there's a non-null assertion, such as the [`!!{:tact}`](/book/operators#unary-non-null-assert) operator, and the checked value is [`null{:tact}`](/book/optionals), an error with exit code $128$ is thrown: `Null reference exception`. + +```tact +let gotcha: String? = null; + +try { + // Asserting that the value isn't null, which isn't the case! + dump(gotcha!!); +} catch (exitCode) { + // exitCode is 128 } ``` -### $134$: Invalid argument {#134} +### 129: Invalid serialization prefix {#129} + +Reserved, but due to a number of prior checks it cannot be thrown unless one hijacks the contract code before deployment and changes the opcodes of the [Messages][message] expected to be received in the contract. -This will be thrown by the below FunC function(in the last part of a bunch of if conditions). This function reads something from Base64. +### 130: Invalid incoming message {#130} -If the input characters don't fit into base64 chars, you will encounter this exit code. +If the received internal or external message isn't handled by the contract, an error with exit code $130$ is thrown: `Invalid incoming message`. It usually happens when the contract doesn't have a receiver for the particular message and its opcode prefix (32-bit integer header). -Example: +Consider the following contract: ```tact -let code: Slice = beginCell().storeUint(0, 8).asSlice().fromBase64(); -// 0 is not a valid ASCII code so it cannot be converted to Base64 +import "@stdlib/deploy"; + +contract Dummy with Deployable {} ``` -### $135$: Code of a contract was not found {#135} +If you try to send any message, except for [`Deploy{:tact}`](/ref/stdlib-deploy#deploy) provided by [`@stdlib/deploy`](/ref/stdlib-deploy), the contract won't have a receiver for it and thus would throw an error with exit code $130$. + +### 131: Constraints error {#131} -It will check the return flag of a search on the dictionary keys. +Constraints error. Reserved, but never thrown. -Example: +### 132: Access denied {#132} + +If you use the [`Ownable{:tact}`](/ref/stdlib-ownable#ownable) [trait][ct] from the [`@stdlib/ownable`](/ref/stdlib-ownable) library, the helper function `requireOwner(){:tact}` provided by it will throw an error with exit code $132$ if the sender of the inbound message won't match the specified owner: `Access denied`. ```tact -// copy & paste the below line in wrapper file(../build/ContractName/tact_ContractName.ts) instead of the second line of ContractName_init() function - this is a dictionary containing another smart contract code which leads to 135 exit code -// const __system = Cell.fromBase64('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'); -let ctx: Context = context(); -let fireworks_init: StateInit = initOf Fireworks(0); +import "@stdlib/ownable"; + +contract Hal9k with Ownable { + owner: Address; + + init(owner: Address) { + self.owner = owner; // set the owner address upon deployment + } + + receive("I'm sorry Dave, I'm afraid I can't do that.") { + // Checks that the message sender's address equals to the owner address, + // and if not β€” throws an error with exit code 132. + self.requireOwner(); + + // ... you do you ... + } +} ``` -### $136$: Invalid address {#136} +### 133: Contract stopped {#133} + +A message has been sent to a stopped contract. Reserved, but never thrown. -In TON, all addresses are 267 bits. If you violate this rule, you will face this exit code. +### 134: Invalid argument {#134} -Currently, TON only supports two chain id. 0 for basechain and -1 for masterchain. If you address isn't from basechain, 136 exit code will be thrown. +If there is an invalid or unexpected argument value, an error with exit code $134$ is thrown: `Invalid argument`. -Example: +Here are some of the functions in Tact which can throw an error with this exit code: + +1. [`Int.toFloatString(digits){:tact}`](/ref/core-strings#inttofloatstring): if the `digits` is not in the interval: $0 <$ `digits` $< 78$. + +2. [`String.fromBase64(){:tact}`](/ref/core-strings#stringfrombase64) and [`Slice.fromBase64(){:tact}`](/ref/core-strings#slicefrombase64): if the given [`String{:tact}`][p] or [`Slice{:tact}`][slice] contains non-Base64 characters. ```tact -// fun newAddress(chain: Int, hash: Int): Address; -// creates a new address from chain and hash values. -let zeroAddress: Address = newAddress(1, 0); // invalid chain zero address +try { + // 0 is code of NUL in ASCII and it is not valid Base64 + let code: Slice = beginCell().storeUint(0, 8).asSlice().fromBase64(); +} catch (exitCode) { + // exitCode is 134 +} ``` -### $137$: Masterchain support is not enabled for this contract {#137} +### 135: Code of a contract was not found {#135} + +If the code of the contract doesn't match the one saved in TypeScript wrappers, the error with exit code $135$ will be thrown: `Code of a contract was not found`. + +### 136: Invalid address {#136} + +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. -Currently, TON only supports two chain id. 0 for basechain and -1 for masterchain. +If the [`Address{:tact}`][p] isn't valid, the error with exit code $136$ will be thrown: `Invalid address`. -Tact only supports basechain and if you address is from masterchain, 137 exit code will be thrown. +```tact +// Only basechain (ID 0) or masterchain (ID -1) are supported by Tact +let unsupportedChainID = 1; + +try { + // Zero address in unsupported workchain + dump(newAddress(unsupportedChainID, 0)); +} catch (exitCode) { + // exitCode is 136 +} +``` -Example: +### 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`. ```tact -// fun newAddress(chain: Int, hash: Int): Address; -// creates a new address from chain and hash values. -let zeroAddress: Address = newAddress(-1, 0); // masterchain zero address +let masterchainID = -1; + +try { + // Zero address in masterchain without the config option set + dump(newAddress(masterchainID, 0)); +} catch (exitCode) { + // exitCode is 137 +} ``` + +[p]: /book/types#primitive-types +[ct]: /book/types#composite-types +[cell]: /book/cells +[builder]: /book/cells#builders +[slice]: /book/cells#slices +[message]: /book/structs-and-messages#messages + +[tlb]: https://docs.ton.org/develop/data-formats/tl-b-language +[tvm]: https://docs.ton.org/develop/func/statements#function-application +[bp]: https://github.com/ton-org/blueprint +[sb]: https://github.com/ton-org/sandbox +[jest]: https://jestjs.io diff --git a/src/generator/createABI.ts b/src/generator/createABI.ts index 503edfa1c..4aa7b4ff8 100644 --- a/src/generator/createABI.ts +++ b/src/generator/createABI.ts @@ -158,8 +158,8 @@ export function createABI(ctx: CompilerContext, name: string): ContractABI { errors["36"] = { message: "Invalid destination address in outbound message", }; - errors["37"] = { message: "Not enough TON" }; - errors["38"] = { message: "Not enough extra-currencies" }; + errors["37"] = { message: "Not enough Toncoin" }; + errors["38"] = { message: "Not enough extra currencies" }; errors["39"] = { message: "Outbound message does not fit into a cell after rewriting", }; diff --git a/src/test/e2e-emulated/__snapshots__/local-type-inference.spec.ts.snap b/src/test/e2e-emulated/__snapshots__/local-type-inference.spec.ts.snap index 33a4b617f..5573c4ad8 100644 --- a/src/test/e2e-emulated/__snapshots__/local-type-inference.spec.ts.snap +++ b/src/test/e2e-emulated/__snapshots__/local-type-inference.spec.ts.snap @@ -70,10 +70,10 @@ exports[`local-type-inference should automatically set types for let statements "message": "Invalid destination address in outbound message", }, "37": { - "message": "Not enough TON", + "message": "Not enough Toncoin", }, "38": { - "message": "Not enough extra-currencies", + "message": "Not enough extra currencies", }, "39": { "message": "Outbound message does not fit into a cell after rewriting", diff --git a/src/test/exit-codes/contracts/compute-phase-errors.tact b/src/test/exit-codes/contracts/compute-phase-errors.tact index e27f8395c..aa9e68463 100644 --- a/src/test/exit-codes/contracts/compute-phase-errors.tact +++ b/src/test/exit-codes/contracts/compute-phase-errors.tact @@ -204,7 +204,7 @@ contract ComputePhaseErrorsTester { /// Exit code 11 receive("11") { // Unlike nativeSendMessage which uses SENDRAWMSG, this one uses SENDMSG, - // and therefore fails in Compute time when the message is ill-formed + // and therefore fails in Compute phase when the message is ill-formed nativeSendMessageReturnForwardFee(emptyCell(), 0); }