Skip to content

Commit 43852ba

Browse files
vezenovmTomAFrench
andauthored
fix: remove usage of u1 (#16)
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
1 parent 5e97f97 commit 43852ba

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

src/encoding.nr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ unconstrained fn __split_into_base4_5bit_slices(encoded: Field) -> [u32; 13] {
110110
/// Split an input Field element `e` (known to be 64 bits) into slices that can be efficiently composed to produce inputs to `EncodedChoose`
111111
unconstrained fn __decompose_e(e: Field) -> [u32; 9] {
112112
let mut r: [u32; 9] = [0; 9];
113-
let mut bytes = e.to_le_bytes::<8>();
113+
let bytes = e.to_le_bytes::<8>();
114114
let b8to14 = bytes[1] & 63;
115115
let b14to16 = bytes[1] >> 6;
116116
let b16to18 = bytes[2] & 3;
@@ -142,7 +142,7 @@ unconstrained fn __decompose_e(e: Field) -> [u32; 9] {
142142
/// Split an input Field element `a` (known to be 64 bits) into slices that can be efficiently composed to produce inputs to `EncodedMajority`
143143
unconstrained fn __decompose_a(a: Field) -> [u32; 9] {
144144
let mut r: [u32; 9] = [0; 9];
145-
let mut bytes = a.to_le_bytes::<8>();
145+
let bytes = a.to_le_bytes::<8>();
146146
let b24to28 = bytes[3] & 15;
147147
let b28to32 = bytes[3] >> 4;
148148
let b32to34 = bytes[4] & 3;
@@ -210,7 +210,7 @@ unconstrained fn __decompose_witness(w: Field) -> [u32; 12] {
210210
/// # Cost
211211
/// 40 gates
212212
pub(crate) fn encode_message_extension(w: Field) -> EncodedWitness {
213-
//Safety: split input into slices with the following bit sizes:
213+
// Safety: split input into slices with the following bit sizes:
214214
// 1, 5, 1, 1, 8, 3, 8, 8, 8, 9, 9, 3
215215
// We need to validate the correctness of these slice claims by asserting their sum equals `w`,
216216
// and we also need to validate the bit range of each slice

src/lib.nr

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub fn sha512_compression(_input: INT_BLOCK, _state: STATE) -> STATE {
6464
/// Input is the message to be hashed, produces a 64-byte output
6565
/// The `IS_SHA512` generic is used to toggle whether a SHA384 or SHA512 hash is desired
6666
/// (the only diff between SHA384/SHA512 are different initial starting constants, and the SHA384 hash output is truncated)
67-
fn digest<let N: u32, let IS_SHA512: u1>(msg: [u8; N]) -> [u8; 64] {
67+
fn digest<let N: u32, let IS_SHA512: u8>(msg: [u8; N]) -> [u8; 64] {
6868
// noir-fmt:ignore
6969
let mut h: [u64; 8] = if IS_SHA512 == 1 {
7070
SHA512_INITIAL_HASH_VALUES
@@ -121,7 +121,8 @@ fn digest<let N: u32, let IS_SHA512: u1>(msg: [u8; N]) -> [u8; 64] {
121121
/// The `IS_SHA512` generic is used to toggle whether a SHA384 or SHA512 hash is desired
122122
///
123123
/// (the only diff between SHA384/SHA512 are different initial starting constants, and the SHA384 hash output is truncated)
124-
fn digest_var<let N: u32, let IS_SHA512: u1>(msg: BoundedVec<u8, N>) -> [u8; 64] {
124+
fn digest_var<let N: u32, let IS_SHA512: u8>(msg: BoundedVec<u8, N>) -> [u8; 64] {
125+
std::static_assert(IS_SHA512 <= 1, "IS_SHA512 must be 0 or 1");
125126
// noir-fmt:ignore
126127
let mut h: [u64; 8] = if IS_SHA512 == 1 {
127128
SHA512_INITIAL_HASH_VALUES
@@ -190,11 +191,11 @@ fn digest_var<let N: u32, let IS_SHA512: u1>(msg: BoundedVec<u8, N>) -> [u8; 64]
190191
/// methods here are interface-compatible with sha256 blackbox fns
191192
pub mod sha512 {
192193
pub fn digest<let N: u32>(msg: [u8; N]) -> [u8; 64] {
193-
crate::digest::<_, 1_u1>(msg)
194+
crate::digest::<_, 1_u8>(msg)
194195
}
195196

196197
pub fn sha512_var<let N: u32>(msg: BoundedVec<u8, N>) -> [u8; 64] {
197-
crate::digest_var::<_, 1_u1>(msg)
198+
crate::digest_var::<_, 1_u8>(msg)
198199
}
199200

200201
// Fuzz testing the sha512 implementation
@@ -288,7 +289,7 @@ pub mod sha512 {
288289

289290
pub mod sha384 {
290291
pub fn digest<let N: u32>(msg: [u8; N]) -> [u8; 48] {
291-
let full_result = crate::digest::<_, 0_u1>(msg);
292+
let full_result = crate::digest::<_, 0_u8>(msg);
292293
let mut r: [u8; 48] = [0; 48];
293294
for i in 0..48 {
294295
r[i] = full_result[i];
@@ -297,7 +298,7 @@ pub mod sha384 {
297298
}
298299

299300
pub fn sha384_var<let N: u32>(msg: BoundedVec<u8, N>) -> [u8; 48] {
300-
let full_result = crate::digest_var::<_, 0_u1>(msg);
301+
let full_result = crate::digest_var::<_, 0_u8>(msg);
301302
let mut r: [u8; 48] = [0; 48];
302303
for i in 0..48 {
303304
r[i] = full_result[i];

0 commit comments

Comments
 (0)