algorand / algorand/pyteal

Provide Op Cost method given Expression

Aperta
#445 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
new-feature-request Team Scytale
Lingua principale
Python
Stelle
288
Fork
138
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

## 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

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.