Skip to content
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

refactor(data): refactor parameter validation using @zk-kit/utils #938

Closed

Conversation

FaezehShakouri
Copy link

@FaezehShakouri FaezehShakouri commented Jan 13, 2025

Description

This pull request replaces the custom checkParameter function with the errorHandlers utility from the @zk-kit/utils package for parameter validation across multiple files. This change improves code consistency and leverages existing utility functions for better error handling.

  • Current Behavior: The code uses a custom function checkParameter to validate parameters.
  • New Behavior: The code now uses errorHandlers.requireString and errorHandlers.requireObject for parameter validation, which provides a more standardized approach to error handling.

Note: Currently, there is no requireBoolean function available in @zk-kit/utils, so we are using requireDefined for parameter validation in the meantime.

Related Issue(s)

Closes #773

Other information

No visual changes are introduced by this PR, as it primarily focuses on refactoring the parameter validation logic.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have run yarn format and yarn lint without getting any errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

cedoor and others added 30 commits March 28, 2024 17:57
…/convert-hex-pk

Convert hexadecimal private key before signing messages
perf(contracts): turn on solidity optimizer
fix: incorrect alias check brought from snarkjs. (possible security vulnerability)
…s/update-code

Update Solidity code to create groups in documentation website
…/baby-jubjub

Add check to make sure Baby Jubjub secret scalar is < l
Don't version control `asdf` and `direnv` configuration files
…/install-circom-deps

ci: fix circom deps installation steps
…/docs

docs: fix `typedoc` compilation warnings
…emaphore-protocol#747)

* chore(proof): bump `@zk-kit/utils` dep

* refactor(proof): use `maybeGetSemaphoreSnarkArtifacts` from `@zk-kit/utils`

Delete logic related to fetching snark artifacts (wasm and zkey files) that was moved to
`@zk-kit/utils`

* revert(proof): add back `requireObject(snarkArtifacts)` check

* chore(proof): update rollup.browser.config.ts

* docs(proof): update README

* chore(proof): remove unused import in rollup.browser.config.ts

* Update packages/proof/package.json

Co-authored-by: Cedoor <[email protected]>

* docs(proof): add links to other repos in proof README

* chore: bump `yarn.lock`

* docs(proof): add punctuation

---------

Co-authored-by: Cedoor <[email protected]>
chore: remove heyauthn package

The heyauthn package was moved to the semaphore-protocol extensions repo.

re semaphore-protocol#752
* chore(docs): format `mdx` files with `remark`

`prettier` doesn't not have proper support for MDX v3.
Docusaurus recommends using `remark` instead.
https://docusaurus.io/docs/markdown-features/react

re semaphore-protocol#503

* chore(docs): add remark lint plugins

* chore: bump yarn.lock

* chore: add `quiet` option to remark
hanghuge and others added 7 commits January 20, 2025 12:43
docs(website): update roadmap on the website
…tocol#945)

* docs: make year update dynamically on website and docs

* docs(docs): make year update dynamically
* broken redirect CONTRIBUTING.md

* typo README.md
)

* chore(subgraph): update matchstick-as dependency

* chore(subgraph): update dependency versions

* ci: update pull request workflow to install libssl1.1 before testing the subgraph

* ci: update pull requests workflow

* ci: update ubuntu version

* ci: update ubuntu version in tests

* ci: update ubuntu version
* Add new article

* Update apps/website/src/data/articles.json

remove referral link

Co-authored-by: Vivian Plasencia <[email protected]>

---------

Co-authored-by: Vivian Plasencia <[email protected]>
Copy link
Member

@vplasencia vplasencia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @FaezehShakouri! Great work! Thank you very much! I just left some comments.

@@ -17,8 +17,8 @@ import {
Provider
} from "ethers/providers"
import { SemaphoreABI } from "@semaphore-protocol/utils/constants"
import { errorHandlers } from "@zk-kit/utils"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { errorHandlers } from "@zk-kit/utils"
import { requireString } from "@zk-kit/utils/error-handlers"

The module can be imported directly. This way it's no longer necessary to use errorHandlers.requireString and requireString can be used directly.


const { members = false, validatedProofs = false } = options

checkParameter(members, "members", "boolean")
checkParameter(validatedProofs, "validatedProofs", "boolean")
// NOTE: There is no function to check if a parameter is a boolean, so currently we are just checking if it is defined or not
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just created a PR to support requireBoolean , see privacy-scaling-explorations/zk-kit#373.

When the new version of the package is ready, this section can be updated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! There is a new version of the @zk-kit/utils package that supports requireBoolean . Feel free to update the version in the project and use the new function.

The packages using the @zk-kit/utils library are: group, identity, proof.

The @zk-kit/utils library should also be added as a dependency to the data package.

@vplasencia
Copy link
Member

vplasencia commented Jan 29, 2025

Hey @FaezehShakouri! Next time, please make sure to ask for the issue first, get it assigned, and then start working on it. Thank you for this PR.

Could you write something in the issue so that we can assign it to you?


const { members = false, validatedProofs = false } = options

checkParameter(members, "members", "boolean")
checkParameter(validatedProofs, "validatedProofs", "boolean")
// NOTE: There is no function to check if a parameter is a boolean, so currently we are just checking if it is defined or not
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! There is a new version of the @zk-kit/utils package that supports requireBoolean . Feel free to update the version in the project and use the new function.

The packages using the @zk-kit/utils library are: group, identity, proof.

The @zk-kit/utils library should also be added as a dependency to the data package.

@@ -1,6 +1,6 @@
import { defaultNetwork, SupportedNetwork } from "@semaphore-protocol/utils/networks"
import { AxiosRequestConfig } from "axios"
import checkParameter from "./checkParameter"
import { errorHandlers } from "@zk-kit/utils"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { errorHandlers } from "@zk-kit/utils"
import { requireString, requireObject, requireBoolean } from "@zk-kit/utils/error-handlers"

Similar to the ethers.ts file, you can use the error-handlers module directly.

Copy link

refactor(data): refactor parameter validation using @zk-kit/utils

Generated at commit: 2ba7e82628a6894ea2cbd928fab98bbf90674dd4

🚨 Report Summary

Severity Level Results
Contracts Critical
High
Medium
Low
Note
Total
0
0
0
4
15
19
Dependencies Critical
High
Medium
Low
Note
Total
0
0
0
0
0
0

For more details view the full report in OpenZeppelin Code Inspector

@FaezehShakouri
Copy link
Author

I'm closing this PR because I accidentally rewrote the commit messages. I will open another PR. Sorry for the inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@semaphore-protocol/data uses utility functions that can be replaced by @zk-kit/utils