You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tvm/gas.mdx
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -140,3 +140,24 @@ Instructions [`BLS_G2_ZERO`](/tvm/instructions#f93025-bls_g2_zero) and [`BLS_G2_
140
140
|[`BLS_PAIRING`](/tvm/instructions#f93030-bls_pairing)|`20000 + 11800 * n`|`n` is the number of `(G1, G2)` pairs supplied for the pairing product check. |
141
141
142
142
[`BLS_PUSHR`](/tvm/instructions#f93031-bls_pushr) do not charge additional gas.
143
+
144
+
## `GasLimits` structure
145
+
146
+
TVM has inner structure `GasLimits` for gas manipulations. Its fields are:
147
+
148
+
-`gas_max`: the equivalent of contract's balance at the start of the compute phase in gas units.
149
+
-`gas_limit`: the amount of gas that can be consumed during the virtual machine execution. At the start of the execution, it equals:
150
+
- 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;
151
+
-`0` in the case of an external message.
152
+
-`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:
153
+
- minimum of `gas_max` and corresponding value in configuration parameter `20` for masterchain and `21` for basechain in the case of an external message;
154
+
-`0` in the case of an internal message.
155
+
-`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.
156
+
-`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`.
157
+
158
+
Instructions `SETGASLIMIT` and `ACCEPT` change all above values except `gas_max`:
159
+
160
+
-`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)`.
161
+
-`ACCEPT` is equivalent to `SETGASLIMIT` with the new gas limit equal to `2**63 - 1` (the maximum value of a signed 64-bits integer).
162
+
163
+
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.
0 commit comments