algorand / algorand/pyteal

Provide Op Cost method given Expression

Offen
#445 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
new-feature-request Team Scytale
Vorherrschende Sprache
Python
Sterne
288
Forks
138
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.