You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While practicing my first snarkjs exercises, I aimed to verify if the proof I possess regarding the pre-image hash of a person's birth date aligns with the hash of this specific date. My approach involved comparing the contents of the 'public.json' file with the hash I computed in Python. However, the values do not match. Could I be making a mistake in my approach? Is it accurate to assume that the computed hash should also be present in the 'public.json' file?
circom circuit
pragma circom 2.0.0;
include "../../circomlib/circuits/sha256/sha256.circom";
// Prove tha that we know a birthday of sha256(birthday)
template Birthday(){
component SHA = Sha256(6);
signal input date[6];
SHA.in <== date;
signal output date_out[256];
date_out <== SHA.out;
}
component main = Birthday();
Python code
importhashlibimportjsondefcalculate_hash(filename):
# Read the entire JSON filewithopen(filename, 'r') asfile:
json_data=file.read()
# Create a SHA-256 hash objecthash_object=hashlib.sha256()
# Update the hash object with the entire JSON (string needs to be encoded to bytes)hash_object.update(json_data.encode())
# Get the hash in hexadecimalhash_hex=hash_object.hexdigest()
# Convert the hexadecimal hash to bitshash_bits=''.join(format(int(c, 16), '04b') forcinhash_hex)
returnhash_bitsdefconcatenate_public_json(filename):
# Read the JSON filewithopen(filename, 'r') asfile:
bits=json.load(file)
# Concatenate the bits into a single stringconcatenated_bits=''.join(bits)
returnconcatenated_bits# JSON file name to read data fromfilename='input.json'public='public.json'hash1=calculate_hash(filename)
hash2=concatenate_public_json(public)
# Compare the two bit sequencesifhash1==hash2:
print("The bit sequences are equal.")
else:
print("The bit sequences are different.")
print("Proof Hash: ", hash1)
print("Calculated Hash: ", hash2)
@vvc-git had exact problem solved it by recognizing sha256.circom works on bit array
convert date to binary array, in typescript following will do
function buffer2bitArray(b: string | any[]) {
const res = [];
for (let i=0; i<b.length; i++) {
for (let j=0; j<8; j++) {
res.push((b[i] >> (7-j) &1));
}
}
return res;
}
put date in and get bit array out
While practicing my first snarkjs exercises, I aimed to verify if the proof I possess regarding the pre-image hash of a person's birth date aligns with the hash of this specific date. My approach involved comparing the contents of the 'public.json' file with the hash I computed in Python. However, the values do not match. Could I be making a mistake in my approach? Is it accurate to assume that the computed hash should also be present in the 'public.json' file?
circom circuit
Python code
input.json
public.json
The text was updated successfully, but these errors were encountered: