Is {int,byte}cblock used multiple times?

Hi!

I’m developing a lifter from teal/avm into a SSA representation (the idea is to enable advanced tooling for both developers and auditors). Most operations are relatively simple to implement (given a few constraints that we found are regularly followed like “on basic block mergepoints the stack should have a single height”).

I’m now trying my best at implementing intcblock/bytecblock and friends. A small thing is bothering me though. On every contract i’ve seen on algoexplorer developers just have a single use of these instructions at the start and that use dominates the whole execution.

Would it be wise to cut this corner (for now) and allow usage of intcblock and bytecblock iff the usage dominates the whole execution? From what i’ve seen this is the code that it’s usually generated by pyteal, tealish and friends.

Are there good reasons to use intcblock and bytecblock multiple times on the same contract?

1 Like

Have a look at ARC23 for “Appending application information to the compiled TEAL application”:

This uses a bytecblock to store additional information, but is NOT part of program execution. I’m not aware of TEAL programs that redefine the bytecblock during execution, as the reference algod compile endpoint will not produce this type of AMV bytecode.

2 Likes

Hey mega,

Yes, you can use intcblock and bytecblock multiple times in TEAL, however I’ve never come across any smart contracts that actually do it. If you’re looking to scope some values consider using subroutines (callsub t, retsub) and using the protoframe feature (proto a r), as it give you a stack of arguments which is discarded once you return.

It’s also worth noting though that when reassigning these values debugging becomes harder. In the following example the comments are now wrong and show the incorrect values.

#pragma version 8
intcblock 1 2
bytecblock "one" "two"
b reassign

continue:
  bytec_0
  pop
  bytec_1
  pop
  intc_0
  pop
  intc_1
  pop
  b finish

reassign:
  intcblock 3
  bytecblock "three"
  b continue

finish:
pushint 1
return
goal clerk compile test.teal -o - | goal clerk compile -D -
#pragma version 8
intcblock 1 2
bytecblock 0x6f6e65 0x74776f
b label1
label3:
bytec_0 // "one"
pop
bytec_1 // "two"
pop
intc_0 // 1
pop
intc_1 // 2
pop
b label2
label1:
intcblock 3
bytecblock 0x7468726565
b label3
label2:
pushint 1
return

In fact, this program won’t even succeed, since the second value is no longer available when it continues.

So you can use them multiple times, but I’d be interested in how you’re going to use them.

2 Likes