Skip to content

docs(proof): add documentation on terminating the bn128 curve to prevent resource leaks #998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/proof/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Loading