From dec5b65ed5de6c9e660af2b444e4ddd7a58b5d18 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 17 Nov 2025 16:55:24 +0300 Subject: [PATCH 1/5] Initial --- tvm/gas.mdx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tvm/gas.mdx b/tvm/gas.mdx index 2feb96ee4..9d4f8fb80 100644 --- a/tvm/gas.mdx +++ b/tvm/gas.mdx @@ -140,3 +140,15 @@ Instructions [`BLS_G2_ZERO`](/tvm/instructions#f93025-bls_g2_zero) and [`BLS_G2_ | [`BLS_PAIRING`](/tvm/instructions#f93030-bls_pairing) | `20000 + 11800 * n` | `n` is the number of `(G1, G2)` pairs supplied for the pairing product check. | [`BLS_PUSHR`](/tvm/instructions#f93031-bls_pushr) do not charge additional gas. + + +## `GasLimits` structure + +TVM has inner structure `GasLimits` for gas manipulations. Its fields are: +- `gas_max`: the equivalent of the contract balance in gas. +- `gas_limit`: the amount of gas that can be consumed during the virtual machine execution. At the start of the execution, it equals: + - minimum of `gas_max` and the amount of gas that can be bought with the incoming message value (i.e., the amount of TON coins attached to the message) in the case of an internal message; + - `0` in the case of an external message. +- `gas_credit`: the amount of free gas that can be spent during the execution before accepting an external message. At the start of the execution, it equals: + - minimum of `gas_max` and corresponding value in configuration parameter `20` for masterchain and `21` for basechain in the case of an external message; + - `0` in the case of an internal message. \ No newline at end of file From 1e4c7759237833fc7cf766c54b5edde4fd018a78 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 17 Nov 2025 19:24:45 +0300 Subject: [PATCH 2/5] continue --- tvm/gas.mdx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tvm/gas.mdx b/tvm/gas.mdx index 9d4f8fb80..7ab3ad0ab 100644 --- a/tvm/gas.mdx +++ b/tvm/gas.mdx @@ -145,10 +145,18 @@ Instructions [`BLS_G2_ZERO`](/tvm/instructions#f93025-bls_g2_zero) and [`BLS_G2_ ## `GasLimits` structure TVM has inner structure `GasLimits` for gas manipulations. Its fields are: -- `gas_max`: the equivalent of the contract balance in gas. +- `gas_max`: the equivalent of the contract balance in gas units. - `gas_limit`: the amount of gas that can be consumed during the virtual machine execution. At the start of the execution, it equals: - minimum of `gas_max` and the amount of gas that can be bought with the incoming message value (i.e., the amount of TON coins attached to the message) in the case of an internal message; - `0` in the case of an external message. - `gas_credit`: the amount of free gas that can be spent during the execution before accepting an external message. At the start of the execution, it equals: - minimum of `gas_max` and corresponding value in configuration parameter `20` for masterchain and `21` for basechain in the case of an external message; - - `0` in the case of an internal message. \ No newline at end of file + - `0` in the case of an internal message. +- `gas_remaining`: the amount of available but not spent gas. At the start of the execution, it equals `gas_limit + gas_credit`. It decreases after each instruction execution by the amount of gas consumed by the instruction. +- `gas_base`: an auxiliary parameter that is necessary for rebasing and shows the initial value of `gas_remaining`. At the start of the execution, it equals `gas_remaining`. + +Instructions `SETGASLIMIT` and `ACCEPT` change all above values except `gas_max`: +- `SETGASLIMIT` sets `gas_limit` to the minimum of the indicated value and `gas_max`, `gas_credit` to zero, `gas_base` to the new `gas_limit`, and `gas_remaining` to `gas_remaining + (new gas_base - old gas_base)`. +- `ACCEPT` is equivalent to `SETGASLIMIT` with the new gas limit equal to `2**63 - 1` (the maximum value of a signed 64-bits integer). + +The final value (in gas units) that will be deducted from contract's balance after the execution is `gas_base - gas_remaining`. Note that this value will be deducted if and only if after the execution `gas_credit` is zero, i.e. `SETGASLIMIT` or `ACCEPT` was called at least once during the execution. Without condition `gas_credit == 0`, there will be no commit of the new code and data. \ No newline at end of file From dda05d9e5c233c1f95f981cccd3b5e429504f7ca Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 17 Nov 2025 20:38:35 +0300 Subject: [PATCH 3/5] formatting --- tvm/gas.mdx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tvm/gas.mdx b/tvm/gas.mdx index 7ab3ad0ab..c8d6a9efb 100644 --- a/tvm/gas.mdx +++ b/tvm/gas.mdx @@ -141,10 +141,10 @@ Instructions [`BLS_G2_ZERO`](/tvm/instructions#f93025-bls_g2_zero) and [`BLS_G2_ [`BLS_PUSHR`](/tvm/instructions#f93031-bls_pushr) do not charge additional gas. - ## `GasLimits` structure TVM has inner structure `GasLimits` for gas manipulations. Its fields are: + - `gas_max`: the equivalent of the contract balance in gas units. - `gas_limit`: the amount of gas that can be consumed during the virtual machine execution. At the start of the execution, it equals: - minimum of `gas_max` and the amount of gas that can be bought with the incoming message value (i.e., the amount of TON coins attached to the message) in the case of an internal message; @@ -152,11 +152,12 @@ TVM has inner structure `GasLimits` for gas manipulations. Its fields are: - `gas_credit`: the amount of free gas that can be spent during the execution before accepting an external message. At the start of the execution, it equals: - minimum of `gas_max` and corresponding value in configuration parameter `20` for masterchain and `21` for basechain in the case of an external message; - `0` in the case of an internal message. -- `gas_remaining`: the amount of available but not spent gas. At the start of the execution, it equals `gas_limit + gas_credit`. It decreases after each instruction execution by the amount of gas consumed by the instruction. +- `gas_remaining`: the amount of available but not spent gas. At the start of the execution, it equals `gas_limit + gas_credit`. It decreases after each instruction execution by the amount of gas consumed by the instruction. - `gas_base`: an auxiliary parameter that is necessary for rebasing and shows the initial value of `gas_remaining`. At the start of the execution, it equals `gas_remaining`. Instructions `SETGASLIMIT` and `ACCEPT` change all above values except `gas_max`: + - `SETGASLIMIT` sets `gas_limit` to the minimum of the indicated value and `gas_max`, `gas_credit` to zero, `gas_base` to the new `gas_limit`, and `gas_remaining` to `gas_remaining + (new gas_base - old gas_base)`. - `ACCEPT` is equivalent to `SETGASLIMIT` with the new gas limit equal to `2**63 - 1` (the maximum value of a signed 64-bits integer). -The final value (in gas units) that will be deducted from contract's balance after the execution is `gas_base - gas_remaining`. Note that this value will be deducted if and only if after the execution `gas_credit` is zero, i.e. `SETGASLIMIT` or `ACCEPT` was called at least once during the execution. Without condition `gas_credit == 0`, there will be no commit of the new code and data. \ No newline at end of file +The final value (in gas units) that will be deducted from contract's balance after the execution is `gas_base - gas_remaining`. Note that this value will be deducted if and only if after the execution `gas_credit` is zero, i.e. `SETGASLIMIT` or `ACCEPT` was called at least once during the execution. Without condition `gas_credit == 0`, there will be no commit of the new code and data. From 0747ba6c406d52ec8c26c77b4b20f7379652cefd Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 17 Nov 2025 20:39:27 +0300 Subject: [PATCH 4/5] Small add --- tvm/gas.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tvm/gas.mdx b/tvm/gas.mdx index c8d6a9efb..4966233b0 100644 --- a/tvm/gas.mdx +++ b/tvm/gas.mdx @@ -160,4 +160,4 @@ Instructions `SETGASLIMIT` and `ACCEPT` change all above values except `gas_max` - `SETGASLIMIT` sets `gas_limit` to the minimum of the indicated value and `gas_max`, `gas_credit` to zero, `gas_base` to the new `gas_limit`, and `gas_remaining` to `gas_remaining + (new gas_base - old gas_base)`. - `ACCEPT` is equivalent to `SETGASLIMIT` with the new gas limit equal to `2**63 - 1` (the maximum value of a signed 64-bits integer). -The final value (in gas units) that will be deducted from contract's balance after the execution is `gas_base - gas_remaining`. Note that this value will be deducted if and only if after the execution `gas_credit` is zero, i.e. `SETGASLIMIT` or `ACCEPT` was called at least once during the execution. Without condition `gas_credit == 0`, there will be no commit of the new code and data. +The final value (in gas units) that will be deducted from contract's balance after the execution is `gas_base - gas_remaining`. Note that this value will be deducted if and only if after the execution `gas_credit` is zero, i.e. if `SETGASLIMIT` or `ACCEPT` was called at least once during the execution in the case of incoming external message. Without condition `gas_credit == 0`, there will be no commit of the new code and data. From fd5212dba45fe1c6d21c2232247fc1046ecbc6d5 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 17 Nov 2025 23:03:21 +0300 Subject: [PATCH 5/5] Impro --- tvm/gas.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tvm/gas.mdx b/tvm/gas.mdx index 4966233b0..c3a591598 100644 --- a/tvm/gas.mdx +++ b/tvm/gas.mdx @@ -145,7 +145,7 @@ Instructions [`BLS_G2_ZERO`](/tvm/instructions#f93025-bls_g2_zero) and [`BLS_G2_ TVM has inner structure `GasLimits` for gas manipulations. Its fields are: -- `gas_max`: the equivalent of the contract balance in gas units. +- `gas_max`: the equivalent of contract's balance at the start of the compute phase in gas units. - `gas_limit`: the amount of gas that can be consumed during the virtual machine execution. At the start of the execution, it equals: - minimum of `gas_max` and the amount of gas that can be bought with the incoming message value (i.e., the amount of TON coins attached to the message) in the case of an internal message; - `0` in the case of an external message.