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

Feedback on algoidurovic#3 for switchi fall-through #12

Merged
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
17 changes: 12 additions & 5 deletions data/transactions/logic/assembler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2782,14 +2782,21 @@ func TestAssembleSwitch(t *testing.T) {
switchi label1 label2
label1:
`
testProg(t, source, 8, NewExpect(3, "reference to undefined label \"label2\""))
testProg(t, source, AssemblerMaxVersion, NewExpect(3, "reference to undefined label \"label2\""))

// fail when target index != uint64
testProg(t, `
byte "fail"
switchi label1
labe11:
`, AssemblerMaxVersion, Expect{3, "switchi label1 arg 0 wanted type uint64..."})

// No labels is pretty degenerate, but ok, I suppose. It's just a no-op
testProg(t, `
int 0
switchi
int 1
`, 8)
`, AssemblerMaxVersion)

// confirm size of varuint list size
source = `
Expand All @@ -2798,7 +2805,7 @@ int 1
label1:
label2:
`
ops, err := AssembleStringWithVersion(source, 8)
ops, err := AssembleStringWithVersion(source, AssemblerMaxVersion)
require.NoError(t, err)
val, bytesUsed := binary.Uvarint(ops.Program[4:])
require.Equal(t, uint64(2), val)
Expand All @@ -2819,7 +2826,7 @@ int 1
switchi %s
%s
`, strings.Join(labelReferences, " "), strings.Join(labels, "\n"))
ops, err = AssembleStringWithVersion(source, 8)
ops, err = AssembleStringWithVersion(source, AssemblerMaxVersion)
require.NoError(t, err)
val, bytesUsed = binary.Uvarint(ops.Program[4:])
require.Equal(t, uint64(1<<9), val)
Expand All @@ -2831,5 +2838,5 @@ int 1
switchi label1 label1
label1:
`
testProg(t, source, 8)
testProg(t, source, AssemblerMaxVersion)
}
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": "The `switchi` instruction opcode 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, then evaluation falls through to the next instruction. 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