Teal debugging - Invocation error

I’m getting the following error when debugging atomic transfer with tealdbg:

Debug error: all 1 program(s) failed in less than a second, invocation error?

Atomic transaction consists of 5 grouped transactions. They are approved by Stateful and stateless contract, Bug can be anywhere, so it’s hard to guess what is the problem. Is this some kind of generic error?

What version of TEAL are you using 2 or 3? Can you paste the command you are running? Did all TEAL contracts compile OK?

Teal version 3.
There are 5 transactions grouped together:

Both stateful and stateless compiled fine, but whenever signed grouped txn is sent to the network:

cat signout-0.tx signout-1.tx signout-2.tx signout-3.tx signout-4.tx  > signout.tx
goal clerk rawsend -f signout.tx

getting the whole log of transactions and error, which says: rejected by logic err=stack underflow in &&

Then I run debugger:

goal clerk dryrun -t signout.tx --dryrun-dump  -o dr.msgp
tealdbg debug --remote-debugging-port 1234 stateful.teal -d dr.msgp --group-index 0 &
socat tcp-listen:9392,reuseaddr,fork tcp:localhost:1234

which prints:

2021/05/18 14:08:03 Using proto: https://github.com/algorandfoundation/specs/tree/d050b3cade6d5c664df8bd729bf219f179812595
2021/05/18 14:08:03 Run mode: stateful
2021/05/18 14:08:03 Debug error: all 1 program(s) failed in less than a second, invocation error?

to dive into the problem, I reduced the number of txs to 3. So, I changed the approval program in stateful and stateless as well. After that, was able to run teal debugger. First transaction, which is a call to stateful, passed. Second transaction from the group is asset transfer approved by Escrow contract. Debugger command:

tealdbg debug --remote-debugging-port 12345 escrow.teal -d dr.msgp --group-index 1 & socat tcp-listen:9392,reuseaddr,fork tcp:localhost:12345

Code snippet where execution is paused:

gtxn 0 TypeEnum
int appl // 6
== // 6
&& // Stack has 1, but error: Exception: stack underflow in &&
gtxn 1 TypeEnum
int axfer
==
&&
gtxn 2 TypeEnum
int pay
==
&&

Can’t figure out yet what raises this undeflow error and if this is directly connected to the ‘’ invocation error’ when debugger wasn’t able to run.

Any suggestions are appreciated!

So I believe your error is that you are only supplying one parameter to the && opcode. It requires two.
Change your code to:

gtxn 0 TypeEnum
int appl // 6
== // 6
gtxn 1 TypeEnum
int axfer
==
&&
gtxn 2 TypeEnum
int pay
==
&&

Thanks Jason!

That is correct regarding stack underflow error. I took this code from the stateful contract, where on top of the first check was an additional GroupSize check, which was making the total block a valid code:

global GroupSize // Check atomic transfer group size
int 3
==
gtxn 0 TypeEnum
int appl
==
&&
gtxn 1 TypeEnum
int axfer
==
&&
gtxn 2 TypeEnum
int pay
==
&&

I went back to 5 transaction transfer and got the same error when running tealdbg:

Debug error: all 1 program(s) failed in less than a second, invocation error?

Then, I found more similar bugs for && opcode, fixed them and after that, all went fine. So, it’s a little bit hard to find a bug when the debugger doesn’t start.

Thanks for posting back. I wonder if you would have tried just doing a dryrun what error you would have gotten.

If I just do dryrun, it gives the following:

tx[3] cost=142 trace:
  1 intcblock => <empty stack>
  9 global 0x04 => (5 0x5)
 11 intc_0 => (1 0x1)
 12 == => (0 0x0)
 13 bnz => <empty stack>
 16 intc_1 => (3 0x3)
 17 store 0x0a => <empty stack>
 19 intc_0 => (1 0x1)
 20 store 0x0b => <empty stack>
 22 global 0x04 => (5 0x5)
 24 intc_2 => (5 0x5)
 25 == => (1 0x1)
 26 bnz => <empty stack>
 70 gtxn 0x00 0x10 => (1 0x1)
 73 intc_0 => (1 0x1)
 74 == => (1 0x1)
 75 stack underflow in &&

REJECT
ERROR: stack underflow in &&

Now, that makes sense and is understandable, it indicates which transaction fails tx[3] and the stack flow. So I guess, the first thing to get the information for the error is to use dryrun command without dump. Thanks for your help!

Glad you got it working!