algorand / algorand/pyteal

Provide general-purpose wide arithmetic (128-bit) API

Abierto
#246 3 comentarios 0 reacciones 1 asignado Reclamado por @PabloLION Ver en GitHub
new-feature-request Team Scytale
Lenguaje dominante
Python
Estrellas
288
Forks
138
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

## Problem

PyTeal's ergonomics for wide arithmetic opcodes (`addw`, `mulw`, `divw`, `divmodw`, `expw`) is limited. Limitation examples:
* No general-purpose way exists to confirm the result of wide arithmetic operations fits into 64 bits. While possible for PyTeal developers to implement, it'd be less error prone PyTeal provided a 1st class facility.
* Here's an example implementing the logic for a special purpose use case:
https://github.com/algorand/pyteal/blob/4594ceacb597ca6e5ae125ab81c1efc783c020c5/pyteal/ast/widemath.py#L127-L136
* No general-purpose abstraction exists for wide arithmetic operations. Consequently, PyTeal developers must hand roll abstractions (e.g. add two 128-bit ints). It feels like a common abstraction can be provided to minimize sources of error and promote application consistency.

## Solution

* Define wide arithmetic abstraction (e.g. `WideUint128`) with these APIs for 64-bit and 128-bit operations:
* \+
* \-
* \*
* /
* mod
* exp
* Consider interactions with existing abstractions (e.g. `WideRatio`).
* Update user guide docs.

Background context:
* https://github.com/algorand/pyteal/issues/101 first introduced specific abstractions like `WideRatio`.
* Subsequent iterations led to https://github.com/algorand/pyteal/pull/236. Since https://github.com/algorand/pyteal/pull/236 moves towards a general-purpose API, it motivated creating this _issue_ to reassess scope.

## Dependencies

N/A

## Urgency

TBD

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.