Home

Awesome

Basic operations involving big integers - Cairo

WARNING: The latest version of asyncio (>=0.19.0) is not supported. To downgrade do pip install pytest-asyncio==0.18.3

We implement the following libraries:

field_arithmetic

Cairo implementation of operations between elements of a prime field $\mathbb{F}_p$ (i.e. operations modulo a prime p) with p of up to 384 bits. (Note that Cairo's native "integer" is of 251 bits)

The implemented operations are:

uint384

This follows and extends uint256 from Cairo's common library to 384 bits. The usage and logic is almost the same as in uint256. All operations from uint256 are implemented here for 384 bits.

Specifically, a Uint384 represents 384-bit integers with three 128-bit felts. It is important to never use felts larger than this as members of a Uint384.

uint384_extension

This implements some extra functions involving operations between 384-bit integers and 768-bit integers. These are needed in field_arithmetic.cairo (there's some more details below in the technical notes)

Tests

Tests are provided for all functions.

Technical notes

Hints

Most hints were whitelisted on Cairo v0.9.1 (20 Jul 2022). It is possible that some subsequent repo updates use or will use hints which are not whitelisted.