From e109e0ebef252dfcf7d989f1e6e63421a727a851 Mon Sep 17 00:00:00 2001 From: Hannes Karppila Date: Thu, 21 Mar 2024 00:57:53 +0200 Subject: [PATCH 1/2] Add GM_BASE_ASSET_ID --- src/fuel-vm/instruction-set.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/fuel-vm/instruction-set.md b/src/fuel-vm/instruction-set.md index 80afeecc..05fb5b15 100644 --- a/src/fuel-vm/instruction-set.md +++ b/src/fuel-vm/instruction-set.md @@ -2415,13 +2415,14 @@ Panic if: Read metadata from memory. A convenience instruction to avoid manually extracting metadata. -| name | value | description | -|------------------------------|-----------|---------------------------------| -| `GM_IS_CALLER_EXTERNAL` | `0x00001` | Get if caller is external. | -| `GM_GET_CALLER` | `0x00002` | Get caller's contract ID. | -| `GM_GET_VERIFYING_PREDICATE` | `0x00003` | Get index of current predicate. | -| `GM_GET_CHAIN_ID` | `0x00004` | Get the value of `CHAIN_ID` | -| `GM_GET_TX_START` | `0x00005` | Get transaction start address | +| name | value | description | +|------------------------------|-----------|----------------------------------| +| `GM_IS_CALLER_EXTERNAL` | `0x00001` | Get if caller is external. | +| `GM_GET_CALLER` | `0x00002` | Get caller's contract ID. | +| `GM_GET_VERIFYING_PREDICATE` | `0x00003` | Get index of current predicate. | +| `GM_GET_CHAIN_ID` | `0x00004` | Get the value of `CHAIN_ID` | +| `GM_TX_START` | `0x00005` | Transaction start memory address | +| `GM_BASE_ASSET_ID` | `0x00006` | Base asset ID | If `imm == GM_IS_CALLER_EXTERNAL`: From 8ecaae0c9b2959ef57cda3177ba98dbc6e5a2a83 Mon Sep 17 00:00:00 2001 From: Hannes Karppila Date: Thu, 21 Mar 2024 05:46:15 +0200 Subject: [PATCH 2/2] Add VM initialization changes --- src/fuel-vm/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fuel-vm/index.md b/src/fuel-vm/index.md index 85dd70c2..2caa33ed 100644 --- a/src/fuel-vm/index.md +++ b/src/fuel-vm/index.md @@ -81,6 +81,7 @@ Every time the VM runs, a single monolithic memory of size `VM_MAX_RAM` bytes is To initialize the VM, the following is pushed on the stack sequentially: 1. Transaction hash (`byte[32]`, word-aligned), computed as defined [here](../identifiers/transaction-id.md). +1. Base asset ID (`byte[32]`, word-aligned) 1. [`MAX_INPUTS`](../tx-format/consensus_parameters.md) pairs of `(asset_id: byte[32], balance: uint64)`, of: 1. For [predicate estimation](#predicate-estimation) and [predicate verification](#predicate-verification), zeroes. 1. For [script execution](#script-execution), the free balance for each asset ID seen in the transaction's inputs, ordered in ascending order. If there are fewer than `MAX_INPUTS` asset IDs, the pair has a value of zero. @@ -89,7 +90,7 @@ To initialize the VM, the following is pushed on the stack sequentially: Then the following registers are initialized (without explicit initialization, all registers are initialized to zero): -1. `$ssp = 32 + MAX_INPUTS*(32+8) + size(tx))`: the writable stack area starts immediately after the serialized transaction in memory (see above). +1. `$ssp = 32 + 32 + MAX_INPUTS*(32+8) + size(tx))`: the writable stack area starts immediately after the serialized transaction in memory (see above). 1. `$sp = $ssp`: writable stack area is empty to start. 1. `$hp = VM_MAX_RAM`: the heap area begins at the top and is empty to start.