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

Perf: KZG verification in a single point #386

Merged
merged 1 commit into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
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
27 changes: 9 additions & 18 deletions ecc/bls12-377/fr/kzg/kzg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 9 additions & 18 deletions ecc/bls12-378/fr/kzg/kzg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 9 additions & 18 deletions ecc/bls12-381/fr/kzg/kzg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 9 additions & 18 deletions ecc/bls24-315/fr/kzg/kzg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 9 additions & 18 deletions ecc/bls24-317/fr/kzg/kzg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 9 additions & 18 deletions ecc/bn254/fr/kzg/kzg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 9 additions & 18 deletions ecc/bw6-633/fr/kzg/kzg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 9 additions & 18 deletions ecc/bw6-756/fr/kzg/kzg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 9 additions & 18 deletions ecc/bw6-761/fr/kzg/kzg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 9 additions & 17 deletions internal/generator/kzg/template/kzg.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -177,28 +177,20 @@ func Verify(commitment *Digest, proof *OpeningProof, point fr.Element, vk Verify
var negH {{ .CurvePackage }}.G1Affine
negH.Neg(&proof.H)

// [α-a]G₂
var alphaMinusaG2Jac, genG2Jac, alphaG2Jac {{ .CurvePackage }}.G2Jac
// [f(α) - f(a) + a*H(α)]G₁
var totalG1 {{ .CurvePackage }}.G1Jac
var pointBigInt big.Int
point.BigInt(&pointBigInt)
genG2Jac.FromAffine(&vk.G2[0])
alphaG2Jac.FromAffine(&vk.G2[1])
alphaMinusaG2Jac.ScalarMultiplication(&genG2Jac, &pointBigInt).
Neg(&alphaMinusaG2Jac).
AddAssign(&alphaG2Jac)
totalG1.ScalarMultiplicationAffine(&proof.H, &pointBigInt)
totalG1.AddAssign(&fminusfaG1Jac)
var totalG1Aff {{ .CurvePackage }}.G1Affine
totalG1Aff.FromJacobian(&totalG1)

// [α-a]G₂
var xminusaG2Aff {{ .CurvePackage }}.G2Affine
xminusaG2Aff.FromJacobian(&alphaMinusaG2Jac)

// [f(α) - f(a)]G₁
var fminusfaG1Aff {{ .CurvePackage }}.G1Affine
fminusfaG1Aff.FromJacobian(&fminusfaG1Jac)

// e([f(α) - f(a)]G₁, G₂).e([-H(α)]G₁, [α-a]G₂) ==? 1
// e([f(α)-f(a)+aH(α)]G₁], G₂).e([-H(α)]G₁, [α]G₂) == 1
check, err := {{ .CurvePackage }}.PairingCheck(
[]{{ .CurvePackage }}.G1Affine{fminusfaG1Aff, negH},
[]{{ .CurvePackage }}.G2Affine{vk.G2[0], xminusaG2Aff},
[]{{ .CurvePackage }}.G1Affine{totalG1Aff, negH},
[]{{ .CurvePackage }}.G2Affine{vk.G2[0], vk.G2[1]},
)
if err != nil {
return err
Expand Down