PyTeal opcodes cost (Asserts vs And) - General - Algorand
PyTeal opcodes cost (Asserts vs And)
post by javier0rosas on Apr 8, 2022
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.
post by fabrice on Apr 8, 2022
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)
post by SilentRhetoric on Apr 8, 2022
I’ll add that debugging separate Asserts is much easier than when a large And expression has a ton of things on the stack.