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

Initial work for combine chunked polynomials phase #17

Merged
merged 16 commits into from
Sep 29, 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
90 changes: 81 additions & 9 deletions evm_bridge/src/prover/prover.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Polynomial } from "../polynomial.js"
import { Field, Group, Scalar } from "o1js"
import { PolyComm } from "../poly_commitment/commitment";
import { getLimbs64 } from "../util/bigint";
Expand Down Expand Up @@ -351,29 +352,90 @@ export class ProverProof {
}//
}

export class Context {
/* The [VerifierIndex] associated to the proof */
verifier_index: VerifierIndex

/* The proof to verify */
proof: ProverProof

/* The public input used in the creation of the proof */
public_input: Scalar[]
};

/**
* Polynomial evaluations contained in a `ProverProof`.
* **Chunked evaluations** `Field` is instantiated with vectors with a length that equals the length of the chunk
* **Non chunked evaluations** `Field` is instantiated with a field, so they are single-sized#[serde_as]
*/
export class ProofEvaluations<Evals> {
/* witness polynomials */
w: Array<Evals> // of size 15, total num of registers (columns)
w: Array<Evals> // of size 15, total num of registers (columns)
/* permutation polynomial */
z: Evals
z: Evals
/*
* permutation polynomials
* (PERMUTS-1 evaluations because the last permutation is only used in commitment form)
*/
s: Array<Evals> // of size 7 - 1, total num of wirable registers minus one
s: Array<Evals> // of size 7 - 1, total num of wirable registers minus one
/* coefficient polynomials */
coefficients: Array<Evals> // of size 15, total num of registers (columns)
coefficients: Array<Evals> // of size 15, total num of registers (columns)
/* lookup-related evaluations */
lookup?: LookupEvaluations<Evals>
lookup?: LookupEvaluations<Evals>
/* evaluation of the generic selector polynomial */
genericSelector: Evals
genericSelector: Evals
/* evaluation of the poseidon selector polynomial */
poseidonSelector: Evals
poseidonSelector: Evals

constructor(w: Array<Evals>,
z: Evals, s: Array<Evals>,
coefficients: Array<Evals>,
lookup: LookupEvaluations<Evals>,
genericSelector: Evals,
poseidonSelector: Evals) {
this.w = w;
this.z = z;
this.s = s;
this.coefficients = coefficients;
this.lookup = lookup;
this.genericSelector = genericSelector;
this.poseidonSelector = poseidonSelector;
return this;
}

// TODO: implement this!!!!
/*
Returns a new PointEvaluations struct with the combined evaluations.
*/
combine_point_evaluations(): PointEvaluations<Evals> {
let zeta: Evals = Scalar.from(0) as Evals;
let zetaOmega: Evals = Scalar.from(0) as Evals;

let ret = new PointEvaluations(zeta, zetaOmega);
return ret;
}
/*
pub fn combine(&self, pt: &PointEvaluations<F>) -> ProofEvaluations<PointEvaluations<F>> {
self.map_ref(&|evals| PointEvaluations {
zeta: DensePolynomial::eval_polynomial(&evals.zeta, pt.zeta),
zeta_omega: DensePolynomial::eval_polynomial(&evals.zeta_omega, pt.zeta_omega),
})
}
*/

evaluate_coefficients(point: Scalar): Scalar {
let zero = Scalar.from(0);

let coeffs = this.coefficients.map((value) => value as Scalar);
let p = new Polynomial(coeffs);
if (this.coefficients.length == 0) {
return zero;
}
if (point == zero) {
return this.coefficients[0] as Scalar;
}
return p.evaluate(point);
}
}

/**
Expand All @@ -388,6 +450,11 @@ export class LookupEvaluations<Evals> {
table: Evals
/* runtime table polynomial*/
runtime?: Evals

constructor() {
this.sorted = [];
return this;
}
}

/**
Expand All @@ -398,6 +465,11 @@ export class PointEvaluations<Evals> {
zeta: Evals
/* Evaluation at `zeta . omega`, the product of the challenge point and the group generator */
zetaOmega: Evals

constructor(zeta: Evals, zetaOmega: Evals) {
this.zeta = zeta;
this.zetaOmega = zetaOmega;
}
}

