-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
66 additions
and
66 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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,52 @@ | ||
pragma circom 2.1.5; | ||
|
||
include "circomlib/circuits/bitify.circom"; | ||
include "circomlib/circuits/comparators.circom"; | ||
include "circomlib/circuits/poseidon.circom"; | ||
include "./constants.circom"; | ||
|
||
|
||
/// @title PackBytesToInts | ||
/// @notice Converts a byte array into a 31-byte integer array (packing) | ||
/// @param maxBytes: the maximum number of bytes in the input array | ||
/// @input in: the input byte array | ||
/// @output out: the output integer array | ||
template PackBytesToInts(maxBytes) { | ||
var packSize = MAX_BYTES_IN_FIELD(); | ||
|
||
// Calculate number of int chunks based in maxBytes | ||
var remain = maxBytes % packSize; | ||
var maxInts = (maxBytes - remain) / packSize; | ||
if (remain > 0) { | ||
maxInts += 1; | ||
} | ||
|
||
signal input in[maxBytes]; | ||
signal output out[maxInts]; | ||
|
||
signal intSums[maxInts][packSize]; | ||
|
||
for (var i = 0; i < maxInts; i++) { | ||
for(var j=0; j < packSize; j++) { | ||
var idx = packSize * i + j; | ||
|
||
// Copy the previous value if we are out of bounds - we take last item as final result | ||
if(idx >= maxBytes) { | ||
intSums[i][j] <== intSums[i][j-1]; | ||
} | ||
// First item of each chunk is the byte itself | ||
else if (j == 0){ | ||
intSums[i][j] <== bytes[idx]; | ||
} | ||
// Every other item is 256^j * byte | ||
else { | ||
intSums[i][j] <== intSums[i][j-1] + (1 << (8*j)) * bytes[idx]; | ||
} | ||
} | ||
} | ||
|
||
// Last item of each chunk is the final sum | ||
for (var i = 0; i < maxInts; i++) { | ||
ints[i] <== intSums[i][packSize-1]; | ||
} | ||
} |
This file contains 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,14 @@ | ||
pragma circom 2.1.5; | ||
|
||
function EMAIL_ADDR_MAX_BYTES() { | ||
return 256; | ||
} | ||
|
||
function DOMAIN_MAX_BYTES() { | ||
return 255; | ||
} | ||
|
||
// Field support maximum of ~253 bit | ||
function MAX_BYTES_IN_FIELD() { | ||
return 31; | ||
} |