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

test(eddsa-poseidon): Targeted tests for compatibility & security of secret scalar modulus #269

Open
artwyman opened this issue Apr 24, 2024 · 3 comments
Assignees
Labels
good first issue Good for newcomers tests 🧪 Adding missing or correcting existing tests

Comments

@artwyman
Copy link
Collaborator

Is your feature request related to a problem? Please describe.

This is a follow-on suggestion to #257 which added mod reduction to secret scalar generation. Existing tests confirm that this results in the same public key for one test case, but nothing to confirm that the default private key used actually causes an overflow. I suggest adding some more targeted test cases for the specific situations and vulnerabilities targeted by this change.

Describe the solution you'd like

A few things I'd suggest for additional test cases:

  • Check that the secret scalar is in the intended range in all tests.
  • Pick multiple secret keys which do and don't cause the overflow targeted here.
  • Pick secret keys tailored to the attack scenario which motivated this (those which cause overflow but result in the same public key). Confirm they result in the same secret scalar now as well.

Describe alternatives you've considered
May be too late for this now, but an approach I've found valuable particularly with security-related bugs is based on TDD. Write a test first which will fail and prove the existence of a security bug. Then make the fix and prove the test now passes.

@artwyman artwyman added the feature 🚀 This is enhancing something existing or creating something new label Apr 24, 2024
@cedoor cedoor added this to ZK-Kit Apr 25, 2024
@cedoor cedoor added tests 🧪 Adding missing or correcting existing tests and removed feature 🚀 This is enhancing something existing or creating something new labels Apr 25, 2024
@cedoor cedoor changed the title eddsa-poseidon: Targeted tests for compatibility & security of secret scalar modulus test(eddsa-poseidon): Targeted tests for compatibility & security of secret scalar modulus Apr 25, 2024
@cedoor cedoor moved this to ♻️ Grooming in ZK-Kit Apr 25, 2024
@cedoor cedoor added the good first issue Good for newcomers label Jun 26, 2024
@ChinoCribioli
Copy link
Contributor

Hey! I can work on a few tests targeting this part of the protocol.

@vplasencia
Copy link
Member

Hey @ChinoCribioli! Thanks. I just assigned the issue to you. Feel free to ask any questions.

@ChinoCribioli
Copy link
Contributor

After giving a thought to the signing algorithm and exploring the codebase, I have 2 things that I don't understand:

  1. The "overflow" (the case in which the secret scalar without taking reminder mod subOrder has 252 bits, while the subOrder has 251 bits) always happens. That's because the pruneBuffer method turns off the most significant bit and turns on the second most significant bit. Therefore, after doing the right shift by 3 bits (to a 256-bit number, which ends up in a 253-bit number), we end up with a secretScalar of strictly 252 bits because we know that the most significant bit is a 0 and the second is a 1. Thus, the "overflow" case doesn't depend on the private key passed. Does this make sense?
  2. I don't see what potential issue could it be with taking remainder modulo subOrder. The secret scalar is only used to then be multiplied to the base point Base8, which has order subOrder. Therefore, the points t * Base8 and (t+k*subOrder)*Base8 will always be the same. The only thing that changes when applying the modulo to the secret scalar is that you save a couple of EC point additions when doing mulPointEscalar(Base8, secretScalar), which is always a benefit if you ask me. What I mean is that the result doesn't change.

Sorry if this is a lot of info, but it is what I could take out after my analysis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers tests 🧪 Adding missing or correcting existing tests
Projects
Status: ♻️ Grooming
Development

No branches or pull requests

4 participants