Skip to main content

scryptomath for Python

Why

In more complex Scrypto blueprints you need to calculate your test values against which you want to compare your outputs first. A good approach to achieve that is to calculate them on a higher level without optimisations staying close to the mathematical specification.

This allows you to validate your mathematical specification more easily, including numerical precision boundaries, by investigating and resolving differences in the calculation results between the Scrypto and Python implementations.

Features

Fixed precision decimal types in Python

This library supports you implementing your Python prototype by providing Scrypto decimal types with fixed precision math in Python:

  • Decimal (18 decimal places)
  • PreciseDecimal (36 decimal places)

Currently the following operations are implemented (more can be added):

  • __abs__
  • __add__
  • __sub__
  • __mul__
  • __truediv__ ("normal" division)
  • __pow__ (exact pow result)
  • sqrt() (exact s)
  • powi() (powi implementation Scrypto is using to match results and not identical to result of __pow__)

However, use this wisely if necessary only because depending on the use case you rather want to calculate your test assertion outputs with very high precision (like 500 decimal places) in Python first. That's what we are doing by default for Ociswap and only use the fixed decimal point types if it is required to match the test values.

Disclaimer: if you are using other operations than the ones above a normal Python decimal.Decimal with the full precision you have specified is returned. In that case the return value is not being trimmed down to the fixed decimal places of the Scrypto decimal.

Code generation for decimal constants in Scrypto

Currently, the macros dec! and pdec! can't be used for constants in Scrypto. To workaround that limitation we have implemented Scrypto code generation for initialising decimal constants directly in Scrypto:

>>> from scryptomath import Decimal
>>> Decimal(3).powi(4).scrypto
'Decimal(I192::from_digits([7213023705161793536, 4, 0]))'

Which can be directly used in your Scrypto blueprint like this:

const MY_CONST: Decimal = Decimal(I192::from_digits([7213023705161793536, 4, 0]));

Eventually, we assume Scrypto probably will support compile time macros for dec! and pdec!, but in the meantime this is working very well as a workaround.

Contribute

If you have any requirements for additional data types just open an issue or pull request. Happy to add more :)

Metadata

Release files for scryptomath 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scryptomath 0.0.6
File Size Uploaded Provenance Actions
scryptomath-0.0.6.tar.gz 5.1 kB Without provenance Details for scryptomath-0.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for scryptomath 0.0.6
File Interpreter ABI Platform Actions
scryptomath-0.0.6-py3-none-any.whl Python 3 none any Details for scryptomath-0.0.6-py3-none-any.whl

Total release size: 11.0 kB

Release files / scryptomath-0.0.6.tar.gz

Download URL scryptomath-0.0.6.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4c59936b8548e070aa05822474abae06e482e2317b891ac77ec125eed4a5b0dc
BLAKE2b-256 checksum
How to use checksums
2415de0183efdccfdd468dc04f781217b48fd9af16c158168c4070eb75a5b529
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release files / scryptomath-0.0.6-py3-none-any.whl

Download URL scryptomath-0.0.6-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8602c1482caf36822e104337a743c404eccc846cfb684ed08279fd268d580cbb
BLAKE2b-256 checksum
How to use checksums
c5fe45cc4caf5dbc2a4c84f85b30258fcc90a60047430511e01f4296a0d2d9c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Security for scryptomath 0.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page