Skip to content

Commit dc09b4e

Browse files
committed
cleanup
1 parent 0cab5e7 commit dc09b4e

File tree

4 files changed

+13
-110
lines changed

4 files changed

+13
-110
lines changed

packages/contracts/sdk/LobService.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { assert, type AsyncOrSync } from "ts-essentials";
33
import { type PoolERC20 } from "../typechain-types";
44
import { NoteInputStruct } from "../typechain-types/contracts/PoolERC20";
55
import { MpcProverService, type Side } from "./mpc/MpcNetworkService.js";
6-
import { splitInput, splitInput2 } from "./mpc/utils.js";
6+
import { splitInput } from "./mpc/utils.js";
77
import { type ITreesService } from "./RemoteTreesService.js";
88
import {
99
CompleteWaAddress,
@@ -13,6 +13,7 @@ import {
1313
type NoirAndBackend,
1414
type PoolErc20Service,
1515
} from "./RollupService.js";
16+
import { prove } from "./utils.js";
1617

1718
export class LobService {
1819
constructor(
@@ -69,19 +70,15 @@ export class LobService {
6970
randomness: buyerRandomness,
7071
};
7172

72-
const inputPublic = {
73+
const input = {
7374
tree_roots: await this.trees.getTreeRoots(),
74-
};
75-
const input0 = {
7675
seller_secret_key: params.sellerSecretKey,
7776
seller_note: await this.poolErc20.toNoteConsumptionInputs(
7877
params.sellerSecretKey,
7978
params.sellerNote,
8079
),
8180
seller_order,
8281
seller_randomness: sellerRandomness,
83-
};
84-
const input1 = {
8582
buyer_secret_key: params.buyerSecretKey,
8683
buyer_note: await this.poolErc20.toNoteConsumptionInputs(
8784
params.buyerSecretKey,
@@ -90,19 +87,7 @@ export class LobService {
9087
buyer_order,
9188
buyer_randomness: buyerRandomness,
9289
};
93-
const inputs0Shared = await splitInput(swapCircuit.circuit, {
94-
// merge public inputs into first input because it does not matter how public inputs are passed
95-
...input0,
96-
...inputPublic,
97-
});
98-
const inputs1Shared = await splitInput(swapCircuit.circuit, input1);
99-
// const { proof } = await prove("swap", swapCircuit, input);
100-
const { proof } = await this.mpcProver.prove({
101-
circuit: swapCircuit.circuit,
102-
inputs0Shared,
103-
inputs1Shared,
104-
numPublicInputs: 8,
105-
});
90+
const { proof } = await prove("swap", swapCircuit, input);
10691
const noteInputs: [
10792
NoteInputStruct,
10893
NoteInputStruct,
@@ -176,7 +161,7 @@ export class LobService {
176161
tree_roots: await this.trees.getTreeRoots(),
177162
}
178163
: undefined;
179-
const inputsShared = await splitInput2(swapCircuit.circuit, {
164+
const inputsShared = await splitInput(swapCircuit.circuit, {
180165
// merge public inputs into first input because it does not matter how public inputs are passed
181166
...input,
182167
...inputPublic,
@@ -194,7 +179,6 @@ export class LobService {
194179
});
195180
}),
196181
);
197-
console.log("got proofs", proofs.length);
198182
assert(uniq(proofs).length === 1, "proofs mismatch");
199183
const proof = proofs[0]!;
200184
return {

packages/contracts/sdk/mpc/MpcNetworkService.ts

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import type { CompiledCircuit } from "@noir-lang/noir_js";
22
import { ethers } from "ethers";
3-
import { omit, range } from "lodash";
3+
import { omit } from "lodash";
44
import fs from "node:fs";
55
import path from "node:path";
6-
import { assert } from "ts-essentials";
76
import { z } from "zod";
87
import { promiseWithResolvers } from "../utils.js";
98
import { inWorkingDir, makeRunCommand } from "./utils.js";
109

1110
export type OrderId = string & { __brand: "OrderId" };
1211
export type PartyIndex = 0 | 1 | 2;
12+
/**
13+
* Deterministically determined based on the tokens being swapped
14+
*/
1315
export type Side = "seller" | "buyer";
1416

1517
type Order = {
@@ -97,7 +99,6 @@ export class MpcProverService {
9799
input1Shared: inputsShared[1],
98100
numPublicInputs: params.numPublicInputs,
99101
});
100-
console.log("got proof", orderId, params.partyIndex, proof.length);
101102
const proofHex = ethers.hexlify(proof);
102103
order.result.resolve(proofHex);
103104
otherOrder.result.resolve(proofHex);
@@ -166,31 +167,4 @@ export class MpcProverService {
166167
return { proof, publicInputs };
167168
});
168169
}
169-
170-
async prove(params: {
171-
circuit: CompiledCircuit;
172-
inputs0Shared: string[];
173-
inputs1Shared: string[];
174-
// TODO: infer number of public inputs
175-
numPublicInputs: number;
176-
}) {
177-
assert(
178-
params.inputs0Shared.length === params.inputs1Shared.length,
179-
"inputs length mismatch",
180-
);
181-
const proofs = await Promise.all(
182-
range(params.inputs0Shared.length).map(async (i) => {
183-
const input0Shared = params.inputs0Shared[i]!;
184-
const input1Shared = params.inputs1Shared[i]!;
185-
return await this.proveAsParty({
186-
partyIndex: i,
187-
circuit: params.circuit,
188-
input0Shared,
189-
input1Shared,
190-
numPublicInputs: params.numPublicInputs,
191-
});
192-
}),
193-
);
194-
return proofs[0]!;
195-
}
196170
}

packages/contracts/sdk/mpc/run.sh

Lines changed: 0 additions & 47 deletions
This file was deleted.

packages/contracts/sdk/mpc/utils.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import path from "node:path";
66
import toml from "smol-toml";
77
import type { PartyIndex } from "./MpcNetworkService.js";
88

9-
/**
10-
* @deprecated use {@link splitInput2} instead
11-
*/
129
export async function splitInput(circuit: CompiledCircuit, input: InputMap) {
1310
return await inWorkingDir(async (workingDir) => {
1411
const proverPath = path.join(workingDir, "ProverX.toml");
@@ -21,18 +18,13 @@ export async function splitInput(circuit: CompiledCircuit, input: InputMap) {
2118
const x = Uint8Array.from(fs.readFileSync(`${proverPath}.${i}.shared`));
2219
return ethers.hexlify(x);
2320
});
24-
return shared;
21+
return Array.from(shared.entries()).map(([partyIndex, inputShared]) => ({
22+
partyIndex: partyIndex as PartyIndex,
23+
inputShared,
24+
}));
2525
});
2626
}
2727

28-
export async function splitInput2(circuit: CompiledCircuit, input: InputMap) {
29-
const shared = await splitInput(circuit, input);
30-
return Array.from(shared.entries()).map(([partyIndex, inputShared]) => ({
31-
partyIndex: partyIndex as PartyIndex,
32-
inputShared,
33-
}));
34-
}
35-
3628
export async function inWorkingDir<T>(f: (workingDir: string) => Promise<T>) {
3729
const id = crypto.randomUUID();
3830
const workingDir = path.join(__dirname, "work-dirs", id);

0 commit comments

Comments
 (0)