-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1031 from privacy-scaling-explorations/deps/optim…
…isedmt refactor(optimisedmt): remove dependency and implement locally
- Loading branch information
Showing
23 changed files
with
931 additions
and
1,420 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Benchmarks | ||
|
||
on: | ||
push: | ||
branches: [dev] | ||
pull_request: | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: pnpm/action-setup@v2 | ||
with: | ||
version: latest | ||
|
||
- name: Use Node.js 20 | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: "pnpm" | ||
|
||
- name: Install | ||
run: | | ||
pnpm install --frozen-lockfile --prefer-offline | ||
- name: Build | ||
run: | | ||
pnpm build | ||
- name: Benchmarks | ||
run: pnpm benchmarks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,4 +155,6 @@ circuits/circom/test | |
publish | ||
|
||
# typedoc | ||
docs/typedoc/* | ||
docs/typedoc/* | ||
|
||
**/ts/__benchmarks__/results/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import benny from "benny"; | ||
import { Keypair, PCommand } from "maci-domainobjs"; | ||
|
||
import { MaciState } from ".."; | ||
|
||
import { | ||
COORDINATOR_KEYPAIR, | ||
DURATION, | ||
MAX_VALUES, | ||
MESSAGE_BATCH_SIZE, | ||
STATE_TREE_DEPTH, | ||
TREE_DEPTHS, | ||
VOICE_CREDIT_BALANCE, | ||
} from "./utils/constants"; | ||
|
||
const NAME = "maci-core"; | ||
|
||
export default function runCore(): void { | ||
benny.suite( | ||
NAME, | ||
|
||
benny.add(`maci-core - Generate circuit inputs for 10 signups and 50 messages`, () => { | ||
const voteWeight = 9n; | ||
|
||
const users: Keypair[] = []; | ||
|
||
const maciState = new MaciState(STATE_TREE_DEPTH); | ||
// Sign up and vote | ||
for (let i = 0; i < MESSAGE_BATCH_SIZE - 1; i += 1) { | ||
const userKeypair = new Keypair(); | ||
users.push(userKeypair); | ||
|
||
maciState.signUp(userKeypair.pubKey, VOICE_CREDIT_BALANCE, BigInt(Math.floor(Date.now() / 1000))); | ||
} | ||
|
||
const pollId = maciState.deployPoll( | ||
BigInt(Math.floor(Date.now() / 1000) + DURATION), | ||
MAX_VALUES, | ||
TREE_DEPTHS, | ||
MESSAGE_BATCH_SIZE, | ||
COORDINATOR_KEYPAIR, | ||
); | ||
const poll = maciState.polls[pollId]; | ||
|
||
// 24 valid votes | ||
for (let i = 0; i < MESSAGE_BATCH_SIZE - 1; i += 1) { | ||
const userKeypair = users[i]; | ||
|
||
const command = new PCommand( | ||
BigInt(i + 1), | ||
userKeypair.pubKey, | ||
BigInt(i), // vote option index | ||
voteWeight, | ||
1n, | ||
BigInt(pollId), | ||
); | ||
|
||
const signature = command.sign(userKeypair.privKey); | ||
|
||
const ecdhKeypair = new Keypair(); | ||
const sharedKey = Keypair.genEcdhSharedKey(ecdhKeypair.privKey, COORDINATOR_KEYPAIR.pubKey); | ||
const message = command.encrypt(signature, sharedKey); | ||
poll.publishMessage(message, ecdhKeypair.pubKey); | ||
} | ||
|
||
// 24 invalid votes | ||
for (let i = 0; i < MESSAGE_BATCH_SIZE - 1; i += 1) { | ||
const userKeypair = users[i]; | ||
const command = new PCommand( | ||
BigInt(i + 1), | ||
userKeypair.pubKey, | ||
BigInt(i), // vote option index | ||
VOICE_CREDIT_BALANCE * 2n, // invalid vote weight | ||
1n, | ||
BigInt(pollId), | ||
); | ||
|
||
const signature = command.sign(userKeypair.privKey); | ||
|
||
const ecdhKeypair = new Keypair(); | ||
const sharedKey = Keypair.genEcdhSharedKey(ecdhKeypair.privKey, COORDINATOR_KEYPAIR.pubKey); | ||
const message = command.encrypt(signature, sharedKey); | ||
poll.publishMessage(message, ecdhKeypair.pubKey); | ||
} | ||
|
||
// Process messages | ||
poll.processMessages(pollId); | ||
|
||
// Process messages | ||
poll.processMessages(pollId); | ||
|
||
// Test processAllMessages | ||
poll.processAllMessages(); | ||
}), | ||
|
||
benny.cycle(), | ||
benny.complete((results) => { | ||
results.results.forEach((result) => { | ||
// eslint-disable-next-line no-console | ||
console.log(`${result.name}: mean time: ${result.details.mean.toFixed(2)}`); | ||
}); | ||
}), | ||
|
||
benny.save({ folder: "ts/__benchmarks__/results", file: NAME, version: "1.0.0", details: true }), | ||
benny.save({ folder: "ts/__benchmarks__/results", file: NAME, format: "chart.html", details: true }), | ||
benny.save({ folder: "ts/__benchmarks__/results", file: NAME, format: "table.html", details: true }), | ||
); | ||
} | ||
|
||
runCore(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Keypair } from "maci-domainobjs"; | ||
|
||
export const VOICE_CREDIT_BALANCE = 100n; | ||
export const DURATION = 30; | ||
export const MESSAGE_BATCH_SIZE = 25; | ||
export const COORDINATOR_KEYPAIR = new Keypair(); | ||
export const STATE_TREE_DEPTH = 10; | ||
export const MAX_VALUES = { | ||
maxUsers: 25, | ||
maxMessages: 25, | ||
maxVoteOptions: 25, | ||
}; | ||
|
||
export const TREE_DEPTHS = { | ||
intStateTreeDepth: 2, | ||
messageTreeDepth: 3, | ||
messageTreeSubDepth: 2, | ||
voteOptionTreeDepth: 4, | ||
}; |
Oops, something went wrong.