-
Notifications
You must be signed in to change notification settings - Fork 18
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
Re-implement encrypt.circom and poseidon decrypt #45
Conversation
Signed-off-by: Jim Zhang <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #45 +/- ##
==========================================
+ Coverage 73.23% 75.22% +1.99%
==========================================
Files 12 13 +1
Lines 538 553 +15
==========================================
+ Hits 394 416 +22
+ Misses 103 93 -10
- Partials 41 44 +3 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Jim Zhang <[email protected]>
Signed-off-by: Jim Zhang <[email protected]>
Signed-off-by: Jim Zhang <[email protected]>
Signed-off-by: Jim Zhang <[email protected]>
Signed-off-by: Jim Zhang <[email protected]>
Signed-off-by: Jim Zhang <[email protected]>
Signed-off-by: Jim Zhang <[email protected]>
Signed-off-by: Jim Zhang <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the change and the detailed comments! One suggestion on changing -->
to ==>
to ensure the constraints are added correctly, they were missed in previous reviews.
// ensure that the salt fits inside the field of SNARKs | ||
maxRounds := 10 | ||
var e error | ||
for rounds := 0; rounds < maxRounds; rounds++ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why this loop is needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mainly to account for temporary failures due to entropy related errors
go-sdk/internal/utxo/utils.go
Outdated
} | ||
|
||
func NewEncryptionNonce() *big.Int { | ||
max, _ := new(big.Int).SetString("340282366920938463463374607431768211456", 10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be clearer to either add a comment explaining that the number is 2^128 like the node.js version or construct the calculation in code. Also, max
can be a constant
encrypt1.cipherText[0] --> cipherTextReceiver[0]; | ||
encrypt1.cipherText[1] --> cipherTextReceiver[1]; | ||
encrypt1.cipherText[2] --> cipherTextReceiver[2]; | ||
encrypt1.cipherText[3] --> cipherTextReceiver[3]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
encrypt1.cipherText[0] --> cipherTextReceiver[0]; | |
encrypt1.cipherText[1] --> cipherTextReceiver[1]; | |
encrypt1.cipherText[2] --> cipherTextReceiver[2]; | |
encrypt1.cipherText[3] --> cipherTextReceiver[3]; | |
encrypt1.cipherText[0] ==> cipherTextReceiver[0]; | |
encrypt1.cipherText[1] ==> cipherTextReceiver[1]; | |
encrypt1.cipherText[2] ==> cipherTextReceiver[2]; | |
encrypt1.cipherText[3] ==> cipherTextReceiver[3]; |
idx2++; | ||
j3++; | ||
} | ||
encrypt2.cipherText --> cipherTextAuthority; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
encrypt2.cipherText --> cipherTextAuthority; | |
encrypt2.cipherText ==> cipherTextAuthority; |
zkp/circuits/lib/encrypt.circom
Outdated
var l = length; | ||
while (l % 3 != 0) { | ||
l += 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var l = length; | |
while (l % 3 != 0) { | |
l += 1; | |
} | |
var l = length; | |
if (l % 3 != 0) { | |
l += (3 - (l % 3)); | |
} |
I tend to avoid while
loop in other programming languages, thus the suggestion. But I don't know whether this will improve/reduce performance in the circom world.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the coding style. and thanks for suggesting the optimization
state = poseidon(state, 4); | ||
|
||
// Release three elements of the decrypted message | ||
message.push(addMod(ciphertext[i * 3], -state[1])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was confused by the paper which didn't use subtraction for decryption. But I guess it's just the level of details that didn't need to be expressed explicitly
Signed-off-by: Jim Zhang <[email protected]>
thanks @Chengxuan for the detailed reviews. All good comments especially catching the non-verifying assignments to the cipher text outputs 👍 |
So that both the encryption (in circom and js) and decryption (in js) follow the paper closely: https://drive.google.com/file/d/1EVrP3DzoGbmzkRmYnyEDcIQcXVU7GlOd/view
Also added two more circuits, poseidon.circom and poseidon-ex.circom, purely for testing purposes, to ensure that the underlying poseidon templates continue to work as expected.
This PR also eliminates GPL-v3 dependencies from the SDK library (
zkp/js/index
). Some GPL-v3 exists but only used in constructing tests.