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

replaceRequirement() method not working as expected #121

Open
zyxyoshine opened this issue Jan 6, 2025 · 0 comments
Open

replaceRequirement() method not working as expected #121

zyxyoshine opened this issue Jan 6, 2025 · 0 comments

Comments

@zyxyoshine
Copy link

There seems to be a bug in the wallet library's VerifiedIdPartialRequest class. (2.0.1-prerelease)
replaceRequirement() method not working as expected.

Symptom

  1. Assume that a VerifiedIdPartialRequest request has a GroupRequirement which contains 2 VerifiedIdRequirement requirements. (id="1", "2").
  2. Try to call request.replaceRequirement("2", ....)
  3. This call will fail (return false) because no VerifiedIdRequirement with id="2" can be found.

Root cause

Image

This method seems to use DFS to support nested GroupRequirement, but the implementation of DFS is wrong:
In the loop "L52: for (i in 0 till requirement.requirements.size)", if requirement[0] is not what we want, it will recursively call replaceRequirement("2", requirement[0], ...) to try to find and replace the target requirement from the child requirement (requirement[0]).
However, if the child call still fails (because requirement[0] is not a GroupRequirement), the function will directly return failure (L58) without continuing to search for the next candidate - requirement[1].
I believe this behavior is not by design.

How to fix

Assuming id is unique or we just need to replace the first one.
Replace L58 with:

if(this.replaceRequirement(id, childRequirement, transformer))
{
    return true
}
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

No branches or pull requests

1 participant