コード例 #1
0
ファイル: test_fft.py プロジェクト: zkswap/plonk_tutorial
def test_ifft():
    p = 337
    domain = [FQ(i) for i in [1, 85, 148, 111, 336, 252, 189, 226]]
    poly = [3, 1, 4, 1, 5, 9, 2, 6]
    result = []

    p_x = fft(p, domain, poly)

    result = ifft(p, domain, p_x)

    assert result == poly
コード例 #2
0
ファイル: test_fft.py プロジェクト: zkswap/plonk_tutorial
def test_degree_reduction():
    a = [1, 0, 0, 0, 0, 0, 0, 1]
    b = [0, 1, 0, 0, 0, 0, 0, 0]
    domain = [FQ(i) for i in [1, 85, 148, 111, 336, 252, 189, 226]]
    p = 337

    a_fft = fft(p, domain, a)
    b_fft = fft(p, domain, b)
    c = [a * b for a, b in zip(a_fft, b_fft)]

    res = ifft(p, domain, c)

    assert res == [1, 1, 0, 0, 0, 0, 0, 0]
コード例 #3
0
ファイル: test_fft.py プロジェクト: zkswap/plonk_tutorial
def test_mul_poly():
    # (x + 1) **2
    a = [1, 1, 0, 0, 0, 0, 0, 0]
    b = [1, 1, 0, 0, 0, 0, 0, 0]
    domain = [FQ(i) for i in [1, 85, 148, 111, 336, 252, 189, 226]]
    p = 337

    a_fft = fft(p, domain, a)
    b_fft = fft(p, domain, b)
    c = [a * b for a, b in zip(a_fft, b_fft)]

    res = ifft(p, domain, c)
    assert res == [1, 2, 1, 0, 0, 0, 0, 0]
コード例 #4
0
ファイル: test_fft.py プロジェクト: zkswap/plonk_tutorial
def test_poly_add():
    a = [1, 1, 0, 0, 0, 0, 0, 0]
    b = [1, 1, 0, 0, 0, 0, 0, 0]
    domain = [FQ(i) for i in [1, 85, 148, 111, 336, 252, 189, 226]]
    p = 337

    a_fft = fft(p, domain, a)
    b_fft = fft(p, domain, b)
    c = [a * b for a, b in zip(a_fft, b_fft)]

    c = [a + b for a, b in zip(c, a_fft)]

    res = ifft(p, domain, c)

    assert res == [2, 3, 1, 0, 0, 0, 0, 0]
コード例 #5
0
ファイル: test_fft.py プロジェクト: zkswap/plonk_tutorial
def test_constant_add():
    a = [1, 1, 0, 0, 0, 0, 0, 0]
    b = [1, 1, 0, 0, 0, 0, 0, 0]
    domain = [FQ(i) for i in [1, 85, 148, 111, 336, 252, 189, 226]]
    p = 337

    constant = 330

    a_fft = fft(p, domain, a)
    b_fft = fft(p, domain, b)
    c = [a * b for a, b in zip(a_fft, b_fft)]

    c = [a + constant for a in c]

    res = ifft(p, domain, c)

    assert res == [331, 2, 1, 0, 0, 0, 0, 0]
コード例 #6
0
ファイル: test_fft.py プロジェクト: zkswap/plonk_tutorial
def test_mul():
    a = [3, 5, 2, 1, 0, 0, 0, 0]
    b = [5, 9, 8, 1, 0, 0, 0, 0]
    domain = [FQ(i) for i in [1, 85, 148, 111, 336, 252, 189, 226]]
    p = 337

    a_fft = fft(p, domain, a)
    b_fft = fft(p, domain, b)

    a_b_fft = [a * b for a, b in zip(a_fft, b_fft)]
    res = ifft(p, domain, a_b_fft)
    for i, x in enumerate(res):
        res[i] = x % 10
        if int(x / 10) != 0:
            res[i + 1] += int(x / 10)

    assert res == [5, 3, 4, 4, 7, 3, 2, 0]