This forum is a read-only archive. Posting, replying and signing in are disabled.

PyTeal opcodes cost (Asserts vs And)

javier0rosas

What is the preferred way to do these checks (in terms of opcode cost and PyTeal style guide):

Multiple Assert's inside a Seq, or a single And opcode with multiple conditions inside it?

This:

Assert( Global.group_size() == Int(1) ),

Assert( Txn.application_args.length() == Int(3) ),

Assert( Txn.accounts.length() == Int(0) ),

vs. this:

And( 

   Global.group_size() == Int(1) ,

   Txn.application_args.length() == Int(3) ,

   Txn.accounts.length() == Int(0) 
)

Thanks in advance.

✔ Solved by fabrice in post #2
fabrice

I prefer the above because I think it’s less error prone from my point of view.

Code size and cost is the same (up to one byte/one cost difference)

✔ Solution
SilentRhetoric

I’ll add that debugging separate Asserts is much easier than when a large And expression has a ton of things on the stack.