Skip to content

Commit

Permalink
Fix balanceOfStart usage. (#327)
Browse files Browse the repository at this point in the history
* Fix balanceOfStart usage.

* Fix helper wording.
  • Loading branch information
adlerjohn authored Jun 6, 2022
1 parent 60be3d7 commit f32f5dd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions specs/vm/opcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,8 @@ This modifies the `balanceRoot` field of the appropriate output.
| Encoding | `0x00 rA rB rC rD` |
| Notes | |

Given helper `balanceOfStart(asset_id: byte[32]) -> uint32` which returns the memory address of the remaining free balance of `asset_id`, or panics if `asset_id` has no free balance remaining.

Panic if:

- `$rA + 32` overflows
Expand Down Expand Up @@ -1495,7 +1497,7 @@ Panic if:
| Encoding | `0x00 rA rB rC -` |
| Notes | |

Given helper `balanceOfStart(asset_id: byte[32]) -> uint32` which returns the memory address of `asset_id` balance, or `0` if `asset_id` has no balance.
Given helper `balanceOfStart(asset_id: byte[32]) -> uint32` which returns the memory address of the remaining free balance of `asset_id`, or panics if `asset_id` has no free balance remaining.

Panic if:

Expand All @@ -1504,7 +1506,7 @@ Panic if:
- `$rA + 32 > VM_MAX_RAM`
- `$rC + 32 > VM_MAX_RAM`
- Contract with ID `MEM[$rA, 32]` is not in `tx.inputs`
- In an external context, if `$rB > MEM[balanceOf(MEM[$rC, 32]), 8]`
- In an external context, if `$rB > MEM[balanceOfStart(MEM[$rC, 32]), 8]`
- In an internal context, if `$rB` is greater than the balance of asset ID `MEM[$rC, 32]` of output with contract ID `MEM[$fp, 32]`
- `$rB == 0`

Expand Down Expand Up @@ -1534,7 +1536,7 @@ This modifies the `balanceRoot` field of the appropriate output(s).
| Encoding | `0x00 rA rB rC rD` |
| Notes | |

Given helper `balanceOfStart(asset_id: byte[32]) -> uint32` which returns the memory address of `asset_id` balance, or `0` if `asset_id` has no balance.
Given helper `balanceOfStart(asset_id: byte[32]) -> uint32` which returns the memory address of the remaining free balance of `asset_id`, or panics if `asset_id` has no free balance remaining.

Panic if:

Expand All @@ -1543,7 +1545,7 @@ Panic if:
- `$rA + 32 > VM_MAX_RAM`
- `$rD + 32 > VM_MAX_RAM`
- `$rB > tx.outputsCount`
- In an external context, if `$rC > MEM[balanceOf(MEM[$rD, 32]), 8]`
- In an external context, if `$rC > MEM[balanceOfStart(MEM[$rD, 32]), 8]`
- In an internal context, if `$rC` is greater than the balance of asset ID `MEM[$rD, 32]` of output with contract ID `MEM[$fp, 32]`
- `$rC == 0`
- `tx.outputs[$rB].type != OutputType.Variable`
Expand Down

0 comments on commit f32f5dd

Please # to comment.