-
Notifications
You must be signed in to change notification settings - Fork 178
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
Expose uncompress and hash_to functions for JVM bindings #232
base: master
Are you sure you want to change the base?
Conversation
This is needed for Java bindings when DST is not a valid Unicode string
As for |
One of the commit messages says "DST as byte array." Is this it? How come? String is the most natural type for DST... |
Yes, I agree.
What seems to happen is that I encode a DST String as SWIG generates code that reads those as UTF-8 encoded, which results in different byte array and thus, different hash/point. There are 3 solutions:
but I don't know how. What do you think? |
What does But in either case, I'd say that there is a 4th option, to perform sensible tests that reflect real life. DST-s are determined at the protocol design stage and it's perfectly reasonable to expect that protocol designers, being humans, would choose printable strings, at least in order to communicate it to coworkers ;-) As for 1. The problem is that it would require corresponding adjustments to all cases where DST is used. Adding just the method in question just in order to pass the test in question begs for the 4th option. As for 2. The referred snippet is for Javascript, not Java. I don't think one can pull off something similar in JNI. At least not with SWIG... Just in case for reference, the conversion to UTF8 stems from SWIG. It should be noted that it's reasonable to expect the conversion to be successful, because as far as I understand Java strings are maintained "printable." In the sense that not-printable byte sequences are replaced with something "printable" like �, i.e. you can't instantiate a String that won't be convertible to UTF8. As for 3. Well, I'm not in position to give you the permission :-) |
And even if it is possible, why would we want to jump through the hoops just to make an arguably non-representative test pass? For reference, as for Javascript, the referred conversion is not DST-specific, it serves multiple purposes. |
Hmmm, I might be wrong... At least things vary with LANG environment variable in jshell... |
My main concert is that In Cardano, If we treat it as I don't like this change either, but what do we do? Ignore it? If we could make sure that Java bindings use ISO-8859-1/Latin1 encoding while encoding/decoding the DST String that would solve the issue all together, I think. |
As for def bls12_381_G1_compress(p: BLS12_381_G1_Element): ByteString
def bls12_381_G1_uncompress(bs: ByteString): BLS12_381_G1_Element I didn't find an obvious way to get those in Java bindings. If you could tell me how to do that I'd much appreciate it. And I'll remove this change from the PR. |
Oh, one more thing. For len(DST) > 255 So essentially, current implementation has this bug for Java (and probably JavaScript as well) |
Ignore what? Suggested modification? I'm not going to merge it, because it doesn't actually make it possible to use the remaining parts of the Java bindings with non-printable DST, but merely makes an arguably non-representative test pass. Or are we talking about ignoring the remote possibility of using non-printable string for DST? I admit I'm resistant to considering it, because I see no indication that it won't result in an unnecessary moving part/dead weight. In other words I'm disputing it, but I don't write it off totally.
On the native side of JNI UTF-8 is all you get, so that a Java String instantiated with ISO-8859-1/Latin1 encoding will be viewed through the UTF-8 lens no matter what. At the same time even .getBytes() from such string varies with LC_CTYPE, i.e. current locale. Indeed, I get
It's not unlike that it would be something else on Windows. In other words forget about ISO-8859-1/Latin1. |
Again, |
You just pass the long DST and blst will take care of it. In other words application is not expected to do something about oversized DSTs. |
uncompress
andhash_to
are not exposed in JVM bindings.This PR exposes those to JVM.
These functions are useful and are used in Cardano and specificly in JVM implementation of Cardano smart contracts VM.