diff --git a/packages/circuits/utils/bytes2ints.circom b/packages/circuits/utils/bytes2ints.circom new file mode 100644 index 000000000..29e7fc5a8 --- /dev/null +++ b/packages/circuits/utils/bytes2ints.circom @@ -0,0 +1,41 @@ + +pragma circom 2.1.5; + +include "circomlib/circuits/bitify.circom"; +include "circomlib/circuits/comparators.circom"; +include "circomlib/circuits/poseidon.circom"; +include "./constants.circom"; + +function compute_ints_size(bytes_size) { + var pack_bytes = pack_bytes_const(); + var remain = bytes_size % pack_bytes; + var num_chunk = (bytes_size - remain) / pack_bytes; + if(remain>0) { + num_chunk += 1; + } + return num_chunk; +} + +template Bytes2Ints(bytes_size) { + var num_chunk = compute_ints_size(bytes_size); + signal input bytes[bytes_size]; + signal output ints[num_chunk]; + + var pack_bytes = pack_bytes_const(); + signal ints_sums[num_chunk][pack_bytes]; + for(var i=0; i=bytes_size) { + ints_sums[i][j] <== ints_sums[i][j-1]; + } else if (j==0){ + ints_sums[i][j] <== bytes[idx]; + } else { + ints_sums[i][j] <== ints_sums[i][j-1] + (1<<(8*j)) * bytes[idx]; + } + } + } + for(var i=0; i> 1; + if(k % 2 == 1) { + k2_chunked_size += 1; + } + signal output sign_ints[k2_chunked_size]; + + // signal pubkey_hash_input[k2_chunked_size]; + // for(var i = 0; i < k2_chunked_size; i++) { + // if(i==k2_chunked_size-1 && k2_chunked_size % 2 == 1) { + // pubkey_hash_input[i] <== pubkey[2*i]; + // } else { + // pubkey_hash_input[i] <== pubkey[2*i] + (1<