From 0eab75e4591f5c62f7d60df1e4a341b188b7138b Mon Sep 17 00:00:00 2001
From: xgreenx <xgreenx9999@gmail.com>
Date: Tue, 7 Nov 2023 10:50:19 +0000
Subject: [PATCH 1/4] Some clarification after implementation

---
 src/fuel-vm/instruction-set.md | 3 +--
 src/tx-format/transaction.md   | 3 ++-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/fuel-vm/instruction-set.md b/src/fuel-vm/instruction-set.md
index c128e56e..eafcfed1 100644
--- a/src/fuel-vm/instruction-set.md
+++ b/src/fuel-vm/instruction-set.md
@@ -2508,8 +2508,7 @@ Get [fields from the transaction](../tx-format/transaction.md).
 | `GTF_OUTPUT_CONTRACT_CREATED_STATE_ROOT`  | `0x308` | Memory address of `tx.outputs[$rB].stateRoot`                     |
 | `GTF_WITNESS_DATA_LENGTH`                 | `0x400` | `tx.witnesses[$rB].dataLength`                                    |
 | `GTF_WITNESS_DATA`                        | `0x401` | Memory address of `tx.witnesses[$rB].data`                        |
-| `GTF_POLICY_COUNT`                        | `0x500` | `count_ones(tx.policyTypes)`                                      |
-| `GTF_POLICY_TYPE`                         | `0x501` | `tx.policies[$rB].type`                                           |
+| `GTF_POLICY_TYPES`                        | `0x501` | `tx.policies.policyTypes`                                         |
 | `GTF_POLICY_GAS_PRICE`                    | `0x502` | `tx.policies[0x00].gasPrice`                                      |
 | `GTF_POLICY_WITNESS_LIMIT`                | `0x504` | `tx.policies[count_ones(0b11 & tx.policyTypes) - 1].witnessLimit` |
 | `GTF_POLICY_MATURITY`                     | `0x505` | `tx.policies[count_ones(0b111 & tx.policyTypes) - 1].maturity`    |
