Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BAL balance opcode #226

Merged
merged 6 commits into from
Nov 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions specs/vm/opcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
- [SB: Store byte](#sb-store-byte)
- [SW: Store word](#sw-store-word)
- [Contract Opcodes](#contract-opcodes)
- [BAL: Balance of contract ID](#bal-balance-of-contract-id)
- [BHEI: Block height](#bhei-block-height)
- [BHSH: Block hash](#bhsh-block-hash)
- [BURN: Burn existing coins](#burn-burn-existing-coins)
Expand Down Expand Up @@ -972,6 +973,53 @@ Panic if:

All these opcodes advance the program counter `$pc` by `4` after performing their operation, except for [CALL](#call-call-contract), [RETD](#retd-return-from-context-with-data) and [RVRT](#rvrt-revert).

### BAL: Balance of contract ID

| | |
|-------------|---------------------------------------------------------------------------|
| Description | Set `$rA` to the balance of color at `$rB` for contract with ID at `$rC`. |
| Operation | ```$rA = balance(MEM[$rB, 32], MEM[$rC, 32]);``` |
| Syntax | `bal $rA, $rB, $rC` |
| Encoding | `0x00 rA rB rC -` |
| Notes | |

Where helper `balance(color: byte[32], contract_id: byte[32]) -> uint64` returns the current balance of `color` of contract with ID `contract_id`.

Panic if:

- `$rA` is a [reserved register](./main.md#semantics)
- `$rB + 32` overflows
- `$rB + 32 > VM_MAX_RAM`

In a script transaction, append an additional receipt to the list of receipts, modifying `tx.receiptsRoot`:

| name | type | description |
|------------|---------------|-------------------------------------------------------------------------|
| `type` | `ReceiptType` | `ReceiptType.ScriptResult` |
| `result` | `uint64` | ```PanicReason.MemoryOverflow \| rB >> 8``` |
| `gas_used` | `uint64` | Gas consumed by the script. |

- `$rC + 32` overflows
- `$rC + 32 > VM_MAX_RAM`

In a script transaction, append an additional receipt to the list of receipts, modifying `tx.receiptsRoot`:

| name | type | description |
|------------|---------------|-------------------------------------------------------------------------|
| `type` | `ReceiptType` | `ReceiptType.ScriptResult` |
| `result` | `uint64` | `PanicReason.MemoryOverflow \| rC >> 8` |
| `gas_used` | `uint64` | Gas consumed by the script. |

- Contract with ID `MEM[$rC, 32]` is not in `tx.inputs`

In a script transaction, append an additional receipt to the list of receipts, modifying `tx.receiptsRoot`:

| name | type | description |
|------------|---------------|-------------------------------------------------------------------------|
| `type` | `ReceiptType` | `ReceiptType.ScriptResult` |
| `result` | `uint64` | `PanicReason.ContractNotInInputs \| rC >> 8` |
| `gas_used` | `uint64` | Gas consumed by the script. |

### BHEI: Block height

| | |
Expand Down