Skip to content

Commit

Permalink
use from_bits_le
Browse files Browse the repository at this point in the history
  • Loading branch information
anstylian committed Jan 21, 2025
1 parent 28c795a commit 8410f2e
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions synthesizer/program/src/logic/instruction/operation/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,21 +266,17 @@ fn to_console_array<N: Network>(hash: &[bool], len: usize, literal_type: Literal
}

fn to_circuit_array_u8<A: circuit::Aleo>(hash: &[circuit::Boolean<A>], len: usize) -> Result<circuit::Plaintext<A>> {
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::<A>::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(),
)
})
Expand All @@ -292,21 +288,17 @@ fn to_circuit_array_u8<A: circuit::Aleo>(hash: &[circuit::Boolean<A>], len: usiz
}

fn to_circuit_array_u16<A: circuit::Aleo>(hash: &[circuit::Boolean<A>], len: usize) -> Result<circuit::Plaintext<A>> {
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::<A>::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(),
)
})
Expand Down

0 comments on commit 8410f2e

Please sign in to comment.