From 8410f2e26df0b71dd368a3d5613717af60a40c0b Mon Sep 17 00:00:00 2001 From: Angelos Stylianidis Date: Tue, 21 Jan 2025 23:40:01 +0200 Subject: [PATCH] use from_bits_le --- .../src/logic/instruction/operation/hash.rs | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/synthesizer/program/src/logic/instruction/operation/hash.rs b/synthesizer/program/src/logic/instruction/operation/hash.rs index 88a154fdc2..6018cec956 100644 --- a/synthesizer/program/src/logic/instruction/operation/hash.rs +++ b/synthesizer/program/src/logic/instruction/operation/hash.rs @@ -266,21 +266,17 @@ fn to_console_array(hash: &[bool], len: usize, literal_type: Literal } fn to_circuit_array_u8(hash: &[circuit::Boolean], len: usize) -> Result> { - use circuit::{Eject, Inject}; + use circuit::traits::FromBits; ensure!(hash.len() % 8 == 0, "Expected hash length to be a multiple of 8, but found {}", hash.len()); let hash: Vec<_> = hash .chunks(8) .map(|element| { - let value = element - .iter() - .enumerate() - .fold(0, |acc, (i, bit)| if bit.eject_value() { acc | (1 << i) } else { acc }); + let value = circuit::types::U8::::from_bits_le(element); - let value = console::types::U8::new(value); circuit::Plaintext::Literal( - circuit::Literal::U8(circuit::types::U8::new(element.eject_mode(), value)), + circuit::Literal::U8(value), Default::default(), ) }) @@ -292,21 +288,17 @@ fn to_circuit_array_u8(hash: &[circuit::Boolean], len: usiz } fn to_circuit_array_u16(hash: &[circuit::Boolean], len: usize) -> Result> { - use circuit::{Eject, Inject}; + use circuit::traits::FromBits; ensure!(hash.len() % 16 == 0, "Expected hash length to be a multiple of 16, but found {}", hash.len()); let hash: Vec<_> = hash .chunks(16) .map(|element| { - let value = element - .iter() - .enumerate() - .fold(0, |acc, (i, bit)| if bit.eject_value() { acc | (1 << i) } else { acc }); + let value = circuit::types::U16::::from_bits_le(element); - let value = console::types::U16::new(value); circuit::Plaintext::Literal( - circuit::Literal::U16(circuit::types::U16::new(element.eject_mode(), value)), + circuit::Literal::U16(value), Default::default(), ) })