diff --git a/apps/benchmarks/package.json b/apps/benchmarks/package.json index 73f9c33..c178027 100644 --- a/apps/benchmarks/package.json +++ b/apps/benchmarks/package.json @@ -12,9 +12,10 @@ "@chakra-ui/react": "^2.6.1", "@emotion/react": "^11.11.0", "@emotion/styled": "^11.11.0", - "@semaphore-protocol/group": "^3.15.0", - "@semaphore-protocol/identity": "^3.15.0", - "@semaphore-protocol/proof": "^3.15.0", + "@semaphore-protocol/core": "4.0.0-beta.9", + "@semaphore-protocol/group": "3.15.2", + "@semaphore-protocol/identity": "3.15.2", + "@semaphore-protocol/proof": "3.15.2", "buffer": "^6.0.3", "events": "^3.3.0", "framer-motion": "^10.12.12", diff --git a/apps/benchmarks/src/App.tsx b/apps/benchmarks/src/App.tsx index 7e5d2fa..88e15be 100644 --- a/apps/benchmarks/src/App.tsx +++ b/apps/benchmarks/src/App.tsx @@ -1,6 +1,7 @@ -import { Box, Button, Flex, List, ListIcon, ListItem, Text } from "@chakra-ui/react" +import { Box, Button, Flex, Heading, List, ListIcon, ListItem, Text } from "@chakra-ui/react" import { Group } from "@semaphore-protocol/group" import { Identity } from "@semaphore-protocol/identity" +import * as V4 from "@semaphore-protocol/core" import { generateProof, verifyProof } from "@semaphore-protocol/proof" import { useCallback, useState } from "react" import { MdCheckCircle } from "react-icons/md" @@ -11,9 +12,11 @@ import TreeDepth from "./components/TreeDepth" const functions = ["new Identity", "new Group", "generateProof", "verifyProof", "addMember", "updateMember"] function App() { - const [treeDepth, setTreeDepth] = useState(20) - const [groupMembers, setGroupMembers] = useState(100) - const [times, setTimes] = useState([]) + const [v3treeDepth, setV3TreeDepth] = useState(20) + const [v3GroupMembers, setV3GroupMembers] = useState(100) + const [v4GroupMembers, setV4GroupMembers] = useState(100) + const [v3Times, setV3Times] = useState([]) + const [v4Times, setV4Times] = useState([]) async function run(callback: () => any): Promise<[any, number]> { const t0 = performance.now() @@ -25,35 +28,35 @@ function App() { return [result, t1 - t0] } - const runFunctions = useCallback(async () => { + const runV3Functions = useCallback(async () => { const timeValues = [] const [identity, time0] = await run(() => new Identity()) timeValues.push(time0) - setTimes(timeValues) + setV3Times(timeValues) - let members = Array.from(Array(groupMembers - 1).keys()) + let members = Array.from(Array(v3GroupMembers - 1).keys()) members = [...members, identity.commitment] - const [group, time1] = await run(() => new Group(1, treeDepth, members)) + const [group, time1] = await run(() => new Group(1, v3treeDepth, members)) timeValues.push(time1) - setTimes(timeValues.slice()) + setV3Times(timeValues.slice()) const [proof, time2] = await run(async () => generateProof(identity, group, 1, 1)) timeValues.push(time2) - setTimes(timeValues.slice()) + setV3Times(timeValues.slice()) - const [, time3] = await run(async () => verifyProof(proof, treeDepth)) + const [, time3] = await run(async () => verifyProof(proof, v3treeDepth)) timeValues.push(time3) - setTimes(timeValues.slice()) + setV3Times(timeValues.slice()) const [, time4] = await run(() => { group.addMember(1) @@ -61,7 +64,7 @@ function App() { timeValues.push(time4) - setTimes(timeValues.slice()) + setV3Times(timeValues.slice()) const [, time5] = await run(() => { group.updateMember(0, 1) @@ -69,34 +72,111 @@ function App() { timeValues.push(time5) - setTimes(timeValues.slice()) - }, [treeDepth, groupMembers]) + setV3Times(timeValues.slice()) + }, [v3treeDepth, v3GroupMembers]) + + const runV4Functions = useCallback(async () => { + const timeValues = [] + + const [identity, time0] = await run(() => new V4.Identity()) + + timeValues.push(time0) + + setV4Times(timeValues) + + let members = Array.from(Array(v3GroupMembers - 1).keys()).map((m) => BigInt(m) + 1n) + members = [...members, identity.commitment] + + const [group, time1] = await run(() => new V4.Group(members)) + + timeValues.push(time1) + + setV4Times(timeValues.slice()) + + const [proof, time2] = await run(async () => V4.generateProof(identity, group, 1, 1)) + + timeValues.push(time2) + + setV4Times(timeValues.slice()) + + const [, time3] = await run(async () => V4.verifyProof(proof)) + + timeValues.push(time3) + + setV4Times(timeValues.slice()) + + const [, time4] = await run(() => { + group.addMember(1) + }) + + timeValues.push(time4) + + setV4Times(timeValues.slice()) + + const [, time5] = await run(() => { + group.updateMember(0, 2n) + }) + + timeValues.push(time5) + + setV4Times(timeValues.slice()) + }, [v4GroupMembers]) return ( - - - - - - - - {functions.map((f, i) => ( - - - - {times[i] && } - {f} - - {times[i] ? times[i] : 0} ms - - - ))} - + + + + Semaphore v3 + + + + + + + + {functions.map((f, i) => ( + + + + {v3Times[i] && } + {f} + + {v3Times[i] ? v3Times[i] : 0} ms + + + ))} + + + + + Semaphore v4 + + + + + + + + {functions.map((f, i) => ( + + + + {v4Times[i] && } + {f} + + {v4Times[i] ? v4Times[i] : 0} ms + + + ))} + + diff --git a/apps/benchmarks/src/components/Navbar.tsx b/apps/benchmarks/src/components/Navbar.tsx index 55e01fd..dd8acf5 100644 --- a/apps/benchmarks/src/components/Navbar.tsx +++ b/apps/benchmarks/src/components/Navbar.tsx @@ -7,7 +7,7 @@ export default function Navbar() { - +