add select hash helper fn

This commit is contained in:
M Alghazwi 2024-12-13 16:37:26 +03:00
parent e5985184df
commit b280a5252c
No known key found for this signature in database
GPG Key ID: 646E567CAD7DB607

View File

@ -89,4 +89,20 @@ pub fn add_assign_hash_out_target<
/// Reads the contents of the specified file and returns them as a vector of bytes using `std::fs::read`.
pub fn read_bytes_from_file<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
fs::read(path)
}
/// select hash helper method
/// Computes `if b { h0 } else { h1 }`.
pub fn select_hash<
F: RichField + Extendable<D> + Poseidon2,
const D: usize,
>(
builder: &mut CircuitBuilder<F, D>,
b: BoolTarget,
h0: HashOutTarget,
h1: HashOutTarget,
) -> HashOutTarget {
HashOutTarget {
elements: core::array::from_fn(|i| builder.select(b, h0.elements[i], h1.elements[i])),
}
}