/**
Expand Down Expand Up @@ -445,10 +517,10 @@ export class ScalarChallenge {
a = a.add(a);
b = b.add(b);

const r_2i = getBit(rep_64_limbs, 2*i);
const r_2i = getBit(rep_64_limbs, 2 * i);
const s = r_2i === 0n ? negone : one;

if (getBit(rep_64_limbs, 2*i + 1) === 0n) {
if (getBit(rep_64_limbs, 2 * i + 1) === 0n) {
b = b.add(s);
} else {
a = a.add(s);
Expand Down
29 changes: 17 additions & 12 deletions evm_bridge/src/serde/serde_proof.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Proof, Scalar } from "o1js"
import { PolyComm } from "../poly_commitment/commitment.js";
import { PointEvaluations, ProofEvaluations, ProverCommitments, ProverProof, RecursionChallenge } from "../prover/prover.js"
import { LookupEvaluations, PointEvaluations, ProofEvaluations, ProverCommitments, ProverProof, RecursionChallenge } from "../prover/prover.js"
import { deserPolyComm, PolyCommJSON } from "./serde_index.js";

type PointEvals = PointEvaluations<Scalar[]>;
Expand Down Expand Up @@ -43,7 +43,9 @@ export function deserPointEval(json: PointEvalsJSON): PointEvals {
}
const zeta = json.zeta.map(deserHexScalar);
const zetaOmega = json.zeta_omega.map(deserHexScalar);
return { zeta, zetaOmega };
let ret = new PointEvaluations(zeta, zetaOmega);

return ret;
}

/**
Expand All @@ -64,19 +66,22 @@ export function deserProofEvals(json: ProofEvalsJSON): ProofEvaluations<PointEva
// in the current json, there isn't a non-null lookup, so TS infers that it'll always be null.
let lookup = undefined;
// let lookup = undefined;
// if (json.lookup) {
// const sorted = json.lookup.sorted.map(deserPointEval);
// const [aggreg, table] = [json.lookup.aggreg, json.lookup.table].map(deserPointEval);
// if (json.lookup) {
// const sorted = json.lookup.sorted.map(deserPointEval);
// const [aggreg, table] = [json.lookup.aggreg, json.lookup.table].map(deserPointEval);

// let runtime = undefined;
// if (json.lookup.runtime) {
// runtime = deserPointEval(json.lookup.runtime);
// }

// let runtime = undefined;
// if (json.lookup.runtime) {
// runtime = deserPointEval(json.lookup.runtime);
// }
// lookup = { sorted, aggreg, table, runtime };
// }

// lookup = { sorted, aggreg, table, runtime };
// }
// TODO!!!: fix this
let lookup2 = new LookupEvaluations<PointEvals>();

return { w, z, s, coefficients, lookup, genericSelector, poseidonSelector };
return new ProofEvaluations(w, z, s, coefficients, lookup2, genericSelector, poseidonSelector);
}

export function deserProverCommitments(json: ProverCommitmentsJSON): ProverCommitments {
Expand Down
19 changes: 17 additions & 2 deletions evm_bridge/src/verifier/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,27 @@ export class Batch extends Verifier {

proof.oracles(verifier_index, public_comm, public_input);

return public_comm;

/*
Check the length of evaluations inside the proof.
Commit to the negated public input polynomial.
Run the Fiat-Shamir argument.

Combine the chunked polynomials’ evaluations (TODO: most likely only the quotient polynomial is chunked) with the right powers of $\zeta^n$ and $(\zeta * \omega)^n$.
*/

let original_evals = proof.evals;

//original_evals.combine();

// let evals = proof.evals.combine(&powers_of_eval_points_for_chunks);
//let context = Context {
// verifier_index,
// proof,
// public_input,
//};


/*
Compute the commitment to the linearized polynomial $f$. To do this, add the constraints of all of the gates, of the permutation, and optionally of the lookup. (See the separate sections in the constraints section.) Any polynomial should be replaced by its associated commitment, contained in the verifier index or in the proof, unless a polynomial has its evaluation provided by the proof in which case the evaluation should be used in place of the commitment.
Compute the (chuncked) commitment of $ft$ (see Maller’s optimization).
List the polynomial commitments, and their associated evaluations, that are associated to the aggregated evaluation proof in the proof:
Expand All @@ -46,6 +60,7 @@ export class Batch extends Verifier {
sigma commitments
lookup commitments
*/
return public_comm;
}

/*
Expand Down
Loading