forked from splix/polkaj
-
Notifications
You must be signed in to change notification settings - Fork 0
Add VRF proof verification / generation to the Schnorrkel wrapper #2
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
902dc1a
feat!: add vrf proof generation / verification
9830030
feat: add test with invalid proof
0ed54f2
fix: fix error in big int to u64-le conversion
015023e
fix: remove deprecated `jar` task
7c267be
chore!: remove a leaked playground main
d48033d
chore: add `final`
2a681be
refactor!: remove `appendU64` from `TranscriptData`
b60ca55
refactor!: proper error handling
2549326
chore: better document hacks
831b64a
meta: add .vscode
27c9864
chore: use `merlin` with `std`
104dc44
chore: add `Cargo.lock` to version control
eb8447c
feat!: rebuild the native lib for all target architectures
9eb60f5
chore: bump minor version
5de8a9f
chore: link tests to where they've been translated from
8b7a76e
style: unify style
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
polkaj-schnorrkel/src/main/java/io/emeraldpay/polkaj/merlin/TranscriptData.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package io.emeraldpay.polkaj.merlin; | ||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.ArrayList; | ||
|
|
||
| /** | ||
| * A container class to simply hold all the necessary input data (label + messages) to construct the actual | ||
| * transcript on Rust's side. Think of this as "the bag of currently necessary arguments". | ||
| * The main idea of this class is to be easily portable to Rust using JNI. | ||
| * It has no usage on its own on the Java side alone. | ||
| */ | ||
| @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection", "FieldCanBeLocal"}) | ||
| public class TranscriptData { | ||
| // INTENTIONALITY: Those fields being of type ArrayList is essential for the JNI mappings on the Rust side | ||
|
|
||
| // HACK: | ||
| // Semantically, the internal representation of the domainSeparationLabel should be a single byte[] | ||
| // Due to an unresolved issue with robusta (the rust lib) though, | ||
| // the field mapping from byte[] doesn't work as expected, so this is the current workaround. | ||
| private final ArrayList<byte[]> domainSeparationLabel; | ||
|
|
||
| private final ArrayList<byte[]> labels; | ||
| private final ArrayList<byte[]> messages; | ||
|
|
||
| public TranscriptData(byte[] domainSeparationLabel) { | ||
| this.domainSeparationLabel = new ArrayList<>(); | ||
| this.domainSeparationLabel.add(domainSeparationLabel); | ||
| this.labels = new ArrayList<>(); | ||
| this.messages = new ArrayList<>(); | ||
| } | ||
|
|
||
| /** | ||
| * Appends an ASCII encoded string message to the transcript with an ASCII encoded string label. | ||
| * @param label the ASCII encoded label | ||
| * @param message the ASCII encoded message | ||
| */ | ||
| public void appendMessage(String label, String message) { | ||
| appendMessage(label, message.getBytes(StandardCharsets.US_ASCII)); | ||
| } | ||
|
|
||
| /** | ||
| * Appends a message to the transcript with an ASCII encoded string label. | ||
| * @param label the ASCII encoded label | ||
| * @param message the actual message (content) | ||
| */ | ||
| public void appendMessage(String label, byte[] message) { | ||
| appendMessage(label.getBytes(StandardCharsets.US_ASCII), message); | ||
| } | ||
|
|
||
| /** | ||
| * Appends a message to the transcript. | ||
| * @param label the label of the message | ||
| * @param message the actual message (content) | ||
| */ | ||
| public void appendMessage(byte[] label, byte[] message) { | ||
| labels.add(label); | ||
| messages.add(message); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
polkaj-schnorrkel/src/main/java/io/emeraldpay/polkaj/schnorrkel/VrfOutputAndProof.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package io.emeraldpay.polkaj.schnorrkel; | ||
|
|
||
| /** | ||
| * Essentially a record to hold the VRF output together with its proof. | ||
| */ | ||
| public class VrfOutputAndProof { | ||
| public static final int OUTPUT_BYTE_LEN = 32; | ||
| public static final int PROOF_BYTE_LEN = 64; | ||
|
|
||
| private final byte[] output; | ||
|
|
||
| private final byte[] proof; | ||
|
|
||
| public static VrfOutputAndProof wrap(byte[] output, byte[] proof) { | ||
| if (output.length != OUTPUT_BYTE_LEN) { | ||
| throw new IllegalArgumentException( | ||
| String.format("VRF output must be %d bytes (compressed ristretto point).", OUTPUT_BYTE_LEN)); | ||
| } | ||
|
|
||
| if (proof.length != PROOF_BYTE_LEN) { | ||
| throw new IllegalArgumentException( | ||
| String.format("VRF proof must be %d bytes (compressed ristretto point).", PROOF_BYTE_LEN)); | ||
| } | ||
|
|
||
| return new VrfOutputAndProof(output, proof); | ||
| } | ||
|
|
||
| private VrfOutputAndProof(byte[] output, byte[] proof) { | ||
| this.output = output; | ||
| this.proof = proof; | ||
| } | ||
|
|
||
| public byte[] getOutput() { | ||
| return output; | ||
| } | ||
|
|
||
| public byte[] getProof() { | ||
| return proof; | ||
| } | ||
| } | ||
Binary file modified
BIN
-122 KB
(98%)
polkaj-schnorrkel/src/main/resources/native/linux/amd/libpolkaj_schnorrkel.so
Binary file not shown.
Binary file modified
BIN
+15.2 MB
(390%)
polkaj-schnorrkel/src/main/resources/native/linux/arm/libpolkaj_schnorrkel.so
Binary file not shown.
Binary file modified
BIN
-196 KB
(96%)
polkaj-schnorrkel/src/main/resources/native/linux/i686/libpolkaj_schnorrkel.so
Binary file not shown.
Binary file modified
BIN
-148 KB
(83%)
polkaj-schnorrkel/src/main/resources/native/macos/amd/libpolkaj_schnorrkel.dylib
Binary file not shown.
Binary file modified
BIN
-155 KB
(83%)
polkaj-schnorrkel/src/main/resources/native/macos/arm/libpolkaj_schnorrkel.dylib
Binary file not shown.
Binary file modified
BIN
-353 KB
(95%)
polkaj-schnorrkel/src/main/resources/native/windows/amd/polkaj_schnorrkel.dll
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1 @@ | ||
| Cargo.lock | ||
| target/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "rust-analyzer.linkedProjects": [ | ||
| "./Cargo.toml" | ||
| ] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.