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

implemented bls12_381 built-in primitives #2

Merged
merged 1 commit into from
Feb 16, 2024
Merged
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
52 changes: 32 additions & 20 deletions lib/ak-381/groth16.ak
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
use aiken/builtin.{bls12_381_final_verify, bls12_381_miller_loop}
use aiken.{G1Element, G2Element} // ,MillerLoopResult
use aiken/builtin.{bls12_381_final_verify, bls12_381_miller_loop, bls12_381_g1_scalar_mul, bls12_381_g1_add, bls12_381_mul_miller_loop_result}
use aiken/list.{head, map2, reduce, tail}

type VerificationKey {
pub type VerificationKey {
nPublic: Int,
vkAlpha: List<Int>,
vkBeta: List<List<Int>>,
vkGamma: List<List<Int>>,
vkDelta: List<List<Int>>,
vkAlphaBeta: List<List<List<Int>>>,
vkIC: List<List<Int>>,
vkAlpha: G1Element,
vkBeta: G2Element,
vkGamma: G2Element,
vkDelta: G2Element,
vkAlphaBeta: List<G2Element>,
vkIC: List<G1Element>
}

type Proof {
piA: List<Int>,
piB: List<List<Int>>,
piC: List<Int>,
pub type Proof {
piA: G1Element,
piB: G2Element,
piC: G1Element
}

pub fn pairing(alfa: G1, beta: G2) -> Bool {
todo
pub fn pairing(g1: G1Element, g2: G2Element) {
bls12_381_miller_loop(g1, g2)
}

pub fn groth_verify(
vk: VerificationKey,
proof: Proof,
public: List<Int>,
) -> Bool {
todo
pub fn groth_verify(vk: VerificationKey, proof: Proof, public: List<Int>) -> Bool {
// let n = vk.nPublic

let eAB = pairing(proof.piA, proof.piB)
let eAlphaBeta = pairing(vk.vkAlpha, vk.vkBeta)

expect Some(vkICHead) = head(vk.vkIC)
expect Some(vkICTail) = tail(vk.vkIC)
let derived_vkIC = map2(public, vkICTail, bls12_381_g1_scalar_mul)
let vkI = reduce(derived_vkIC, vkICHead, bls12_381_g1_add)
let eIGamma = pairing(vkI, vk.vkGamma)
let eCDelta = pairing(proof.piC, vk.vkDelta)

let mlr1 = bls12_381_mul_miller_loop_result(eAlphaBeta, eIGamma)
let mlr2 = bls12_381_mul_miller_loop_result(mlr1, eCDelta)
bls12_381_final_verify(eAB, mlr2)
}
Loading