Provide Op Cost method given Expression
- Dominant language
- Python
- Stars
- 288
- Forks
- 138
- PR merge metrics
- No merged PRs in 30d
Description
## Problem
I want to know how much a given expression should cost for computing how many additional opup requests to make.
Adding another element to the `Op` tuple for `cost` provides a way to get the cost per op and we can use something like
```py
from pyteal import *
options = CompileOptions(mode=Mode.Application, version=6)
def op_cost(tb: TealBlock):
cost = 0
for x in TealBlock.Iterate(tb):
for op in x.ops:
cost += op.op.cost
return cost
tb, _ = Seq(
Assert(Int(1)),
Pop(Int(1)+Int(1)),
).__teal__(options)
print(op_cost(tb)) # 6
```
## Issues with this approach:
- Variable opcode cost by pragma version
- Variable opcode costs by argument (Secp256k1=1700, Secp256r1=2500)
- Things like loops can't be used directly, rather the author should compute the cost of the loop body and multiply it by the number of times it is called at runtime
Contributor guide
Assessment
This issue has not been assessed yet.