Workspace IndexMath › Day 48

Pairings / KZG (Concept) TODO

Math · Day 48 / 52 · December — Cryptography & Information Theory (Day 44-52)

Concept

A pairing is a bilinear map that takes elements from two elliptic curve groups and produces an element in a third group, letting you check a multiplicative relationship between exponents (scalars) just by looking at the group elements. This makes it possible to verify multiplicative relationships between hidden values, and it's the basis for BLS signatures and the verification equations of several proof systems. A KZG commitment commits a single polynomial to one constant-size group element, and lets you open a claim like f(z) = y at any point z with a proof that is also constant size. The principle is that f(X) − y is divisible by (X − z); submitting a commitment to that quotient polynomial as the proof lets the verifier confirm the division relationship with a single pairing check. The cost is that KZG requires a trusted setup that produces a structured reference string, and the fundamental assumption behind this scheme is that a leak of the secret used in that setup would allow forged proofs.

A significant portion of recent Ethereum infrastructure — blob data commitments, rollup proofs, signature aggregation — is built on pairings and polynomial commitments, so you can't read the design docs without the concept; the trusted-setup assumption is also the system's actual trust boundary.

Code & Formula

# 페어링/KZG(개념) — f(X)-f(z)가 (X-z)로 나누어떨어진다는 인수정리가 KZG 증명의 핵심
# 실제 KZG는 이 몫 다항식을 페어링 기반 커밋먼트로 압축하지만, 여기선 그 대수적 뼈대만 GF(p)에서 재현한다.

p = 101  # 작은 소수 유한체

def poly_eval(coeffs, x):
    y = 0
    for c in reversed(coeffs):
        y = (y * x + c) % p
    return y

def poly_sub_const(coeffs, c):
    out = coeffs[:]
    out[0] = (out[0] - c) % p
    return out

def synthetic_division(coeffs, z):
    """(coeffs) / (X - z) 를 합성 나눗셈으로 계산. 몫의 계수와 나머지를 반환."""
    n = len(coeffs)
    quotient = [0] * (n - 1)
    remainder = coeffs[-1]
    for i in range(n - 2, -1, -1):
        quotient[i] = remainder % p
        remainder = (coeffs[i] + remainder * z) % p
    return quotient, remainder

# 예시 다항식 f(X) = 5 + 3X + 2X^2 + X^3  (계수: [5,3,2,1], 상수항이 index 0)
f = [5, 3, 2, 1]
z = 7
y = poly_eval(f, z)
print(f"f(X) = 5 + 3X + 2X^2 + X^3, z={z}  =>  y = f(z) = {y}")

# f(X) - y 는 반드시 (X - z)로 나누어떨어진다 (인수정리)
f_minus_y = poly_sub_const(f, y)
quotient, remainder = synthetic_division(f_minus_y, z)
print(f"몫 다항식 q(X) 계수 = {quotient}, 나머지 = {remainder}  (0이어야 정상)")
assert remainder == 0

# "증명"이 성립함을 재구성으로 검증: q(X)*(X - z) + y 를 다시 펼치면 f(X)와 완전히 같아야 한다
def poly_mul(a, b):
    out = [0] * (len(a) + len(b) - 1)
    for i, ai in enumerate(a):
        for j, bj in enumerate(b):
            out[i + j] = (out[i + j] + ai * bj) % p
    return out

reconstructed = poly_mul(quotient, [(-z) % p, 1])  # (X - z) = [-z, 1]
reconstructed[0] = (reconstructed[0] + y) % p
print("재구성한 f(X) 계수:", reconstructed, " 원본:", f, " 일치:", reconstructed == f)
print("\n실제 KZG는 이 q(X)를 SRS로 만든 상수크기 군 원소로 커밋하고, 검증자는 페어링 한 번으로")
print("commit(f) - y*G1 == commit(q) * (tau - z)*G2 관계를 확인한다 (여기선 다항식 자체로 원리만 재현).")

Exercise

Pick a simple polynomial, actually divide f(X) − f(z) by (X − z) to get the quotient, explain using the factor theorem why the remainder is always zero, and write up why that quotient serves as a proof.

Practical Connection

If Verex posts data to an L2 or aggregates multiple signatures, the cost and trust assumptions of that path ultimately come from pairing-based commitment structures.

If you study this on a given day, add a note link and a ✅ to this line in the source curriculum (docs/knowledge/math-50-curriculum.md) and this spot will lead straight to the note body. You can also write directly on this page — but regenerating overwrites it, so it's safer to keep anything you want to save as markdown under docs/algorithms/.


한국어

페어링/KZG(개념) TODO

Math · Day 48 / 52 · 12월 — 암호학·정보이론 (Day 44–52)

개념

