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

Unable to compute inverse of a scalar while using the Oblivious.ristretto library #8

Closed
rashmibhle opened this issue May 3, 2024 · 4 comments · May be fixed by #10
Closed

Unable to compute inverse of a scalar while using the Oblivious.ristretto library #8

rashmibhle opened this issue May 3, 2024 · 4 comments · May be fixed by #10

Comments

@rashmibhle
Copy link

When I try to find an inverse of a scalar, it doesn't work as expected while using the Oblivious.ristretto library.

I tried couple of variations to test out the discrepancy in the behavior.

Here are few of those instances:

#Some scalar s
s = scalar.hash("s".encode())

The scalars for which I am able to get an inverse:
~(s)
~(s * s)

But, if the scalar is of the form (s + s'), I am not able to get the inverse of it.
It throws - TypeError: bad operand type for unary ~: 'bytes'. I also tried using the inverse() method but that failed to work too.

Surprisingly, this error seems to be localised only within the Oblivious.ristretto library. The Oblivious.bn254 works well and behaves as expected.

We tested out these instances on google colab. Adding python code here for reference.

from oblivious.ristretto import point, scalar

s = scalar.hash(b"123")
m =  scalar.hash(b"456")

#Works
~(s)
~(s*s)

#Doesn't work
~(s+s)
~(s+m)

Do let me know if you need more context.

@wyatt-howe
Copy link
Member

Hi! Thanks for using oblivious!

Good catch. There is not a glitch in the type casting of the scalar that the overloaded scalar + scalar addition method returns, because there isn't such a method to begin with, in Ristretto255. Specifically, oblivious.bn254 supports operating over the full ring of scalars, that is, both additive and multiplicative group operations, while oblivious.ristretto only supports the multiplicative ones.

More clearly, oblivious.ristretto.scalar objects can only be multiplied and inverted (s * s or ~s as you've seen), and doing s + s returns a byte string of length 64 (double the length of a 32-byte, 255-bit scalar) from the byte string concatenation.

It's a good catch because, implicitly casting to bytes and concatenation is not the expected behavior by any means. In the next version, we will either have evaluating the expression s + s raise an exception saying "+ is not implemented yet" or simply implement/bring all of BN254's nice scalar arithmetic that is currently lacking from Ristretto255 into oblivious.ristretto for your use.

@wyatt-howe
Copy link
Member

TL;DR:

Addition of Ristretto255 scalars is not supported

type(s) is oblivious.ristretto.scalar
s + s  # bytes

The above expression actually unexpectedly yeilds a 64-byte-long bytes object which is the concatenation of s, casted to bytes(s), with itself.

Negation of Ristretto255 scalars is also not supported

type(s) is oblivious.ristretto.scalar
-s  # error

@wyatt-howe
Copy link
Member

Moved to #9. Thanks @rashmibhle for raising this discrepancy to our attention.

@rashmibhle
Copy link
Author

rashmibhle commented May 3, 2024 via email

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 a pull request may close this issue.

2 participants