From 246801ed35d6487e987e6f7fbe78ffb93a4e1955 Mon Sep 17 00:00:00 2001 From: VolodymyrBg Date: Thu, 23 Oct 2025 01:18:22 +0300 Subject: [PATCH 1/2] docs(proof): add documentation on terminating the bn128 curve to prevent resource leaks (#998) --- packages/proof/README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/proof/README.md b/packages/proof/README.md index 9e49c01c3..696b11764 100644 --- a/packages/proof/README.md +++ b/packages/proof/README.md @@ -116,3 +116,25 @@ import { verifyProof } from "@semaphore-protocol/proof" await verifyProof(proof1) ``` + +## Resource management: Terminating the bn128 curve + +When using the Semaphore proof library in Node.js environments, especially in tests or scripts that create and use the `bn128` curve (for example, via `getCurveFromName("bn128")` from the `ffjavascript` package), it is important to properly release resources associated with the curve after use. Failing to do so can result in leaked handles (such as `MessagePort` handles), which may prevent Node.js from exiting cleanly. This is particularly relevant when running test suites. + +**How to terminate the bn128 curve:** + +If you create a curve instance using `getCurveFromName("bn128")`, you should call its `terminate()` method when you are done with it. For example: + +```typescript +import { getCurveFromName } from "ffjavascript"; + +let curve; +beforeAll(async () => { + curve = await getCurveFromName("bn128"); +}); +afterAll(async () => { + await curve.terminate(); +}); +``` + +This ensures that all resources are properly released and Node.js can exit cleanly after your script or tests finish. From 2ee0d8b95a1224509f0f7d165097cd84e38cc829 Mon Sep 17 00:00:00 2001 From: Vivian Plasencia Date: Thu, 23 Oct 2025 00:19:08 +0200 Subject: [PATCH 2/2] style(proof): format code with prettier --- packages/proof/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/proof/README.md b/packages/proof/README.md index 696b11764..5554cd9ee 100644 --- a/packages/proof/README.md +++ b/packages/proof/README.md @@ -126,15 +126,15 @@ When using the Semaphore proof library in Node.js environments, especially in te If you create a curve instance using `getCurveFromName("bn128")`, you should call its `terminate()` method when you are done with it. For example: ```typescript -import { getCurveFromName } from "ffjavascript"; +import { getCurveFromName } from "ffjavascript" -let curve; +let curve beforeAll(async () => { - curve = await getCurveFromName("bn128"); -}); + curve = await getCurveFromName("bn128") +}) afterAll(async () => { - await curve.terminate(); -}); + await curve.terminate() +}) ``` This ensures that all resources are properly released and Node.js can exit cleanly after your script or tests finish.