페어링은 두 타원곡선 군의 원소를 받아 세 번째 군의 원소를 내놓는 쌍선형 사상으로, 지수(스칼라)가 곱해지는 관계를 군 원소만 보고 확인할 수 있게 해 준다. 이 성질 덕분에 숨겨진 값들 사이의 곱셈 관계를 검증할 수 있고, BLS 서명이나 여러 증명 시스템의 검증식이 여기에 기반한다. KZG 커밋먼트는 다항식 하나를 상수 크기의 군 원소 하나로 커밋하고, 임의의 점 z에서 f(z)=y라는 사실을 역시 상수 크기의 증명으로 열 수 있게 한다. 원리는 f(X)−y가 (X−z)로 나누어떨어진다는 사실이며, 그 몫 다항식에 대한 커밋먼트를 증명으로 제출하면 검증자가 페어링 한 번으로 나눗셈 관계를 확인한다. 대가로 KZG는 구조화된 참조 문자열을 만드는 신뢰 설정이 필요하고, 그 설정에 쓰인 비밀이 유출되면 거짓 증명을 만들 수 있다는 점이 이 방식의 근본 가정이다.

블롭 데이터 커밋먼트, 롤업 증명, 서명 집계 등 최근 이더리움 인프라의 상당 부분이 페어링과 다항식 커밋먼트 위에 서 있어서, 개념 없이는 설계 문서를 읽을 수 없다. 신뢰 설정 가정은 시스템의 실제 신뢰 경계이기도 하다.

코드 · 수식

# 페어링/KZG(개념) — f(X)-f(z)가 (X-z)로 나누어떨어진다는 인수정리가 KZG 증명의 핵심
# 실제 KZG는 이 몫 다항식을 페어링 기반 커밋먼트로 압축하지만, 여기선 그 대수적 뼈대만 GF(p)에서 재현한다.

p = 101  # 작은 소수 유한체

def poly_eval(coeffs, x):
    y = 0
    for c in reversed(coeffs):
        y = (y * x + c) % p
    return y

def poly_sub_const(coeffs, c):
    out = coeffs[:]
    out[0] = (out[0] - c) % p
    return out

def synthetic_division(coeffs, z):
    """(coeffs) / (X - z) 를 합성 나눗셈으로 계산. 몫의 계수와 나머지를 반환."""
    n = len(coeffs)
    quotient = [0] * (n - 1)
    remainder = coeffs[-1]
    for i in range(n - 2, -1, -1):
        quotient[i] = remainder % p
        remainder = (coeffs[i] + remainder * z) % p
    return quotient, remainder

# 예시 다항식 f(X) = 5 + 3X + 2X^2 + X^3  (계수: [5,3,2,1], 상수항이 index 0)
f = [5, 3, 2, 1]
z = 7
y = poly_eval(f, z)
print(f"f(X) = 5 + 3X + 2X^2 + X^3, z={z}  =>  y = f(z) = {y}")

# f(X) - y 는 반드시 (X - z)로 나누어떨어진다 (인수정리)
f_minus_y = poly_sub_const(f, y)
quotient, remainder = synthetic_division(f_minus_y, z)
print(f"몫 다항식 q(X) 계수 = {quotient}, 나머지 = {remainder}  (0이어야 정상)")
assert remainder == 0

# "증명"이 성립함을 재구성으로 검증: q(X)*(X - z) + y 를 다시 펼치면 f(X)와 완전히 같아야 한다
def poly_mul(a, b):
    out = [0] * (len(a) + len(b) - 1)
    for i, ai in enumerate(a):
        for j, bj in enumerate(b):
            out[i + j] = (out[i + j] + ai * bj) % p
    return out

reconstructed = poly_mul(quotient, [(-z) % p, 1])  # (X - z) = [-z, 1]
reconstructed[0] = (reconstructed[0] + y) % p
print("재구성한 f(X) 계수:", reconstructed, " 원본:", f, " 일치:", reconstructed == f)
print("\n실제 KZG는 이 q(X)를 SRS로 만든 상수크기 군 원소로 커밋하고, 검증자는 페어링 한 번으로")
print("commit(f) - y*G1 == commit(q) * (tau - z)*G2 관계를 확인한다 (여기선 다항식 자체로 원리만 재현).")

연습

작은 다항식 하나를 골라 f(X)−f(z)를 (X−z)로 실제로 나눠 몫을 구하고, 나머지가 항상 0이 되는 이유를 인수정리로 설명한 뒤 그 몫이 왜 증명 역할을 하는지 글로 정리하라.

실무 · Verex 연결

Verex가 L2에 데이터를 올리거나 다수 서명을 집계하는 경로를 쓴다면 그 비용과 신뢰 가정이 결국 페어링 기반 커밋먼트 구조에서 나온다.

공부한 날 원본 커리큘럼(docs/knowledge/math-50-curriculum.md)의 이 줄에 노트 링크와 ✅ 를 붙이면, 이 자리는 노트 본문으로 바로 이어집니다. 노트 없이 이 페이지에 바로 적어도 됩니다 — 다만 다시 생성하면 덮어쓰이므로, 남길 글은 docs/algorithms/ 의 마크다운으로 쓰는 편이 안전합니다.

← 47. 라그랑주 보간 + Reed-Solomon (스레드 A 수확)49. 엔트로피·정보·코딩 →