Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fix in sqrt #383

Open
wants to merge 2 commits into
base: develop-feijoa
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions main/ecrecover/FPSECP256K1/sqrtFpSecp256k1.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,33 @@
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

VAR GLOBAL _input

; RESOURCES:
; with sqrt: 1 arith + 1 binary + 7 steps
; without sqrt: 1 binary + 4 steps
; TOTAL (worst case): 1 arith + 1 binary + 7 steps

sqrtFpSecp256k1:
C => _input

; start by free-inputing the square root of the input C
; taking the positive one if A = 1, and the negative one if A = 0
${var _sqrtFpSecp256k1_sqrt = sqrtFpEcParity(C,A)} => A
${sqrtFpEcParity(C,A)} => A

; In this point we check whether A is LT than SECP256K1_P since, otherwise, either:
; a) A doesn't have square root. 1 is returned in C.
; b) A contains an alias, it's a MAP. 1 is returned in C. In this case, the proof cannot
; be generated because we check in assertNQRFpSecp256k1 if the root actually exists.
%SECP256K1_P => B
$ :LT, JMPNC(sqrtFpSecp256k1_NoRoot)
$ :LT, JMPNC(sqrtFpSecp256k1_NoRoot)
; From here, A,C < SECP256K1_P, which means that the root exists and it's alias-free

; √C·√C + 0 = C (mod SECP256K1_P)
A => B
0 => C
%SECP256K1_P => D
${(A*B) % D} => E :ARITH_MOD, RETURN
${(A*B) % D} :ARITH_MOD, MLOAD(_input), RETURN

sqrtFpSecp256k1_NoRoot:
1 => C :RETURN
1 => C :RETURN
Loading