PWG
Modify partial witness generator to return 32 bytes
@@ -30,26 +30,14 @@ fn generic_hash_256<D: Digest>(
Some(assignment) => assignment,
};
- // Although we have bits, we need to truncate to bytes as this is the smallest atomic unit
- // for byte based hash functions. Consequence: u4 is seen as u8
- let bytes = assignment.truncate_to_bytes(num_bits);
+ let bytes = assignment.fetch_nearest_bytes(num_bits as usize);
hasher.update(bytes);
}
let result = hasher.finalize();
-
- // Now split the hash result into two 128 bits
- // and store lower and upper into two field elements
- // This behavior is only because the scalar field is 254 bits.
- // XXX: I guess for larger fields, we can make it one field element, but it would be a bit annoying to modify your code based on the field size.
- let (low_128_bytes, high_128_bytes) = result.split_at(16);
- assert_eq!(low_128_bytes.len(), 16);
- assert_eq!(high_128_bytes.len(), 16);
-
- let low_128_field = FieldElement::from_bytes(low_128_bytes);
- let high_128_field = FieldElement::from_bytes(high_128_bytes);
-
- assert_eq!(gadget_call.outputs.len(), 2);
-
- initial_witness.insert(gadget_call.outputs[0], low_128_field);
- initial_witness.insert(gadget_call.outputs[1], high_128_field);
+ for i in 0..32 {
+ initial_witness.insert(
+ gadget_call.outputs[i],
+ FieldElement::from_bytes(&[result[i]]),
+ );
+ }
}
