Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Sep 17, 2024
1 parent 3467bb1 commit 1b4baea
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -213,25 +213,7 @@ impl<let MaxPaddedBytes: u32, let PaddedChunks: u32, let MaxBytes: u32> StringBo
for i in 0..InputBytes {
body[i] = data[i];
}
StringBody { body, chunks: StringBody::compute_chunks(body), byte_length: length }
}

/**
* @brief given an input byte array, convert into 31-byte chunks
* cost is ~0.5 gates per byte
**/
fn compute_chunks(body: [u8; MaxPaddedBytes]) -> [Field; PaddedChunks] {
let mut chunks: [Field; PaddedChunks] = [0; PaddedChunks];
for i in 0..PaddedChunks {
let mut limb: Field = 0;
for j in 0..31 {
limb *= 256;
limb += body[i * 31 + j] as Field;
}
chunks[i] = limb;
std::as_witness(chunks[i]);
}
chunks
StringBody { body, chunks: compute_chunks(body), byte_length: length }
}

/**
Expand Down Expand Up @@ -419,6 +401,23 @@ impl<let MaxPaddedBytes: u32, let PaddedChunks: u32, let MaxBytes: u32> StringBo
}
}

/// Given an input byte array, convert into 31-byte chunks
///
/// Cost: ~0.5 gates per byte
fn compute_chunks<let MaxPaddedBytes: u32, let PaddedChunks: u32>(body: [u8; MaxPaddedBytes]) -> [Field; PaddedChunks] {
let mut chunks: [Field; PaddedChunks] = [0; PaddedChunks];
for i in 0..PaddedChunks {
let mut limb: Field = 0;
for j in 0..31 {
limb *= 256;
limb += body[i * 31 + j] as Field;
}
chunks[i] = limb;
std::as_witness(chunks[i]);
}
chunks
}

#[test]
fn test() {
let haystack_text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.".as_bytes();
Expand Down

0 comments on commit 1b4baea

Please sign in to comment.