Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion cmd/opdoc/opdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/algorand/go-algorand/protocol"
)

var docVersion = 7
var docVersion = 8

func opGroupMarkdownTable(names []string, out io.Writer) {
fmt.Fprint(out, `| Opcode | Description |
Expand Down
1 change: 1 addition & 0 deletions data/transactions/logic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ Account fields used in the `acct_params_get` opcode.
| `assert` | immediately fail unless A is a non-zero number |
| `callsub target` | branch unconditionally to TARGET, saving the next instruction on the call stack |
| `retsub` | pop the top instruction from the call stack and branch to it |
| `switchi target ...` | branch to target at index A. Fail if index A is out of bounds. |

### State Access

Expand Down
9 changes: 9 additions & 0 deletions data/transactions/logic/TEAL_opcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -1411,3 +1411,12 @@ The notation A,B indicates that A and B are interpreted as a uint128 value, with
| 0 | BlkSeed | []byte | |
| 1 | BlkTimestamp | uint64 | |


## switchi target ...

- Opcode: 0xe0 {varuint length} [{int16 branch offset, big-endian}, ...]
- Stack: ..., A: uint64 → ...
- branch to target at index A. Fail if index A is out of bounds.
- Availability: v8

`switchi` is followed by `n`, the number of targets, each of which are encoded as 2 byte values indicating the position of the target label relative to the end of the `switchi` instruction (i.e. the offset). The last element on the stack represents the index of the target to branch to. If the index is greater than or equal to n, the evaluation will fail. Otherwise, the program will branch to `pc + 1 + sizeof(n) + 2 * n + target[index]`. Branch targets must be aligned instructions. (e.g. Branching to the second byte of a 2 byte op will be rejected.)
2 changes: 1 addition & 1 deletion data/transactions/logic/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ var opDocExtras = map[string]string{
"itxn_submit": "`itxn_submit` resets the current transaction so that it can not be resubmitted. A new `itxn_begin` is required to prepare another inner transaction.",
"base64_decode": "*Warning*: Usage should be restricted to very rare use cases. In almost all cases, smart contracts should directly handle non-encoded byte-strings. This opcode should only be used in cases where base64 is the only available option, e.g. interoperability with a third-party that only signs base64 strings.\n\n Decodes A using the base64 encoding E. Specify the encoding with an immediate arg either as URL and Filename Safe (`URLEncoding`) or Standard (`StdEncoding`). See [RFC 4648 sections 4 and 5](https://rfc-editor.org/rfc/rfc4648.html#section-4). It is assumed that the encoding ends with the exact number of `=` padding characters as required by the RFC. When padding occurs, any unused pad bits in the encoding must be set to zero or the decoding will fail. The special cases of `\\n` and `\\r` are allowed but completely ignored. An error will result when attempting to decode a string with a character that is not in the encoding alphabet or not one of `=`, `\\r`, or `\\n`.",
"json_ref": "*Warning*: Usage should be restricted to very rare use cases, as JSON decoding is expensive and quite limited. In addition, JSON objects are large and not optimized for size.\n\nAlmost all smart contracts should use simpler and smaller methods (such as the [ABI](https://arc.algorand.foundation/ARCs/arc-0004). This opcode should only be used in cases where JSON is only available option, e.g. when a third-party only signs JSON.",
"switchi": "The `switchi` instruction opcode 0xe0 is followed by `n`, the number of targets, each of which are encoded as 2 byte values indicating the position of the target label relative to the end of the `switchi` instruction (i.e. the offset). The last element on the stack represents the index of the target to branch to. If the index is greater than or equal to n, the evaluation will fail. Otherwise, the program will branch to `pc + 1 + sizeof(n) + 2 * n + target[index]`. Branch targets must be aligned instructions. (e.g. Branching to the second byte of a 2 byte op will be rejected.)",
"switchi": "`switchi` is followed by `n`, the number of targets, each of which are encoded as 2 byte values indicating the position of the target label relative to the end of the `switchi` instruction (i.e. the offset). The last element on the stack represents the index of the target to branch to. If the index is greater than or equal to n, the evaluation will fail. Otherwise, the program will branch to `pc + 1 + sizeof(n) + 2 * n + target[index]`. Branch targets must be aligned instructions. (e.g. Branching to the second byte of a 2 byte op will be rejected.)",
}

// OpDocExtra returns extra documentation text about an op
Expand Down
14 changes: 13 additions & 1 deletion data/transactions/logic/langspec.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"EvalMaxVersion": 7,
"EvalMaxVersion": 8,
"LogicSigVersion": 7,
"Ops": [
{
Expand Down Expand Up @@ -2302,6 +2302,18 @@
"Groups": [
"State Access"
]
},
{
"Opcode": 224,
"Name": "switchi",
"Args": "U",
"Size": 0,
"Doc": "branch to target at index A. Fail if index A is out of bounds.",
"DocExtra": "`switchi` is followed by `n`, the number of targets, each of which are encoded as 2 byte values indicating the position of the target label relative to the end of the `switchi` instruction (i.e. the offset). The last element on the stack represents the index of the target to branch to. If the index is greater than or equal to n, the evaluation will fail. Otherwise, the program will branch to `pc + 1 + sizeof(n) + 2 * n + target[index]`. Branch targets must be aligned instructions. (e.g. Branching to the second byte of a 2 byte op will be rejected.)",
"ImmediateNote": "{varuint length} [{int16 branch offset, big-endian}, ...]",
"Groups": [
"Flow Control"
]
}
]
}
2 changes: 1 addition & 1 deletion data/transactions/logic/opcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const randomnessVersion = 7 // vrf_verify, block
// EXPERIMENTAL. These should be revisited whenever a new LogicSigVersion is
// moved from vFuture to a new consensus version. If they remain unready, bump
// their version, and fixup TestAssemble() in assembler_test.go.
const pairingVersion = 8 // bn256 opcodes. will add bls12-381, and unify the available opcodes.
const pairingVersion = 9 // bn256 opcodes. will add bls12-381, and unify the available opcodes.

type linearCost struct {
baseCost int
Expand Down