diff --git a/src/tx-format/transaction.md b/src/tx-format/transaction.md
index 04acd77c..7141f952 100644
--- a/src/tx-format/transaction.md
+++ b/src/tx-format/transaction.md
@@ -72,6 +72,7 @@ enum ReceiptType : uint8 {
 | `outputs`          | [Output](./output.md)`[]`   | List of outputs.                                     |
 | `witnesses`        | [Witness](./witness.md)`[]` | List of witnesses.                                   |
 
+Given helper `max_gas()` returns the maximum gas that the transaction can use..
 Given helper `len()` that returns the number of bytes of a field.
 Given helper `count_ones()` that returns the number of ones in the binary representation of a field.
 Given helper `count_variants()` that returns the number of variants in an enum.
@@ -84,7 +85,7 @@ Transaction is invalid if:
 - `scriptDataLength > MAX_SCRIPT_DATA_LENGTH`
 - `scriptLength * 4 != len(script)`
 - `scriptDataLength != len(scriptData)`
-- `gasLimit > MAX_GAS_PER_TX`
+- `max_gas(tx) > MAX_GAS_PER_TX`
 - No policy of type `PolicyType.GasPrice`
 - `count_ones(policyTypes) > count_variants(PolicyType)`
 - `policyTypes > sum_variants(PolicyType)`

From 286414b8126251b6ccaa15274bb183795e24a686 Mon Sep 17 00:00:00 2001
From: xgreenx <xgreenx9999@gmail.com>
Date: Tue, 7 Nov 2023 12:01:07 +0000
Subject: [PATCH 2/4] Applied the check for `Create` transaciton too

---
 src/tx-format/transaction.md | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/tx-format/transaction.md b/src/tx-format/transaction.md
index 7141f952..8dbfc617 100644
--- a/src/tx-format/transaction.md
+++ b/src/tx-format/transaction.md
@@ -72,7 +72,7 @@ enum ReceiptType : uint8 {
 | `outputs`          | [Output](./output.md)`[]`   | List of outputs.                                     |
 | `witnesses`        | [Witness](./witness.md)`[]` | List of witnesses.                                   |
 
-Given helper `max_gas()` returns the maximum gas that the transaction can use..
+Given helper `max_gas()` returns the maximum gas that the transaction can use.
 Given helper `len()` that returns the number of bytes of a field.
 Given helper `count_ones()` that returns the number of ones in the binary representation of a field.
 Given helper `count_variants()` that returns the number of variants in an enum.
@@ -117,6 +117,7 @@ The receipts root `receiptsRoot` is the root of the [binary Merkle tree](../prot
 | `outputs`              | [Output](./output.md)`[]`   | List of outputs.                                  |
 | `witnesses`            | [Witness](./witness.md)`[]` | List of witnesses.                                |
 
+Given helper `max_gas()` returns the maximum gas that the transaction can use.
 Given helper `count_ones()` that returns the number of ones in the binary representation of a field.
 Given helper `count_variants()` that returns the number of variants in an enum.
 Given helper `sum_variants()` that sums all variants of an enum.
@@ -134,6 +135,7 @@ Transaction is invalid if:
 - The keys of `storageSlots` are not in ascending lexicographic order
 - The computed contract ID (see below) is not equal to the `contractID` of the one `OutputType.ContractCreated` output
 - `storageSlotsCount > MAX_STORAGE_SLOTS`
+- `max_gas(tx) > MAX_GAS_PER_TX`
 - The [Sparse Merkle tree](../protocol/cryptographic-primitives.md#sparse-merkle-tree) root of `storageSlots` is not equal to the `stateRoot` of the one `OutputType.ContractCreated` output
 - No policy of type `PolicyType.GasPrice`
 - `count_ones(policyTypes) > count_variants(PolicyType)`

From b4bf86fdb3ab6ace1b69435cef7285590e619576 Mon Sep 17 00:00:00 2001
From: xgreenx <xgreenx9999@gmail.com>
Date: Wed, 8 Nov 2023 09:23:31 +0000
Subject: [PATCH 3/4] Use `ScriptGasLimit` instead of `GasLimit`

---
 src/fuel-vm/index.md           |  2 +-
 src/fuel-vm/instruction-set.md |  2 +-
 src/protocol/tx-validity.md    |  4 ++--
 src/tx-format/transaction.md   | 32 ++++++++++++++++----------------
 4 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/src/fuel-vm/index.md b/src/fuel-vm/index.md
index cea85fec..533e8442 100644
--- a/src/fuel-vm/index.md
+++ b/src/fuel-vm/index.md
@@ -149,7 +149,7 @@ If script bytecode is present, transaction validation requires execution.
 The VM is [initialized](#vm-initialization), then:
 
 1. `$pc` and `$is` are set to the start of the transaction's script bytecode.
-1. `$ggas` and `$cgas` are set to `tx.gasLimit`.
+1. `$ggas` and `$cgas` are set to `tx.scriptGasLimit`.
 
 Following initialization, execution begins.
 
diff --git a/src/fuel-vm/instruction-set.md b/src/fuel-vm/instruction-set.md
index eafcfed1..dec89c09 100644
--- a/src/fuel-vm/instruction-set.md
+++ b/src/fuel-vm/instruction-set.md
@@ -2442,7 +2442,7 @@ Get [fields from the transaction](../tx-format/transaction.md).
 | name                                      | `imm`   | set `$rA` to                                                      |
 |-------------------------------------------|---------|-------------------------------------------------------------------|
 | `GTF_TYPE`                                | `0x001` | `tx.type`                                                         |
-| `GTF_SCRIPT_GAS_LIMIT`                    | `0x002` | `tx.gasLimit`                                                     |
+| `GTF_SCRIPT_GAS_LIMIT`                    | `0x002` | `tx.scriptGasLimit`                                               |
 | `GTF_SCRIPT_SCRIPT_LENGTH`                | `0x003` | `tx.scriptLength`                                                 |
 | `GTF_SCRIPT_SCRIPT_DATA_LENGTH`           | `0x004` | `tx.scriptDataLength`                                             |
 | `GTF_SCRIPT_INPUTS_COUNT`                 | `0x005` | `tx.inputsCount`                                                  |
diff --git a/src/protocol/tx-validity.md b/src/protocol/tx-validity.md
index 2ca48fab..0bacccd4 100644
--- a/src/protocol/tx-validity.md
+++ b/src/protocol/tx-validity.md
@@ -144,7 +144,7 @@ def unavailable_balance(tx, asset_id) -> int:
     return sentBalance
 
 def fee_balance(tx, asset_id) -> int:
-    gas = tx.gasLimit + sum_predicate_gas_used(tx)
+    gas = tx.scriptGasLimit + sum_predicate_gas_used(tx)
     gasBalance = gasPrice * gas / GAS_PRICE_FACTOR
     bytesBalance = size(tx) * GAS_PER_BYTE * gasPrice / GAS_PRICE_FACTOR
     # Total fee balance
@@ -205,7 +205,7 @@ Once the free balances are computed, the [script is executed](../fuel-vm/index.m
 1. The unspent free balance `unspentBalance` for each asset ID.
 1. The unspent gas `unspentGas` from the `$ggas` register.
 
-The fees incurred for a transaction are `ceiling(((size(tx) * GAS_PER_BYTE) + (tx.gasLimit - unspentGas) + sum(tx.inputs[i].predicateGasUsed)) * tx.gasPrice / GAS_PRICE_FACTOR)`.
+The fees incurred for a transaction are `ceiling(((size(tx) * GAS_PER_BYTE) + (tx.scriptGasLimit - unspentGas) + sum(tx.inputs[i].predicateGasUsed)) * tx.gasPrice / GAS_PRICE_FACTOR)`.
 
 `size(tx)` includes the entire transaction serialized according to the transaction format, including witness data.
 This ensures every byte of block space either on Fuel or corresponding DA layer can be accounted for.
diff --git a/src/tx-format/transaction.md b/src/tx-format/transaction.md
index 8dbfc617..abca7225 100644
--- a/src/tx-format/transaction.md
+++ b/src/tx-format/transaction.md
@@ -55,22 +55,22 @@ enum ReceiptType : uint8 {
 }
 ```
 
-| name               | type                        | description                                          |
-|--------------------|-----------------------------|------------------------------------------------------|
-| `gasLimit`         | `uint64`                    | Gas limit for transaction (including predicate gas). |
-| `scriptLength`     | `uint16`                    | Script length, in instructions.                      |
-| `scriptDataLength` | `uint16`                    | Length of script input data, in bytes.               |
-| `policyTypes`      | `uint32`                    | Bitfield of used policy types.                       |
-| `inputsCount`      | `uint8`                     | Number of inputs.                                    |
-| `outputsCount`     | `uint8`                     | Number of outputs.                                   |
-| `witnessesCount`   | `uint8`                     | Number of witnesses.                                 |
-| `receiptsRoot`     | `byte[32]`                  | Merkle root of receipts.                             |
-| `script`           | `byte[]`                    | Script to execute.                                   |
-| `scriptData`       | `byte[]`                    | Script input data (parameters).                      |
-| `policies`         | [Policy](./policy.md)`[]`   | List of policies, sorted by PolicyType.              |
-| `inputs`           | [Input](./input.md)`[]`     | List of inputs.                                      |
-| `outputs`          | [Output](./output.md)`[]`   | List of outputs.                                     |
-| `witnesses`        | [Witness](./witness.md)`[]` | List of witnesses.                                   |
+| name               | type                        | description                             |
+|--------------------|-----------------------------|-----------------------------------------|
+| `scriptGasLimit`   | `uint64`                    | Gas limits the script execution.        |
+| `scriptLength`     | `uint16`                    | Script length, in instructions.         |
+| `scriptDataLength` | `uint16`                    | Length of script input data, in bytes.  |
+| `policyTypes`      | `uint32`                    | Bitfield of used policy types.          |
+| `inputsCount`      | `uint8`                     | Number of inputs.                       |
+| `outputsCount`     | `uint8`                     | Number of outputs.                      |
+| `witnessesCount`   | `uint8`                     | Number of witnesses.                    |
+| `receiptsRoot`     | `byte[32]`                  | Merkle root of receipts.                |
+| `script`           | `byte[]`                    | Script to execute.                      |
+| `scriptData`       | `byte[]`                    | Script input data (parameters).         |
+| `policies`         | [Policy](./policy.md)`[]`   | List of policies, sorted by PolicyType. |
+| `inputs`           | [Input](./input.md)`[]`     | List of inputs.                         |
+| `outputs`          | [Output](./output.md)`[]`   | List of outputs.                        |
+| `witnesses`        | [Witness](./witness.md)`[]` | List of witnesses.                      |
 
 Given helper `max_gas()` returns the maximum gas that the transaction can use.
 Given helper `len()` that returns the number of bytes of a field.

From f68e2a501f8a5819534ea8206b097d199c68831b Mon Sep 17 00:00:00 2001
From: xgreenx <xgreenx9999@gmail.com>
Date: Wed, 8 Nov 2023 09:41:11 +0000
Subject: [PATCH 4/4] Bump Policices GTF

---
 src/fuel-vm/instruction-set.md | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/fuel-vm/instruction-set.md b/src/fuel-vm/instruction-set.md
index dec89c09..30bde941 100644
--- a/src/fuel-vm/instruction-set.md
+++ b/src/fuel-vm/instruction-set.md
@@ -2508,11 +2508,11 @@ Get [fields from the transaction](../tx-format/transaction.md).
 | `GTF_OUTPUT_CONTRACT_CREATED_STATE_ROOT`  | `0x308` | Memory address of `tx.outputs[$rB].stateRoot`                     |
 | `GTF_WITNESS_DATA_LENGTH`                 | `0x400` | `tx.witnesses[$rB].dataLength`                                    |
 | `GTF_WITNESS_DATA`                        | `0x401` | Memory address of `tx.witnesses[$rB].data`                        |
-| `GTF_POLICY_TYPES`                        | `0x501` | `tx.policies.policyTypes`                                         |
-| `GTF_POLICY_GAS_PRICE`                    | `0x502` | `tx.policies[0x00].gasPrice`                                      |
-| `GTF_POLICY_WITNESS_LIMIT`                | `0x504` | `tx.policies[count_ones(0b11 & tx.policyTypes) - 1].witnessLimit` |
-| `GTF_POLICY_MATURITY`                     | `0x505` | `tx.policies[count_ones(0b111 & tx.policyTypes) - 1].maturity`    |
-| `GTF_POLICY_MAX_FEE`                      | `0x506` | `tx.policies[count_ones(0b1111 & tx.policyTypes) - 1].maxFee`     |
+| `GTF_POLICY_TYPES`                        | `0x500` | `tx.policies.policyTypes`                                         |
+| `GTF_POLICY_GAS_PRICE`                    | `0x501` | `tx.policies[0x00].gasPrice`                                      |
+| `GTF_POLICY_WITNESS_LIMIT`                | `0x502` | `tx.policies[count_ones(0b11 & tx.policyTypes) - 1].witnessLimit` |
+| `GTF_POLICY_MATURITY`                     | `0x503` | `tx.policies[count_ones(0b111 & tx.policyTypes) - 1].maturity`    |
+| `GTF_POLICY_MAX_FEE`                      | `0x504` | `tx.policies[count_ones(0b1111 & tx.policyTypes) - 1].maxFee`     |
 
 Panic if: