From 2a486745e2ce7a8368eb4ab3ce3132730304a3e8 Mon Sep 17 00:00:00 2001 From: Jacob Rothstein Date: Tue, 20 Sep 2022 12:17:49 -0700 Subject: [PATCH 1/2] =?UTF-8?q?prepare=20message=20=E2=86=92=20prepare=20s?= =?UTF-8?q?tate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/prio3/src/prio3.ts | 44 ++++++++++++++++----------------- packages/vdaf/src/index.spec.ts | 16 ++++++------ packages/vdaf/src/index.ts | 18 +++++++------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/packages/prio3/src/prio3.ts b/packages/prio3/src/prio3.ts index 8fdc4403..7dc66193 100644 --- a/packages/prio3/src/prio3.ts +++ b/packages/prio3/src/prio3.ts @@ -5,7 +5,7 @@ import { Field } from "@divviup/field"; import { Flp } from "./flp"; import { Buffer } from "buffer"; -type PrepareMessage = { +type PrepareState = { outputShare: OutputShare; jointRandSeed: Buffer | null; outboundMessage: Buffer; @@ -17,7 +17,7 @@ type OutputShare = bigint[]; type Prio3Vdaf = Vdaf< Measurement, AggregationParameter, - PrepareMessage, + PrepareState, AggregatorShare, AggregationResult, OutputShare @@ -104,13 +104,13 @@ export class Prio3 implements Prio3Vdaf { return this.encodeShares([leaderShare, ...helperShares]); } - async initialPrepareMessage( + async initialPrepareState( verifyKey: Buffer, aggregatorId: number, _aggParam: AggregationParameter, nonce: Buffer, encodedInputShare: Buffer - ): Promise { + ): Promise { const { prg, flp, field } = this; const share = await this.decodeShare(aggregatorId, encodedInputShare); @@ -164,28 +164,31 @@ export class Prio3 implements Prio3Vdaf { } prepareNext( - prepareMessage: PrepareMessage, + prepareState: PrepareState, inbound: Buffer | null ): - | { prepareMessage: PrepareMessage; prepareShare: Buffer } + | { prepareState: PrepareState; prepareShare: Buffer } | { outputShare: OutputShare } { if (!inbound) { - return { prepareMessage, prepareShare: prepareMessage.outboundMessage }; + return { + prepareState, + prepareShare: prepareState.outboundMessage, + }; } const { verifier, jointRand } = this.decodePrepareMessage(inbound); const jointRandEquality = (jointRand && - prepareMessage.jointRandSeed && - 0 === Buffer.compare(jointRand, prepareMessage.jointRandSeed)) || - jointRand === prepareMessage.jointRandSeed; // both null + prepareState.jointRandSeed && + 0 === Buffer.compare(jointRand, prepareState.jointRandSeed)) || + jointRand === prepareState.jointRandSeed; // both null if (!jointRandEquality || !this.flp.decide(verifier)) { throw new Error("Verify error"); } - return { outputShare: prepareMessage.outputShare }; + return { outputShare: prepareState.outputShare }; } prepSharesToPrepareMessage( @@ -195,19 +198,16 @@ export class Prio3 implements Prio3Vdaf { const { flp, prg, field } = this; const jointRandCheck = Buffer.alloc(prg.seedSize); - const verifier = encodedPrepShares.reduce( - (verifier, encodedPrepMessage) => { - const { verifier: shareVerifier, jointRand: shareJointRand } = - this.decodePrepareMessage(encodedPrepMessage); + const verifier = encodedPrepShares.reduce((verifier, encodedPrepState) => { + const { verifier: shareVerifier, jointRand: shareJointRand } = + this.decodePrepareMessage(encodedPrepState); - if (flp.jointRandLen > 0 && shareJointRand) { - xorInPlace(jointRandCheck, shareJointRand); - } + if (flp.jointRandLen > 0 && shareJointRand) { + xorInPlace(jointRandCheck, shareJointRand); + } - return field.vecAdd(verifier, shareVerifier); - }, - fill(flp.verifierLen, 0n) - ); + return field.vecAdd(verifier, shareVerifier); + }, fill(flp.verifierLen, 0n)); return this.encodePrepareMessage(verifier, jointRandCheck); } diff --git a/packages/vdaf/src/index.spec.ts b/packages/vdaf/src/index.spec.ts index eec99974..5e955cf4 100644 --- a/packages/vdaf/src/index.spec.ts +++ b/packages/vdaf/src/index.spec.ts @@ -1,7 +1,7 @@ import { Field128 } from "@divviup/field"; import { Vdaf, testVdaf } from "."; -type PrepareMessage = { +type PrepareState = { inputRange: { min: number; max: number }; encodedInputShare: Buffer; }; @@ -13,7 +13,7 @@ type Measurement = number; type TestVdaf = Vdaf< Measurement, AggregationParameter, - PrepareMessage, + PrepareState, AggregatorShare, AggregationResult, OutputShare @@ -41,13 +41,13 @@ export class VdafTest implements TestVdaf { ]); } - initialPrepareMessage( + initialPrepareState( _verifyKey: Buffer, _aggregatorId: number, _aggParam: AggregationParameter, _nonce: Buffer, inputShare: Buffer - ): Promise { + ): Promise { return Promise.resolve({ inputRange: this.inputRange, encodedInputShare: inputShare, @@ -55,13 +55,13 @@ export class VdafTest implements TestVdaf { } prepareNext( - prepareMessage: PrepareMessage, + prepareState: PrepareState, inbound: Buffer | null ): - | { prepareMessage: PrepareMessage; prepareShare: Buffer } + | { prepareState: PrepareState; prepareShare: Buffer } | { outputShare: bigint[] } { if (!inbound) { - return { prepareMessage, prepareShare: prepareMessage.encodedInputShare }; + return { prepareState, prepareShare: prepareState.encodedInputShare }; } const measurement = Number(this.field.decode(inbound)[0]); @@ -70,7 +70,7 @@ export class VdafTest implements TestVdaf { throw new Error(`measurement ${measurement} was not in [${min}, ${max})`); } - return { outputShare: this.field.decode(prepareMessage.encodedInputShare) }; + return { outputShare: this.field.decode(prepareState.encodedInputShare) }; } prepSharesToPrepareMessage( diff --git a/packages/vdaf/src/index.ts b/packages/vdaf/src/index.ts index 50fc9487..816f4167 100644 --- a/packages/vdaf/src/index.ts +++ b/packages/vdaf/src/index.ts @@ -8,7 +8,7 @@ export const VDAF_VERSION = "vdaf-01"; export interface Vdaf< Measurement, AggregationParameter, - PrepareMessage, + PrepareState, AggregatorShare, AggregationResult, OutputShare @@ -19,19 +19,19 @@ export interface Vdaf< measurementToInputShares(measurement: Measurement): Promise; - initialPrepareMessage( + initialPrepareState( verifyKey: Buffer, aggId: number, aggParam: AggregationParameter, nonce: Buffer, inputShare: Buffer - ): Promise; + ): Promise; prepareNext( - prepareMessage: PrepareMessage, + prepareState: PrepareState, inbound: Buffer | null ): - | { prepareMessage: PrepareMessage; prepareShare: Buffer } + | { prepareState: PrepareState; prepareShare: Buffer } | { outputShare: OutputShare }; prepSharesToPrepareMessage( @@ -103,7 +103,7 @@ export async function runVdaf( const prepStates: P[] = await Promise.all( arr(vdaf.shares, (aggregatorId) => - vdaf.initialPrepareMessage( + vdaf.initialPrepareState( Buffer.from(verifyKey), aggregatorId, aggregationParameter, @@ -118,10 +118,10 @@ export async function runVdaf( const outbound: Buffer[] = prepStates.map( (state, aggregatorId, states) => { const out = vdaf.prepareNext(state, inbound); - if (!("prepareMessage" in out) || !("prepareShare" in out)) { - throw new Error("expected prepareMessage and prepareShare"); + if (!("prepareState" in out) || !("prepareShare" in out)) { + throw new Error("expected prepareState and prepareShare"); } - states[aggregatorId] = out.prepareMessage; + states[aggregatorId] = out.prepareState; return out.prepareShare; } ); From 86135d989a4ca2c0e1db30655525c338b2a6ef10 Mon Sep 17 00:00:00 2001 From: Jacob Rothstein Date: Mon, 3 Oct 2022 12:36:04 -0700 Subject: [PATCH 2/2] Update packages/prio3/src/prio3.ts Co-authored-by: David Cook --- packages/prio3/src/prio3.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/prio3/src/prio3.ts b/packages/prio3/src/prio3.ts index 7dc66193..9c82abca 100644 --- a/packages/prio3/src/prio3.ts +++ b/packages/prio3/src/prio3.ts @@ -198,9 +198,9 @@ export class Prio3 implements Prio3Vdaf { const { flp, prg, field } = this; const jointRandCheck = Buffer.alloc(prg.seedSize); - const verifier = encodedPrepShares.reduce((verifier, encodedPrepState) => { + const verifier = encodedPrepShares.reduce((verifier, encodedPrepShare) => { const { verifier: shareVerifier, jointRand: shareJointRand } = - this.decodePrepareMessage(encodedPrepState); + this.decodePrepareMessage(encodedPrepShare); if (flp.jointRandLen > 0 && shareJointRand) { xorInPlace(jointRandCheck, shareJointRand);