keep-starknet-strange / garaga

State-of-the-art Elliptic Curve operations and SNARKS verification for Cairo & Starknet 🐺.
MIT License
170 stars 37 forks source link

feat: Implement scalar_to_base_neg3_le in Cairo1 #126

Closed feltroidprime closed 1 month ago

feltroidprime commented 1 month ago

Counting the positive and negative multiplicities of the base (-3) decomposition of a u128 is needed for efficient elliptic curve scalar multiplication.

Implement the Cairo1 version of

https://github.com/keep-starknet-strange/garaga/blob/ecbcf0c0185a4e62b428edbf19b4cc9dbf2cb69c/hydra/hints/neg_3.py#L41-L64

Annotations were added on the python function to help you on the expected types.

FYI, the CairoZero version of it is here https://github.com/keep-starknet-strange/garaga/blob/ecbcf0c0185a4e62b428edbf19b4cc9dbf2cb69c/src/fustat/utils.cairo#L440 where the decomposition in digits happens inside the hint and is verified.

Since it is not possible in Cairo1, you must also implement the following function https://github.com/keep-starknet-strange/garaga/blob/ecbcf0c0185a4e62b428edbf19b4cc9dbf2cb69c/hydra/hints/neg_3.py#L1-L21 then count the positive and negative multiplicities.

However, the CairoZero version may still contains important information or clarifications.

luiz-lvj commented 1 month ago

Hi! I'm working on this issue

feltroidprime commented 1 month ago

closed by #127