Skip to content

Commit aeefc4d

Browse files
committed
bindings: refactor verifier index
1 parent a987a9c commit aeefc4d

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

src/bindings/crypto/napi-conversion-verifier-index.ts

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { MlArray, MlBool, MlOption } from '../../lib/ml/base.js';
2-
import type * as wasmNamespace from '../compiled/node_bindings/plonk_wasm.cjs';
2+
import type * as napiNamespace from '../compiled/node_bindings/plonk_wasm.cjs';
33
import type {
44
WasmFpDomain,
55
WasmFpLookupSelectors,
@@ -22,17 +22,16 @@ import { Lookup, LookupInfo, LookupSelectors } from './bindings/lookup.js';
2222

2323
export { napiVerifierIndexConversion };
2424

25-
type wasm = typeof wasmNamespace;
25+
type napi = typeof napiNamespace;
2626

27-
type WasmDomain = WasmFpDomain | WasmFqDomain;
28-
type WasmVerificationEvals = WasmFpPlonkVerificationEvals | WasmFqPlonkVerificationEvals;
29-
type WasmShifts = WasmFpShifts | WasmFqShifts;
30-
type WasmVerifierIndex = WasmFpPlonkVerifierIndex | WasmFqPlonkVerifierIndex;
27+
type NapiDomain = WasmFpDomain | WasmFqDomain;
28+
type NapiVerificationEvals = WasmFpPlonkVerificationEvals | WasmFqPlonkVerificationEvals;
29+
type NapiShifts = WasmFpShifts | WasmFqShifts;
30+
type NapiVerifierIndex = WasmFpPlonkVerifierIndex | WasmFqPlonkVerifierIndex;
31+
type NapiLookupVerifierIndex = WasmFpLookupVerifierIndex | WasmFqLookupVerifierIndex;
32+
type NapiLookupSelector = WasmFpLookupSelectors | WasmFqLookupSelectors;
3133

32-
type WasmLookupVerifierIndex = WasmFpLookupVerifierIndex | WasmFqLookupVerifierIndex;
33-
type WasmLookupSelector = WasmFpLookupSelectors | WasmFqLookupSelectors;
34-
35-
type WasmClasses = {
34+
type NapiClasses = {
3635
Domain: typeof WasmFpDomain | typeof WasmFqDomain;
3736
VerificationEvals: typeof WasmFpPlonkVerificationEvals | typeof WasmFqPlonkVerificationEvals;
3837
Shifts: typeof WasmFpShifts | typeof WasmFqShifts;
@@ -63,7 +62,7 @@ function napiVerifierIndexConversion(napi: any, core: ConversionCores) {
6362
}
6463

6564
function verifierIndexConversionPerField(
66-
wasm: wasm,
65+
napi: any,
6766
core: ConversionCore,
6867
{
6968
Domain,
@@ -72,18 +71,16 @@ function verifierIndexConversionPerField(
7271
VerifierIndex,
7372
LookupVerifierIndex,
7473
LookupSelector,
75-
}: WasmClasses
74+
}: NapiClasses
7675
) {
77-
function domainToRust([, logSizeOfGroup, groupGen]: Domain): WasmDomain {
76+
function domainToRust([, logSizeOfGroup, groupGen]: Domain): NapiDomain {
7877
return new Domain(logSizeOfGroup, fieldToRust(groupGen));
7978
}
80-
function domainFromRust(domain: WasmDomain): Domain {
81-
let logSizeOfGroup = domain.log_size_of_group;
82-
let groupGen = fieldFromRust(domain.group_gen);
83-
return [0, logSizeOfGroup, groupGen];
79+
function domainFromRust(domain: NapiDomain): Domain {
80+
return [0, domain.log_size_of_group, fieldFromRust(domain.group_gen)];
8481
}
8582

86-
function verificationEvalsToRust(evals: VerificationEvals): WasmVerificationEvals {
83+
function verificationEvalsToRust(evals: VerificationEvals): NapiVerificationEvals {
8784
let sigmaComm = core.polyCommsToRust(evals[1]);
8885
let coefficientsComm = core.polyCommsToRust(evals[2]);
8986
let genericComm = core.polyCommToRust(evals[3]);
@@ -115,9 +112,7 @@ function verifierIndexConversionPerField(
115112
rotComm as any
116113
);
117114
}
118-
function verificationEvalsFromRust(evals: WasmVerificationEvals): VerificationEvals {
119-
console.log('evals', evals.coefficients_comm);
120-
115+
function verificationEvalsFromRust(evals: NapiVerificationEvals): VerificationEvals {
121116
let mlEvals: VerificationEvals = [
122117
0,
123118
core.polyCommsFromRust(evals.sigma_comm),
@@ -138,7 +133,7 @@ function verifierIndexConversionPerField(
138133
return mlEvals;
139134
}
140135

141-
function lookupVerifierIndexToRust(lookup: Lookup<PolyComm>): WasmLookupVerifierIndex {
136+
function lookupVerifierIndexToRust(lookup: Lookup<PolyComm>): NapiLookupVerifierIndex {
142137
let [
143138
,
144139
joint_lookup_used,
@@ -157,7 +152,7 @@ function verifierIndexConversionPerField(
157152
MlOption.mapFrom(runtime_tables_selector, core.polyCommToRust) as any
158153
);
159154
}
160-
function lookupVerifierIndexFromRust(lookup: WasmLookupVerifierIndex): Lookup<PolyComm> {
155+
function lookupVerifierIndexFromRust(lookup: NapiLookupVerifierIndex): Lookup<PolyComm> {
161156
let mlLookup: Lookup<PolyComm> = [
162157
0,
163158
MlBool(lookup.joint_lookup_used),
@@ -176,15 +171,15 @@ function verifierIndexConversionPerField(
176171
xor,
177172
range_check,
178173
ffmul,
179-
]: LookupSelectors<PolyComm>): WasmLookupSelector {
174+
]: LookupSelectors<PolyComm>): NapiLookupSelector {
180175
return new LookupSelector(
181176
MlOption.mapFrom(xor, core.polyCommToRust) as any,
182177
MlOption.mapFrom(lookup, core.polyCommToRust) as any,
183178
MlOption.mapFrom(range_check, core.polyCommToRust) as any,
184179
MlOption.mapFrom(ffmul, core.polyCommToRust) as any
185180
);
186181
}
187-
function lookupSelectorsFromRust(selector: WasmLookupSelector): LookupSelectors<PolyComm> {
182+
function lookupSelectorsFromRust(selector: NapiLookupSelector): LookupSelectors<PolyComm> {
188183
let lookup = MlOption.mapTo(selector.lookup, core.polyCommFromRust);
189184
let xor = MlOption.mapTo(selector.xor, core.polyCommFromRust);
190185
let range_check = MlOption.mapTo(selector.range_check, core.polyCommFromRust);
@@ -195,18 +190,18 @@ function verifierIndexConversionPerField(
195190
function lookupInfoToRust([, maxPerRow, maxJointSize, features]: LookupInfo): WasmLookupInfo {
196191
let [, patterns, joint_lookup_used, uses_runtime_tables] = features;
197192
let [, xor, lookup, range_check, foreign_field_mul] = patterns;
198-
let wasmPatterns = new wasm.LookupPatterns(
193+
let napiPatterns = new napi.LookupPatterns(
199194
MlBool.from(xor),
200195
MlBool.from(lookup),
201196
MlBool.from(range_check),
202197
MlBool.from(foreign_field_mul)
203198
);
204-
let wasmFeatures = new wasm.LookupFeatures(
205-
wasmPatterns,
199+
let napiFeatures = new napi.LookupFeatures(
200+
napiPatterns,
206201
MlBool.from(joint_lookup_used),
207202
MlBool.from(uses_runtime_tables)
208203
);
209-
return new wasm.LookupInfo(maxPerRow, maxJointSize, wasmFeatures);
204+
return new napi.LookupInfo(maxPerRow, maxJointSize, napiFeatures);
210205
}
211206
function lookupInfoFromRust(info: WasmLookupInfo): LookupInfo {
212207
let features = info.features;
@@ -232,16 +227,16 @@ function verifierIndexConversionPerField(
232227
}
233228

234229
let self = {
235-
shiftsToRust([, ...shifts]: MlArray<Field>): WasmShifts {
230+
shiftsToRust([, ...shifts]: MlArray<Field>): NapiShifts {
236231
let s = shifts.map((s) => fieldToRust(s));
237232
return new Shifts(s[0], s[1], s[2], s[3], s[4], s[5], s[6]);
238233
},
239-
shiftsFromRust(s: WasmShifts): MlArray<Field> {
234+
shiftsFromRust(s: NapiShifts): MlArray<Field> {
240235
let shifts = [s.s0, s.s1, s.s2, s.s3, s.s4, s.s5, s.s6];
241236
return [0, ...shifts.map(fieldFromRust)];
242237
},
243238

244-
verifierIndexToRust(vk: VerifierIndex): WasmVerifierIndex {
239+
verifierIndexToRust(vk: VerifierIndex): NapiVerifierIndex {
245240
let domain = domainToRust(vk[1]);
246241
let maxPolySize = vk[2];
247242
let nPublic = vk[3];
@@ -263,7 +258,8 @@ function verifierIndexConversionPerField(
263258
zkRows
264259
);
265260
},
266-
verifierIndexFromRust(vk: WasmVerifierIndex): VerifierIndex {
261+
verifierIndexFromRust(vk: NapiVerifierIndex): VerifierIndex {
262+
console.log('vk from rust', vk);
267263
let mlVk: VerifierIndex = [
268264
0,
269265
domainFromRust(vk.domain),

0 commit comments

Comments
 (0)