Skip to content

Commit a3153d8

Browse files
authored
tx_field tables (#2849)
Drive the checking of whether tx_field can set a particular field in a table-driven way, rather than by simple switch. This is cleaner as we add functionality in later versions, and will allow generating the spec for tx_field.
1 parent cde7eed commit a3153d8

File tree

10 files changed

+203
-142
lines changed

10 files changed

+203
-142
lines changed

cmd/opdoc/opdoc.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ func opToMarkdown(out io.Writer, op *logic.OpSpec) (err error) {
159159
if cost.From == cost.To {
160160
fmt.Fprintf(out, " - %d (LogicSigVersion = %d)\n", cost.Cost, cost.To)
161161
} else {
162-
fmt.Fprintf(out, " - %d (%d <= LogicSigVersion <= %d)\n", cost.Cost, cost.From, cost.To)
162+
if cost.To < logic.LogicVersion {
163+
fmt.Fprintf(out, " - %d (%d <= LogicSigVersion <= %d)\n", cost.Cost, cost.From, cost.To)
164+
} else {
165+
fmt.Fprintf(out, " - %d (LogicSigVersion >= %d)\n", cost.Cost, cost.From)
166+
}
163167
}
164168
}
165169
} else {

data/transactions/logic/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ various sizes.
148148
| `substring s e` | pop a byte-array A. For immediate values in 0..255 S and E: extract a range of bytes from A starting at S up to but not including E, push the substring result. If E < S, or either is larger than the array length, the program fails |
149149
| `substring3` | pop a byte-array A and two integers B and C. Extract a range of bytes from A starting at B up to but not including C, push the substring result. If C < B, or either is larger than the array length, the program fails |
150150
| `extract s l` | pop a byte-array A. For immediate values in 0..255 S and L: extract a range of bytes from A starting at S up to but not including S+L, push the substring result. If L is 0, then extract to the end of the string. If S or S+L is larger than the array length, the program fails |
151-
| `extract3` | pop a byte-array A and two integers B and C. Extract a range of bytes from A starting at B up to but not including B+C, push the substring result. If B or B+C is larger than the array length, the program fails |
152-
| `extract16bits` | pop a byte-array A and integer B. Extract a range of bytes from A starting at B up to but not including B+2, convert bytes as big endian and push the uint64 result. If B or B+2 is larger than the array length, the program fails |
153-
| `extract32bits` | pop a byte-array A and integer B. Extract a range of bytes from A starting at B up to but not including B+4, convert bytes as big endian and push the uint64 result. If B or B+4 is larger than the array length, the program fails |
154-
| `extract64bits` | pop a byte-array A and integer B. Extract a range of bytes from A starting at B up to but not including B+8, convert bytes as big endian and push the uint64 result. If B or B+8 is larger than the array length, the program fails |
151+
| `extract3` | pop a byte-array A and two integers B and C. Extract a range of bytes from A starting at B up to but not including B+C, push the substring result. If B+C is larger than the array length, the program fails |
152+
| `extract16bits` | pop a byte-array A and integer B. Extract a range of bytes from A starting at B up to but not including B+2, convert bytes as big endian and push the uint64 result. If B+2 is larger than the array length, the program fails |
153+
| `extract32bits` | pop a byte-array A and integer B. Extract a range of bytes from A starting at B up to but not including B+4, convert bytes as big endian and push the uint64 result. If B+4 is larger than the array length, the program fails |
154+
| `extract64bits` | pop a byte-array A and integer B. Extract a range of bytes from A starting at B up to but not including B+8, convert bytes as big endian and push the uint64 result. If B+8 is larger than the array length, the program fails |
155155

156156
These opcodes take byte-array values that are interpreted as
157157
big-endian unsigned integers. For mathematical operators, the
@@ -197,9 +197,9 @@ The following opcodes allow for the construction and submission of
197197

198198
| Op | Description |
199199
| --- | --- |
200-
| `tx_begin` | Prepare a new application action |
201-
| `tx_field f` | Set field F of the current application action |
202-
| `tx_submit` | Execute the current application action. Panic on any failure. |
200+
| `tx_begin` | Begin preparation of a new inner transaction |
201+
| `tx_field f` | Set field F of the current inner transaction to X |
202+
| `tx_submit` | Execute the current inner transaction. Panic on any failure. |
203203

204204

205205
### Loading Values
@@ -390,7 +390,7 @@ App fields used in the `app_params_get` opcode.
390390
| `dup` | duplicate last value on stack |
391391
| `dup2` | duplicate two last values on stack: A, B -> A, B, A, B |
392392
| `dig n` | push the Nth value from the top of the stack. dig 0 is equivalent to dup |
393-
| `cover n` | remove top of stack, and place it down the stack such that N elements are above it |
393+
| `cover n` | remove top of stack, and place it deeper in the stack such that N elements are above it |
394394
| `uncover n` | remove the value at depth N in the stack and shift above items down so the Nth deep value is on top of the stack |
395395
| `swap` | swaps two last values on stack: A, B -> B, A |
396396
| `select` | selects one of two values based on top-of-stack: A, B, C -> (if C != 0 then B else A) |

data/transactions/logic/TEAL_opcodes.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Ops have a 'cost' of 1 unless otherwise specified.
1818
- SHA256 hash of value X, yields [32]byte
1919
- **Cost**:
2020
- 7 (LogicSigVersion = 1)
21-
- 35 (2 <= LogicSigVersion <= 5)
21+
- 35 (LogicSigVersion >= 2)
2222

2323
## keccak256
2424

@@ -28,7 +28,7 @@ Ops have a 'cost' of 1 unless otherwise specified.
2828
- Keccak256 hash of value X, yields [32]byte
2929
- **Cost**:
3030
- 26 (LogicSigVersion = 1)
31-
- 130 (2 <= LogicSigVersion <= 5)
31+
- 130 (LogicSigVersion >= 2)
3232

3333
## sha512_256
3434

@@ -38,7 +38,7 @@ Ops have a 'cost' of 1 unless otherwise specified.
3838
- SHA512_256 hash of value X, yields [32]byte
3939
- **Cost**:
4040
- 9 (LogicSigVersion = 1)
41-
- 45 (2 <= LogicSigVersion <= 5)
41+
- 45 (LogicSigVersion >= 2)
4242

4343
## ed25519verify
4444

@@ -667,7 +667,7 @@ See `bnz` for details on how branches work. `b` always jumps to the offset.
667667
- Opcode: 0x4e {uint8 depth}
668668
- Pops: *... stack*, any
669669
- Pushes: any
670-
- remove top of stack, and place it down the stack such that N elements are above it
670+
- remove top of stack, and place it deeper in the stack such that N elements are above it
671671
- LogicSigVersion >= 5
672672

673673
## uncover n
@@ -753,31 +753,31 @@ When A is a uint64, index 0 is the least significant bit. Setting bit 3 to 1 on
753753
- Opcode: 0x58
754754
- Pops: *... stack*, {[]byte A}, {uint64 B}, {uint64 C}
755755
- Pushes: []byte
756-
- pop a byte-array A and two integers B and C. Extract a range of bytes from A starting at B up to but not including B+C, push the substring result. If B or B+C is larger than the array length, the program fails
756+
- pop a byte-array A and two integers B and C. Extract a range of bytes from A starting at B up to but not including B+C, push the substring result. If B+C is larger than the array length, the program fails
757757
- LogicSigVersion >= 5
758758

759759
## extract16bits
760760

761761
- Opcode: 0x59
762762
- Pops: *... stack*, {[]byte A}, {uint64 B}
763763
- Pushes: uint64
764-
- pop a byte-array A and integer B. Extract a range of bytes from A starting at B up to but not including B+2, convert bytes as big endian and push the uint64 result. If B or B+2 is larger than the array length, the program fails
764+
- pop a byte-array A and integer B. Extract a range of bytes from A starting at B up to but not including B+2, convert bytes as big endian and push the uint64 result. If B+2 is larger than the array length, the program fails
765765
- LogicSigVersion >= 5
766766

767767
## extract32bits
768768

769769
- Opcode: 0x5a
770770
- Pops: *... stack*, {[]byte A}, {uint64 B}
771771
- Pushes: uint64
772-
- pop a byte-array A and integer B. Extract a range of bytes from A starting at B up to but not including B+4, convert bytes as big endian and push the uint64 result. If B or B+4 is larger than the array length, the program fails
772+
- pop a byte-array A and integer B. Extract a range of bytes from A starting at B up to but not including B+4, convert bytes as big endian and push the uint64 result. If B+4 is larger than the array length, the program fails
773773
- LogicSigVersion >= 5
774774

775775
## extract64bits
776776

777777
- Opcode: 0x5b
778778
- Pops: *... stack*, {[]byte A}, {uint64 B}
779779
- Pushes: uint64
780-
- pop a byte-array A and integer B. Extract a range of bytes from A starting at B up to but not including B+8, convert bytes as big endian and push the uint64 result. If B or B+8 is larger than the array length, the program fails
780+
- pop a byte-array A and integer B. Extract a range of bytes from A starting at B up to but not including B+8, convert bytes as big endian and push the uint64 result. If B+8 is larger than the array length, the program fails
781781
- LogicSigVersion >= 5
782782

783783
## balance
@@ -1222,7 +1222,7 @@ bitlen interprets arrays as big-endian integers, unlike setbit/getbit
12221222
- Opcode: 0xb1
12231223
- Pops: _None_
12241224
- Pushes: _None_
1225-
- Prepare a new application action
1225+
- Begin preparation of a new inner transaction
12261226
- LogicSigVersion >= 5
12271227
- Mode: Application
12281228

@@ -1231,7 +1231,7 @@ bitlen interprets arrays as big-endian integers, unlike setbit/getbit
12311231
- Opcode: 0xb2 {uint8 transaction field index}
12321232
- Pops: *... stack*, any
12331233
- Pushes: _None_
1234-
- Set field F of the current application action
1234+
- Set field F of the current inner transaction to X
12351235
- LogicSigVersion >= 5
12361236
- Mode: Application
12371237

@@ -1240,7 +1240,7 @@ bitlen interprets arrays as big-endian integers, unlike setbit/getbit
12401240
- Opcode: 0xb3
12411241
- Pops: _None_
12421242
- Pushes: _None_
1243-
- Execute the current application action. Panic on any failure.
1243+
- Execute the current inner transaction. Panic on any failure.
12441244
- LogicSigVersion >= 5
12451245
- Mode: Application
12461246

data/transactions/logic/assembler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2552,7 +2552,7 @@ func disTxField(dis *disassembleState, spec *OpSpec) (string, error) {
25522552
dis.nextpc = dis.pc + 2
25532553
arg := dis.program[dis.pc+1]
25542554
if int(arg) >= len(TxnFieldNames) {
2555-
return "", fmt.Errorf("invalid txfield arg index %d at pc=%d", arg, dis.pc)
2555+
return "", fmt.Errorf("invalid %s arg index %d at pc=%d", spec.Name, arg, dis.pc)
25562556
}
25572557
return fmt.Sprintf("%s %s", spec.Name, TxnFieldNames[arg]), nil
25582558
}

data/transactions/logic/doc.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ var opDocByName = map[string]string{
100100
"dup": "duplicate last value on stack",
101101
"dup2": "duplicate two last values on stack: A, B -> A, B, A, B",
102102
"dig": "push the Nth value from the top of the stack. dig 0 is equivalent to dup",
103-
"cover": "remove top of stack, and place it down the stack such that N elements are above it",
103+
"cover": "remove top of stack, and place it deeper in the stack such that N elements are above it",
104104
"uncover": "remove the value at depth N in the stack and shift above items down so the Nth deep value is on top of the stack",
105105
"swap": "swaps two last values on stack: A, B -> B, A",
106106
"select": "selects one of two values based on top-of-stack: A, B, C -> (if C != 0 then B else A)",
@@ -112,10 +112,10 @@ var opDocByName = map[string]string{
112112
"getbyte": "pop a byte-array A and integer B. Extract the Bth byte of A and push it as an integer",
113113
"setbyte": "pop a byte-array A, integer B, and small integer C (between 0..255). Set the Bth byte of A to C, and push the result",
114114
"extract": "pop a byte-array A. For immediate values in 0..255 S and L: extract a range of bytes from A starting at S up to but not including S+L, push the substring result. If L is 0, then extract to the end of the string. If S or S+L is larger than the array length, the program fails",
115-
"extract3": "pop a byte-array A and two integers B and C. Extract a range of bytes from A starting at B up to but not including B+C, push the substring result. If B or B+C is larger than the array length, the program fails",
116-
"extract16bits": "pop a byte-array A and integer B. Extract a range of bytes from A starting at B up to but not including B+2, convert bytes as big endian and push the uint64 result. If B or B+2 is larger than the array length, the program fails",
117-
"extract32bits": "pop a byte-array A and integer B. Extract a range of bytes from A starting at B up to but not including B+4, convert bytes as big endian and push the uint64 result. If B or B+4 is larger than the array length, the program fails",
118-
"extract64bits": "pop a byte-array A and integer B. Extract a range of bytes from A starting at B up to but not including B+8, convert bytes as big endian and push the uint64 result. If B or B+8 is larger than the array length, the program fails",
115+
"extract3": "pop a byte-array A and two integers B and C. Extract a range of bytes from A starting at B up to but not including B+C, push the substring result. If B+C is larger than the array length, the program fails",
116+
"extract16bits": "pop a byte-array A and integer B. Extract a range of bytes from A starting at B up to but not including B+2, convert bytes as big endian and push the uint64 result. If B+2 is larger than the array length, the program fails",
117+
"extract32bits": "pop a byte-array A and integer B. Extract a range of bytes from A starting at B up to but not including B+4, convert bytes as big endian and push the uint64 result. If B+4 is larger than the array length, the program fails",
118+
"extract64bits": "pop a byte-array A and integer B. Extract a range of bytes from A starting at B up to but not including B+8, convert bytes as big endian and push the uint64 result. If B+8 is larger than the array length, the program fails",
119119

120120
"balance": "get balance for account A, in microalgos. The balance is observed after the effects of previous transactions in the group, and after the fee for the current transaction is deducted.",
121121
"min_balance": "get minimum required balance for account A, in microalgos. Required balance is affected by [ASA](https://developer.algorand.org/docs/features/asa/#assets-overview) and [App](https://developer.algorand.org/docs/features/asc1/stateful/#minimum-balance-requirement-for-a-smart-contract) usage. When creating or opting into an app, the minimum balance grows before the app code runs, therefore the increase is visible there. When deleting or closing out, the minimum balance decreases after the app executes.",
@@ -152,9 +152,9 @@ var opDocByName = map[string]string{
152152
"b~": "X with all bits inverted",
153153

154154
"log": "write bytes to log state of the current application",
155-
"tx_begin": "Prepare a new application action",
156-
"tx_field": "Set field F of the current application action",
157-
"tx_submit": "Execute the current application action. Panic on any failure.",
155+
"tx_begin": "Begin preparation of a new inner transaction",
156+
"tx_field": "Set field F of the current inner transaction to X",
157+
"tx_submit": "Execute the current inner transaction. Panic on any failure.",
158158

159159
"txnas": "push Xth value of the array field F of the current transaction",
160160
"gtxnas": "push Xth value of the array field F from the Tth transaction in the current group",

0 commit comments

Comments
 (0)