Skip to content

Commit

Permalink
more checking on tx_field type setting
Browse files Browse the repository at this point in the history
  • Loading branch information
jannotti committed Sep 7, 2021
1 parent adbfd50 commit 04c6b6f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion data/transactions/logic/assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2476,7 +2476,7 @@ func disTxField(dis *disassembleState, spec *OpSpec) (string, error) {
dis.nextpc = dis.pc + 2
arg := dis.program[dis.pc+1]
if int(arg) >= len(TxnFieldNames) {
return "", fmt.Errorf("invalid txfield arg index %d at pc=%d", arg, dis.pc)
return "", fmt.Errorf("invalid %s arg index %d at pc=%d", spec.Name, arg, dis.pc)
}
return fmt.Sprintf("%s %s", spec.Name, TxnFieldNames[arg]), nil
}
Expand Down
10 changes: 8 additions & 2 deletions data/transactions/logic/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -3363,8 +3363,14 @@ func (cx *EvalContext) stackIntoTxnField(sv stackValue, fs txnFieldSpec, txn *tr
if err != nil {
return
}
// i != 0 is so that the error reports 0 instead of Unknown
if i != 0 && i < uint64(len(TxnTypeNames)) {
txn.Type = protocol.TxType(TxnTypeNames[i])
txType, ok := innerTxnTypes[TxnTypeNames[i]]
if ok {
txn.Type = txType
} else {
err = fmt.Errorf("%s is not a valid Type for tx_field", TxnTypeNames[i])
}
} else {
err = fmt.Errorf("%d is not a valid TypeEnum", i)
}
Expand Down Expand Up @@ -3405,7 +3411,7 @@ func (cx *EvalContext) stackIntoTxnField(sv stackValue, fs txnFieldSpec, txn *tr
// appl needs to wait. Can't call AVM from AVM.

default:
return fmt.Errorf("invalid txfield %s", fs.field)
return fmt.Errorf("invalid tx_field %s", fs.field)
}
return
}
Expand Down
12 changes: 7 additions & 5 deletions data/transactions/logic/evalAppTxn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ func TestActionTypes(t *testing.T) {
testApp(t, "tx_begin; byte \"afrz\"; tx_field Type; tx_submit; int 1;", ep, "afrz is not a valid Type for tx_field")
testApp(t, "tx_begin; byte \"appl\"; tx_field Type; tx_submit; int 1;", ep, "appl is not a valid Type for tx_field")
// same, as enums
testApp(t, "tx_begin; int keyreg; tx_field TypeEnum; tx_submit; int 1;", ep, "Invalid inner transaction type")
testApp(t, "tx_begin; int acfg; tx_field TypeEnum; tx_submit; int 1;", ep, "Invalid inner transaction type")
testApp(t, "tx_begin; int afrz; tx_field TypeEnum; tx_submit; int 1;", ep, "Invalid inner transaction type")
testApp(t, "tx_begin; int appl; tx_field TypeEnum; tx_submit; int 1;", ep, "Invalid inner transaction type")
testApp(t, "tx_begin; int keyreg; tx_field TypeEnum; tx_submit; int 1;", ep, "keyreg is not a valid Type for tx_field")
testApp(t, "tx_begin; int acfg; tx_field TypeEnum; tx_submit; int 1;", ep, "acfg is not a valid Type for tx_field")
testApp(t, "tx_begin; int afrz; tx_field TypeEnum; tx_submit; int 1;", ep, "afrz is not a valid Type for tx_field")
testApp(t, "tx_begin; int appl; tx_field TypeEnum; tx_submit; int 1;", ep, "appl is not a valid Type for tx_field")
testApp(t, "tx_begin; int 42; tx_field TypeEnum; tx_submit; int 1;", ep, "42 is not a valid TypeEnum")
testApp(t, "tx_begin; int 0; tx_field TypeEnum; tx_submit; int 1;", ep, "0 is not a valid TypeEnum")

// "insufficient balance" because app account is charged fee
// (defaults make these 0 pay|axfer to zero address, from app account)
Expand Down Expand Up @@ -325,7 +327,7 @@ func TestBadField(t *testing.T) {
ep, ledger := makeSampleEnv()
ledger.NewApp(ep.Txn.Txn.Receiver, 888, basics.AppParams{})
testApp(t, "global CurrentApplicationAddress; txn Accounts 1; int 100"+pay, ep,
"invalid txfield RekeyTo")
"invalid tx_field RekeyTo")
}

func TestNumInner(t *testing.T) {
Expand Down

0 comments on commit 04c6b6f

Please sign in to comment.