a
��tb+ � @ s� d dl mZ d dlZd dlZd dlmZ eeef Zeed�dd�Z eee
d�dd �Zeeed�d
d�Zeeeed�d
d�Z
eeeed�dd�Zeeed�dd�Zeeeed�dd�Zeeeeed�dd�ZdS )� )�TupleN��igcdex)�digits�returnc C s | t j_dtt jj�dd� S )zX
Returns pi as a string of decimal digits without the decimal point ("314...").
�3� N)�mpmath�mpZdps�str�pi)r � r
��/Users/okudajunta/Library/Mobile Documents/com~apple~CloudDocs/solidity/dydx-v3-rust/./src/stark/starkex/starkex_resources/math_utils.py�pi_as_string s r )�n�pr c C s t �| |�S )z9
Returns True if n is a quadratic residue mod p.
)�sympy�is_quad_residue�r r r
r
r r $ s r c C s t tj| |dd��S )zG
Finds the minimum positive integer m such that (m*m) % p == n
T)Z all_roots)�minr �sqrt_modr r
r
r r + s r )r �mr r c C s( t ||�\}}}|dksJ �| | | S )zK
Finds a nonnegative integer 0 <= x < p such that (m * x) % p == n
� r )r r r �a�b�cr
r
r �div_mod2 s r )�point1�point2r r c C s� | d |d | dksJ �t | d |d | d |d |�}|| | d |d | }|| d | | d | }||fS )z�
Gets two points on an elliptic curve mod p and returns their sum.
Assumes the points are given in affine form (x, y) and have different x coordinates.
r r �r )r r r r �x�yr
r
r �ec_add; s
$r"