From 2f94958dfb4bac1cd3cdb597617d0b0cae44e328 Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Wed, 14 Dec 2022 08:18:57 -0500 Subject: [PATCH 1/4] Adding argenum fields, tweaks to immediate note --- cmd/opdoc/opdoc.go | 23 +++++++++-- data/transactions/logic/TEAL_opcodes.md | 22 +++++----- data/transactions/logic/doc.go | 24 +++++------ data/transactions/logic/langspec.json | 53 ++++++++++++++++++++----- 4 files changed, 84 insertions(+), 38 deletions(-) diff --git a/cmd/opdoc/opdoc.go b/cmd/opdoc/opdoc.go index 1a1e9941d1..bb893df3db 100644 --- a/cmd/opdoc/opdoc.go +++ b/cmd/opdoc/opdoc.go @@ -270,14 +270,19 @@ func typeString(types []logic.StackType) string { case logic.StackAny: out[i] = '.' case logic.StackNone: - if i == 0 && len(types) == 1 { - return "" - } - panic("unexpected StackNone in opdoc typeString") + out[i] = '_' default: panic("unexpected type in opdoc typeString") } } + + if strings.Contains(string(out), "_") { + if strings.ContainsAny(string(out), "UB.") { + panic("unexpected StackNone in opdoc typeString") + } + return "" + } + return string(out) } @@ -314,6 +319,16 @@ func argEnums(name string) ([]string, string) { return fieldsAndTypes(logic.AppParamsFields) case "acct_params_get": return fieldsAndTypes(logic.AcctParamsFields) + case "block": + return fieldsAndTypes(logic.BlockFields) + case "json_ref": + return fieldsAndTypes(logic.JSONRefTypes) + case "base64_decode": + return fieldsAndTypes(logic.Base64Encodings) + case "vrf_verify": + return fieldsAndTypes(logic.VrfStandards) + case "ecdsa_pk_recover", "ecdsa_verify", "ecdsa_pk_decompress": + return fieldsAndTypes(logic.EcdsaCurves) default: return nil, "" } diff --git a/data/transactions/logic/TEAL_opcodes.md b/data/transactions/logic/TEAL_opcodes.md index cd2bd5842d..a77c91c02c 100644 --- a/data/transactions/logic/TEAL_opcodes.md +++ b/data/transactions/logic/TEAL_opcodes.md @@ -280,7 +280,7 @@ The notation J,K indicates that two uint64 values J and K are interpreted as a u ## bytecblock bytes ... -- Opcode: 0x26 {varuint count} [({varuint value length} bytes), ...] +- Opcode: 0x26 {varuint count} [({varuint length} bytes), ...] - Stack: ... → ... - prepare block of byte-array constants for use by bytec @@ -318,7 +318,7 @@ The notation J,K indicates that two uint64 values J and K are interpreted as a u ## arg n -- Opcode: 0x2c {uint8 arg index N} +- Opcode: 0x2c {uint8 arg index} - Stack: ... → ..., []byte - Nth LogicSig argument - Mode: Signature @@ -570,7 +570,7 @@ for notes on transaction fields available, see `txn`. If top of stack is _i_, `g ## bnz target -- Opcode: 0x40 {int16 branch offset, big-endian} +- Opcode: 0x40 {int16 branch offset} - Stack: ..., A: uint64 → ... - branch to TARGET if value A is not zero @@ -580,7 +580,7 @@ At v2 it became allowed to branch to the end of the program exactly after the la ## bz target -- Opcode: 0x41 {int16 branch offset, big-endian} +- Opcode: 0x41 {int16 branch offset} - Stack: ..., A: uint64 → ... - branch to TARGET if value A is zero - Availability: v2 @@ -589,7 +589,7 @@ See `bnz` for details on how branches work. `bz` inverts the behavior of `bnz`. ## b target -- Opcode: 0x42 {int16 branch offset, big-endian} +- Opcode: 0x42 {int16 branch offset} - Stack: ... → ... - branch unconditionally to TARGET - Availability: v2 @@ -811,7 +811,7 @@ When A is a uint64, index 0 is the least significant bit. Setting bit 3 to 1 on ## json_ref r -- Opcode: 0x5f {uint8 return type} +- Opcode: 0x5f {uint8 return type index} - Stack: ..., A: []byte, B: []byte → ..., any - key B's value, of type R, from a [valid](jsonspec.md) utf-8 encoded json object A - **Cost**: 25 + 2 per 7 bytes of A @@ -1059,7 +1059,7 @@ pushint args are not added to the intcblock during assembly processes ## pushbytess bytes ... -- Opcode: 0x82 {varuint count} [({varuint value length} bytes), ...] +- Opcode: 0x82 {varuint count} [({varuint length} bytes), ...] - Stack: ... → ..., [N items] - push sequences of immediate byte arrays to stack (first byte array being deepest) - Availability: v8 @@ -1085,7 +1085,7 @@ pushints args are not added to the intcblock during assembly processes ## callsub target -- Opcode: 0x88 {int16 branch offset, big-endian} +- Opcode: 0x88 {int16 branch offset} - Stack: ... → ... - branch unconditionally to TARGET, saving the next instruction on the call stack - Availability: v4 @@ -1126,14 +1126,14 @@ Fails unless the last instruction executed was a `callsub`. ## switch target ... -- Opcode: 0x8d {uint8 branch count} [{int16 branch offset, big-endian}, ...] +- Opcode: 0x8d {uint8 branch count} [{int16 branch offset}, ...] - Stack: ..., A: uint64 → ... - branch to the Ath label. Continue at following instruction if index A exceeds the number of labels. - Availability: v8 ## match target ... -- Opcode: 0x8e {uint8 branch count} [{int16 branch offset, big-endian}, ...] +- Opcode: 0x8e {uint8 branch count} [{int16 branch offset}, ...] - Stack: ..., [A1, A2, ..., AN], B → ... - given match cases from A[1] to A[N], branch to the Ith label where A[I] = B. Continue to the following instruction if no matches are found. - Availability: v8 @@ -1548,7 +1548,7 @@ For boxes that exceed 4,096 bytes, consider `box_create`, `box_extract`, and `bo ## block f -- Opcode: 0xd1 {uint8 block field} +- Opcode: 0xd1 {uint8 block field index} - Stack: ..., A: uint64 → ..., any - field F of block A. Fail unless A falls between txn.LastValid-1002 and txn.FirstValid (exclusive) - Availability: v7 diff --git a/data/transactions/logic/doc.go b/data/transactions/logic/doc.go index 243c22ec2c..cd2a038b8c 100644 --- a/data/transactions/logic/doc.go +++ b/data/transactions/logic/doc.go @@ -224,12 +224,12 @@ var opcodeImmediateNotes = map[string]string{ "intc": "{uint8 int constant index}", "pushint": "{varuint int}", "pushints": "{varuint count} [{varuint value}, ...]", - "bytecblock": "{varuint count} [({varuint value length} bytes), ...]", + "bytecblock": "{varuint count} [({varuint length} bytes), ...]", "bytec": "{uint8 byte constant index}", "pushbytes": "{varuint length} {bytes}", - "pushbytess": "{varuint count} [({varuint value length} bytes), ...]", + "pushbytess": "{varuint count} [({varuint length} bytes), ...]", - "arg": "{uint8 arg index N}", + "arg": "{uint8 arg index}", "global": "{uint8 global field index}", "txn": "{uint8 transaction field index}", @@ -242,10 +242,10 @@ var opcodeImmediateNotes = map[string]string{ "gtxnas": "{uint8 transaction group index} {uint8 transaction field index}", "gtxnsas": "{uint8 transaction field index}", - "bnz": "{int16 branch offset, big-endian}", - "bz": "{int16 branch offset, big-endian}", - "b": "{int16 branch offset, big-endian}", - "callsub": "{int16 branch offset, big-endian}", + "bnz": "{int16 branch offset}", + "bz": "{int16 branch offset}", + "b": "{int16 branch offset}", + "callsub": "{int16 branch offset}", "load": "{uint8 position in scratch space to load from}", "store": "{uint8 position in scratch space to store to}", @@ -279,13 +279,13 @@ var opcodeImmediateNotes = map[string]string{ "ecdsa_pk_recover": "{uint8 curve index}", "base64_decode": "{uint8 encoding index}", - "json_ref": "{uint8 return type}", + "json_ref": "{uint8 return type index}", "vrf_verify": "{uint8 parameters index}", - "block": "{uint8 block field}", + "block": "{uint8 block field index}", - "switch": "{uint8 branch count} [{int16 branch offset, big-endian}, ...]", - "match": "{uint8 branch count} [{int16 branch offset, big-endian}, ...]", + "switch": "{uint8 branch count} [{int16 branch offset}, ...]", + "match": "{uint8 branch count} [{int16 branch offset}, ...]", "proto": "{uint8 arguments} {uint8 return values}", "frame_dig": "{int8 frame slot}", @@ -357,7 +357,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.", + "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.", "match": "`match` consumes N+1 values from the stack. Let the top stack value be B. The following N values represent an ordered list of match cases/constants (A), where the first value (A[0]) is the deepest in the stack. The immediate arguments are an ordered list of N labels (T). `match` will branch to target T[I], where A[I] = B. If there are no matches then execution continues on to the next instruction.", diff --git a/data/transactions/logic/langspec.json b/data/transactions/logic/langspec.json index 148f83e073..da2e96d7c8 100644 --- a/data/transactions/logic/langspec.json +++ b/data/transactions/logic/langspec.json @@ -67,6 +67,10 @@ "Args": "BBBBB", "Returns": "U", "Size": 2, + "ArgEnum": [ + "Secp256k1", + "Secp256r1" + ], "Doc": "for (data A, signature B, C and pubkey D, E) verify the signature of the data against the pubkey =\u003e {0 or 1}", "DocExtra": "The 32 byte Y-component of a public key is the last element on the stack, preceded by X-component of a pubkey, preceded by S and R components of a signature, preceded by the data that is fifth element on the stack. All values are big-endian encoded. The signed data must be 32 bytes long, and signatures in lower-S form are only accepted.", "ImmediateNote": "{uint8 curve index}", @@ -81,6 +85,10 @@ "Args": "B", "Returns": "BB", "Size": 2, + "ArgEnum": [ + "Secp256k1", + "Secp256r1" + ], "Doc": "decompress pubkey A into components X, Y", "DocExtra": "The 33 byte public key in a compressed form to be decompressed into X and Y (top) components. All values are big-endian encoded.", "ImmediateNote": "{uint8 curve index}", @@ -95,6 +103,10 @@ "Args": "BUBB", "Returns": "BB", "Size": 2, + "ArgEnum": [ + "Secp256k1", + "Secp256r1" + ], "Doc": "for (data A, recovery id B, signature C, D) recover a public key", "DocExtra": "S (top) and R elements of a signature, recovery id and data (bottom) are expected on the stack and used to deriver a public key. All values are big-endian encoded. The signed data must be 32 bytes long.", "ImmediateNote": "{uint8 curve index}", @@ -470,7 +482,7 @@ "Size": 0, "Doc": "prepare block of byte-array constants for use by bytec", "DocExtra": "`bytecblock` loads the following program bytes into an array of byte-array constants in the evaluator. These constants can be referred to by `bytec` and `bytec_*` which will push the value onto the stack. Subsequent calls to `bytecblock` reset and replace the bytes constants available to the script.", - "ImmediateNote": "{varuint count} [({varuint value length} bytes), ...]", + "ImmediateNote": "{varuint count} [({varuint length} bytes), ...]", "IntroducedVersion": 1, "Groups": [ "Loading Values" @@ -538,7 +550,7 @@ "Returns": "B", "Size": 2, "Doc": "Nth LogicSig argument", - "ImmediateNote": "{uint8 arg index N}", + "ImmediateNote": "{uint8 arg index}", "IntroducedVersion": 1, "Groups": [ "Loading Values" @@ -1044,7 +1056,7 @@ "Size": 3, "Doc": "branch to TARGET if value A is not zero", "DocExtra": "The `bnz` instruction opcode 0x40 is followed by two immediate data bytes which are a high byte first and low byte second which together form a 16 bit offset which the instruction may branch to. For a bnz instruction at `pc`, if the last element of the stack is not zero then branch to instruction at `pc + 3 + N`, else proceed to next instruction at `pc + 3`. Branch targets must be aligned instructions. (e.g. Branching to the second byte of a 2 byte op will be rejected.) Starting at v4, the offset is treated as a signed 16 bit integer allowing for backward branches and looping. In prior version (v1 to v3), branch offsets are limited to forward branches only, 0-0x7fff.\n\nAt v2 it became allowed to branch to the end of the program exactly after the last instruction: bnz to byte N (with 0-indexing) was illegal for a TEAL program with N bytes before v2, and is legal after it. This change eliminates the need for a last instruction of no-op as a branch target at the end. (Branching beyond the end--in other words, to a byte larger than N--is still illegal and will cause the program to fail.)", - "ImmediateNote": "{int16 branch offset, big-endian}", + "ImmediateNote": "{int16 branch offset}", "IntroducedVersion": 1, "Groups": [ "Flow Control" @@ -1057,7 +1069,7 @@ "Size": 3, "Doc": "branch to TARGET if value A is zero", "DocExtra": "See `bnz` for details on how branches work. `bz` inverts the behavior of `bnz`.", - "ImmediateNote": "{int16 branch offset, big-endian}", + "ImmediateNote": "{int16 branch offset}", "IntroducedVersion": 2, "Groups": [ "Flow Control" @@ -1069,7 +1081,7 @@ "Size": 3, "Doc": "branch unconditionally to TARGET", "DocExtra": "See `bnz` for details on how branches work. `b` always jumps to the offset.", - "ImmediateNote": "{int16 branch offset, big-endian}", + "ImmediateNote": "{int16 branch offset}", "IntroducedVersion": 2, "Groups": [ "Flow Control" @@ -1410,6 +1422,11 @@ "Args": "B", "Returns": "B", "Size": 2, + "ArgEnum": [ + "URLEncoding", + "StdEncoding" + ], + "ArgEnumTypes": "..", "Doc": "decode A which was base64-encoded using _encoding_ E. Fail if A is not base64 encoded with encoding E", "DocExtra": "*Warning*: Usage should be restricted to very rare use cases. In almost all cases, smart contracts should directly handle non-encoded byte-strings.\tThis 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`.", "ImmediateNote": "{uint8 encoding index}", @@ -1424,9 +1441,15 @@ "Args": "BB", "Returns": ".", "Size": 2, + "ArgEnum": [ + "JSONString", + "JSONUint64", + "JSONObject" + ], + "ArgEnumTypes": "BUB", "Doc": "key B's value, of type R, from a [valid](jsonspec.md) utf-8 encoded json object A", "DocExtra": "*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.", - "ImmediateNote": "{uint8 return type}", + "ImmediateNote": "{uint8 return type index}", "IntroducedVersion": 7, "Groups": [ "Byte Array Manipulation" @@ -1704,7 +1727,7 @@ "Size": 0, "Doc": "push sequences of immediate byte arrays to stack (first byte array being deepest)", "DocExtra": "pushbytess args are not added to the bytecblock during assembly processes", - "ImmediateNote": "{varuint count} [({varuint value length} bytes), ...]", + "ImmediateNote": "{varuint count} [({varuint length} bytes), ...]", "IntroducedVersion": 8, "Groups": [ "Loading Values" @@ -1740,7 +1763,7 @@ "Size": 3, "Doc": "branch unconditionally to TARGET, saving the next instruction on the call stack", "DocExtra": "The call stack is separate from the data stack. Only `callsub`, `retsub`, and `proto` manipulate it.", - "ImmediateNote": "{int16 branch offset, big-endian}", + "ImmediateNote": "{int16 branch offset}", "IntroducedVersion": 4, "Groups": [ "Flow Control" @@ -1799,7 +1822,7 @@ "Args": "U", "Size": 0, "Doc": "branch to the Ath label. Continue at following instruction if index A exceeds the number of labels.", - "ImmediateNote": "{uint8 branch count} [{int16 branch offset, big-endian}, ...]", + "ImmediateNote": "{uint8 branch count} [{int16 branch offset}, ...]", "IntroducedVersion": 8, "Groups": [ "Flow Control" @@ -1811,7 +1834,7 @@ "Size": 0, "Doc": "given match cases from A[1] to A[N], branch to the Ith label where A[I] = B. Continue to the following instruction if no matches are found.", "DocExtra": "`match` consumes N+1 values from the stack. Let the top stack value be B. The following N values represent an ordered list of match cases/constants (A), where the first value (A[0]) is the deepest in the stack. The immediate arguments are an ordered list of N labels (T). `match` will branch to target T[I], where A[I] = B. If there are no matches then execution continues on to the next instruction.", - "ImmediateNote": "{uint8 branch count} [{int16 branch offset, big-endian}, ...]", + "ImmediateNote": "{uint8 branch count} [{int16 branch offset}, ...]", "IntroducedVersion": 8, "Groups": [ "Flow Control" @@ -2651,6 +2674,9 @@ "Args": "BBB", "Returns": "BU", "Size": 2, + "ArgEnum": [ + "VrfAlgorand" + ], "Doc": "Verify the proof B of message A against pubkey C. Returns vrf output and verification flag.", "DocExtra": "`VrfAlgorand` is the VRF used in Algorand. It is ECVRF-ED25519-SHA512-Elligator2, specified in the IETF internet draft [draft-irtf-cfrg-vrf-03](https://datatracker.ietf.org/doc/draft-irtf-cfrg-vrf/03/).", "ImmediateNote": "{uint8 parameters index}", @@ -2665,8 +2691,13 @@ "Args": "U", "Returns": ".", "Size": 2, + "ArgEnum": [ + "BlkSeed", + "BlkTimestamp" + ], + "ArgEnumTypes": "BU", "Doc": "field F of block A. Fail unless A falls between txn.LastValid-1002 and txn.FirstValid (exclusive)", - "ImmediateNote": "{uint8 block field}", + "ImmediateNote": "{uint8 block field index}", "IntroducedVersion": 7, "Groups": [ "State Access" From 84350c51675f10dc84dc62e7860386ba7c16a1a1 Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Wed, 14 Dec 2022 09:03:08 -0500 Subject: [PATCH 2/4] Fix fmt --- cmd/opdoc/opdoc.go | 1 + data/transactions/logic/doc.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/opdoc/opdoc.go b/cmd/opdoc/opdoc.go index bb893df3db..0d8d79216b 100644 --- a/cmd/opdoc/opdoc.go +++ b/cmd/opdoc/opdoc.go @@ -276,6 +276,7 @@ func typeString(types []logic.StackType) string { } } + // Cant return None and !None from same op if strings.Contains(string(out), "_") { if strings.ContainsAny(string(out), "UB.") { panic("unexpected StackNone in opdoc typeString") diff --git a/data/transactions/logic/doc.go b/data/transactions/logic/doc.go index cd2a038b8c..02fde82561 100644 --- a/data/transactions/logic/doc.go +++ b/data/transactions/logic/doc.go @@ -357,7 +357,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.", + "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.", "match": "`match` consumes N+1 values from the stack. Let the top stack value be B. The following N values represent an ordered list of match cases/constants (A), where the first value (A[0]) is the deepest in the stack. The immediate arguments are an ordered list of N labels (T). `match` will branch to target T[I], where A[I] = B. If there are no matches then execution continues on to the next instruction.", From a913435ef6b5a877267e1b0627a762ebd19b8656 Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Wed, 14 Dec 2022 10:46:37 -0500 Subject: [PATCH 3/4] restore big-endian note --- data/transactions/logic/TEAL_opcodes.md | 12 ++++++------ data/transactions/logic/doc.go | 12 ++++++------ data/transactions/logic/langspec.json | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/data/transactions/logic/TEAL_opcodes.md b/data/transactions/logic/TEAL_opcodes.md index a77c91c02c..54a80db8f9 100644 --- a/data/transactions/logic/TEAL_opcodes.md +++ b/data/transactions/logic/TEAL_opcodes.md @@ -570,7 +570,7 @@ for notes on transaction fields available, see `txn`. If top of stack is _i_, `g ## bnz target -- Opcode: 0x40 {int16 branch offset} +- Opcode: 0x40 {int16 branch offset, big-endian} - Stack: ..., A: uint64 → ... - branch to TARGET if value A is not zero @@ -580,7 +580,7 @@ At v2 it became allowed to branch to the end of the program exactly after the la ## bz target -- Opcode: 0x41 {int16 branch offset} +- Opcode: 0x41 {int16 branch offset, big-endian} - Stack: ..., A: uint64 → ... - branch to TARGET if value A is zero - Availability: v2 @@ -589,7 +589,7 @@ See `bnz` for details on how branches work. `bz` inverts the behavior of `bnz`. ## b target -- Opcode: 0x42 {int16 branch offset} +- Opcode: 0x42 {int16 branch offset, big-endian} - Stack: ... → ... - branch unconditionally to TARGET - Availability: v2 @@ -1085,7 +1085,7 @@ pushints args are not added to the intcblock during assembly processes ## callsub target -- Opcode: 0x88 {int16 branch offset} +- Opcode: 0x88 {int16 branch offset, big-endian} - Stack: ... → ... - branch unconditionally to TARGET, saving the next instruction on the call stack - Availability: v4 @@ -1126,14 +1126,14 @@ Fails unless the last instruction executed was a `callsub`. ## switch target ... -- Opcode: 0x8d {uint8 branch count} [{int16 branch offset}, ...] +- Opcode: 0x8d {uint8 branch count} [{int16 branch offset, big-endian}, ...] - Stack: ..., A: uint64 → ... - branch to the Ath label. Continue at following instruction if index A exceeds the number of labels. - Availability: v8 ## match target ... -- Opcode: 0x8e {uint8 branch count} [{int16 branch offset}, ...] +- Opcode: 0x8e {uint8 branch count} [{int16 branch offset, big-endian}, ...] - Stack: ..., [A1, A2, ..., AN], B → ... - given match cases from A[1] to A[N], branch to the Ith label where A[I] = B. Continue to the following instruction if no matches are found. - Availability: v8 diff --git a/data/transactions/logic/doc.go b/data/transactions/logic/doc.go index 02fde82561..8242ad1e2d 100644 --- a/data/transactions/logic/doc.go +++ b/data/transactions/logic/doc.go @@ -242,10 +242,10 @@ var opcodeImmediateNotes = map[string]string{ "gtxnas": "{uint8 transaction group index} {uint8 transaction field index}", "gtxnsas": "{uint8 transaction field index}", - "bnz": "{int16 branch offset}", - "bz": "{int16 branch offset}", - "b": "{int16 branch offset}", - "callsub": "{int16 branch offset}", + "bnz": "{int16 branch offset, big-endian}", + "bz": "{int16 branch offset, big-endian}", + "b": "{int16 branch offset, big-endian}", + "callsub": "{int16 branch offset, big-endian}", "load": "{uint8 position in scratch space to load from}", "store": "{uint8 position in scratch space to store to}", @@ -284,8 +284,8 @@ var opcodeImmediateNotes = map[string]string{ "vrf_verify": "{uint8 parameters index}", "block": "{uint8 block field index}", - "switch": "{uint8 branch count} [{int16 branch offset}, ...]", - "match": "{uint8 branch count} [{int16 branch offset}, ...]", + "switch": "{uint8 branch count} [{int16 branch offset, big-endian}, ...]", + "match": "{uint8 branch count} [{int16 branch offset, big-endian}, ...]", "proto": "{uint8 arguments} {uint8 return values}", "frame_dig": "{int8 frame slot}", diff --git a/data/transactions/logic/langspec.json b/data/transactions/logic/langspec.json index da2e96d7c8..cbfb4b0d95 100644 --- a/data/transactions/logic/langspec.json +++ b/data/transactions/logic/langspec.json @@ -1056,7 +1056,7 @@ "Size": 3, "Doc": "branch to TARGET if value A is not zero", "DocExtra": "The `bnz` instruction opcode 0x40 is followed by two immediate data bytes which are a high byte first and low byte second which together form a 16 bit offset which the instruction may branch to. For a bnz instruction at `pc`, if the last element of the stack is not zero then branch to instruction at `pc + 3 + N`, else proceed to next instruction at `pc + 3`. Branch targets must be aligned instructions. (e.g. Branching to the second byte of a 2 byte op will be rejected.) Starting at v4, the offset is treated as a signed 16 bit integer allowing for backward branches and looping. In prior version (v1 to v3), branch offsets are limited to forward branches only, 0-0x7fff.\n\nAt v2 it became allowed to branch to the end of the program exactly after the last instruction: bnz to byte N (with 0-indexing) was illegal for a TEAL program with N bytes before v2, and is legal after it. This change eliminates the need for a last instruction of no-op as a branch target at the end. (Branching beyond the end--in other words, to a byte larger than N--is still illegal and will cause the program to fail.)", - "ImmediateNote": "{int16 branch offset}", + "ImmediateNote": "{int16 branch offset, big-endian}", "IntroducedVersion": 1, "Groups": [ "Flow Control" @@ -1069,7 +1069,7 @@ "Size": 3, "Doc": "branch to TARGET if value A is zero", "DocExtra": "See `bnz` for details on how branches work. `bz` inverts the behavior of `bnz`.", - "ImmediateNote": "{int16 branch offset}", + "ImmediateNote": "{int16 branch offset, big-endian}", "IntroducedVersion": 2, "Groups": [ "Flow Control" @@ -1081,7 +1081,7 @@ "Size": 3, "Doc": "branch unconditionally to TARGET", "DocExtra": "See `bnz` for details on how branches work. `b` always jumps to the offset.", - "ImmediateNote": "{int16 branch offset}", + "ImmediateNote": "{int16 branch offset, big-endian}", "IntroducedVersion": 2, "Groups": [ "Flow Control" @@ -1763,7 +1763,7 @@ "Size": 3, "Doc": "branch unconditionally to TARGET, saving the next instruction on the call stack", "DocExtra": "The call stack is separate from the data stack. Only `callsub`, `retsub`, and `proto` manipulate it.", - "ImmediateNote": "{int16 branch offset}", + "ImmediateNote": "{int16 branch offset, big-endian}", "IntroducedVersion": 4, "Groups": [ "Flow Control" @@ -1822,7 +1822,7 @@ "Args": "U", "Size": 0, "Doc": "branch to the Ath label. Continue at following instruction if index A exceeds the number of labels.", - "ImmediateNote": "{uint8 branch count} [{int16 branch offset}, ...]", + "ImmediateNote": "{uint8 branch count} [{int16 branch offset, big-endian}, ...]", "IntroducedVersion": 8, "Groups": [ "Flow Control" @@ -1834,7 +1834,7 @@ "Size": 0, "Doc": "given match cases from A[1] to A[N], branch to the Ith label where A[I] = B. Continue to the following instruction if no matches are found.", "DocExtra": "`match` consumes N+1 values from the stack. Let the top stack value be B. The following N values represent an ordered list of match cases/constants (A), where the first value (A[0]) is the deepest in the stack. The immediate arguments are an ordered list of N labels (T). `match` will branch to target T[I], where A[I] = B. If there are no matches then execution continues on to the next instruction.", - "ImmediateNote": "{uint8 branch count} [{int16 branch offset}, ...]", + "ImmediateNote": "{uint8 branch count} [{int16 branch offset, big-endian}, ...]", "IntroducedVersion": 8, "Groups": [ "Flow Control" From d9b48d58088a81d82a1b91dc952b3c1f966441ff Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Wed, 14 Dec 2022 11:19:17 -0500 Subject: [PATCH 4/4] adding reminder to possibly modify argEnums method with some automatic thing later --- cmd/opdoc/opdoc.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/opdoc/opdoc.go b/cmd/opdoc/opdoc.go index 0d8d79216b..409b1fa6c8 100644 --- a/cmd/opdoc/opdoc.go +++ b/cmd/opdoc/opdoc.go @@ -301,6 +301,9 @@ func fieldsAndTypes(group logic.FieldGroup) ([]string, string) { } func argEnums(name string) ([]string, string) { + // reminder: this needs to be manually updated every time + // a new opcode is added with an associated FieldGroup + // it'd be nice to have this auto-update switch name { case "txn", "gtxn", "gtxns", "itxn", "gitxn": return fieldsAndTypes(logic.TxnFields)