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

refactor(poseidon-cipher): simplify nonce validation using Num2Bits #19

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions packages/poseidon-cipher/src/poseidon-cipher.circom
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ include "poseidon-constants-old.circom";
// we import this for util functions like Ark, Mix, Sigma
include "poseidon_old.circom";
include "comparators.circom";
include "bitify.circom";

// Poseidon decryption circuit
// param length: length of the input
Expand Down Expand Up @@ -107,13 +108,9 @@ template PoseidonDecryptIterations(length) {
signal output decrypted[decryptedLength];
signal output decryptedLast;

var two128 = 2 ** 128;

// nonce must be < 2^128
component lt = LessThan(252);
lt.in[0] <== nonce;
lt.in[1] <== two128;
lt.out === 1;
component n2b = Num2Bits(128);
n2b.in <== nonce;
ctrlc03 marked this conversation as resolved.
Show resolved Hide resolved

// calculate the number of iterations
// needed for the decryption
Expand All @@ -133,7 +130,7 @@ template PoseidonDecryptIterations(length) {
strategies[0].inputs[0] <== 0;
strategies[0].inputs[1] <== key[0];
strategies[0].inputs[2] <== key[1];
strategies[0].inputs[3] <== nonce + (length * two128);
strategies[0].inputs[3] <== nonce + (length << 128);

// loop for n iterations
for (var i = 0; i < n; i++) {
Expand Down
Loading