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

add generalized barycentric degree check for degree < 2^l #138

Open
wants to merge 1 commit into
base: master
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
39 changes: 39 additions & 0 deletions barycentric_low_degree_check/barycentric_low_degree_check_pow2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# A generalized low degree check based on Dankrad's check for degree < 2^l
from random import randint, shuffle, choice
from poly_utils import PrimeField

MODULUS = 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001
PRIMITIVE_ROOT = 7

assert pow(PRIMITIVE_ROOT, (MODULUS - 1) // 2, MODULUS) != 1
assert pow(PRIMITIVE_ROOT, MODULUS - 1, MODULUS) == 1

primefield = PrimeField(MODULUS)

WIDTH = 32 # number of evaluations at roots of unity
M = 4 # check degree < M
N = WIDTH // M # number of cosets

ROOT_OF_UNITY = pow(PRIMITIVE_ROOT, (MODULUS - 1) // WIDTH, MODULUS)
DOMAIN = [pow(ROOT_OF_UNITY, i, MODULUS) for i in range(WIDTH)]

def check(f):
r = randint(0, MODULUS)
rm = pow(r, M, MODULUS)
sums = [0] * N

for i in range(WIDTH):
coset_idx = i % N
sums[coset_idx] += primefield.div(f[i] * DOMAIN[i], r - DOMAIN[i])

for i in range(N):
sums[i] = primefield.div(primefield.mul(sums[i], rm - DOMAIN[i * M]), DOMAIN[i * M])

return sums.count(sums[0]) == N

fc = [randint(0, MODULUS) for i in range(M)]
f = [primefield.eval_poly_at(fc, x) for x in DOMAIN]

assert check(f)
f[randint(0, len(f) -1)] += 1
assert not check(f)