Skip to content

Commit eceaef8

Browse files
Update functions.md
1 parent cbe081a commit eceaef8

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

docs/v3/documentation/smart-contracts/func/docs/functions.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,45 @@ When a function is marked with the `inline_ref` specifier, its code is stored in
301301

302302
#### method_id
303303

304-
In a TVM program, every function has an internal integer ID that determines how it can be called. By default, ordinary functions are assigned sequential numbers starting from `1`, while contract get-methods use `crc16` hashes of their names.
305-
The `method_id(<some_number>)` specifier allows you to set a function’s ID to a specific value manually. If no ID is specified, the default is calculated as `(crc16(<function_name>) & 0xffff) | 0x10000`. If a function has the `method_id` specifier, it can be invoked by its name as a get-method in lite client or TON explorer.
304+
In a TVM program, every function has an internal integer ID that determines how it can be called.
305+
By default, ordinary functions are assigned sequential numbers starting from `1`, while contract get-methods use `crc16` hashes of their names.
306+
The `method_id(<some_number>)` specifier allows you to set a function's ID to a specific value manually.
307+
If no ID is specified, the default is calculated as `(crc16(<function_name>) & 0xffff) | 0x10000`.
308+
If a function has the `method_id` specifier, it can be invoked by its name as a get-method in lite client or TON explorer.
309+
310+
:::info
311+
There is a catch if you try to define specific ID manually:
312+
- It should not exceed `0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff`
313+
- Due to a lazy check in types it can accept up to `0x6ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff` and succesfully compile
314+
- In TVM it is still a 257-bit unsigned variable, so it should be defined in range
315+
:::
316+
317+
<details>
318+
<summary><b>AnyIntView&lt;Tr&gt;::parse_hex_any</b></summary>
319+
320+
This function (`crypto/common/bigint.hpp`) is responsible for parsing the hexadecimal string.
321+
322+
It first performs a basic check on the length of the hex string:
323+
```cpp
324+
if ((j - i - (p > 0)) * 4 > (max_size() - 1) * word_shift + word_bits - 2) {
325+
return 0; // Invalid if too long
326+
}
327+
```
328+
329+
For `BigInt<257>`, `Tr` is `BigIntInfo`, `word_bits` is 64, `word_shift` is 62.
330+
331+
The `max_size()` for `BigInt<257>` is `257 / 62 + 1 = 4 + 1 = 5` "words".
332+
333+
Let's plug in the values:
334+
`(5 - 1) * 62 + 64 - 2 = 4 * 62 + 62 = 248 + 62 = 310` bits.
335+
336+
A 65-character hex string represents \( 65 times 4 = 260 \) bits.
337+
So, `260 < 310 - 2`. Such a number (65 hex digits) can *pass* this initial length check. This check is designed to quickly reject inputs that are grossly too large. The `-2` is a slight margin.
338+
339+
After basic parsing into internal `digits_`, it calls `normalize_bool_any()`.
340+
341+
If `normalize_bool_any()` returns `false`, `parse_hex_any` will invalidate the `BigInt` and return `0`, indicating a parsing failure. This leads to `td::string_to_int256` returning a `null` `RefInt256`.
342+
</details>
306343

307344
**Example**
308345
```func

0 commit comments

Comments
 (0)