Skip to content

Commit 06aa361

Browse files
zac-williamsonKhashayar Barooti
andauthored
feat: remove redundant additions (#6)
Co-authored-by: Khashayar Barooti <khashayar.baroot@epfl.ch>
1 parent 3e89813 commit 06aa361

8 files changed

Lines changed: 1320 additions & 1405 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ with the following command.
2121

2222
The benchmark will be generated at `./gates_report.json`.
2323

24+
Current benchmarks as of 1 Mar 2025
25+
26+
| num blocks hashed | num bytes hashed | gates for `sha512::hash` | gates for `sha512::digest_var` |
27+
| --- | --- | --- | --- |
28+
| 1 block | 111 | 39,476 | 41,261 |
29+
| 2 blocks | 239 ||66,927 | 69,816 |
30+
| 3 blocks | 367 | 94,377 | 98,355 |
31+
| 4 blocks | 495 | 121,826 | 126,914 |
32+
2433
## Installation
2534

2635
In your _Nargo.toml_ file, add the version of this library you would like to install under dependency:

src/benchmarks/mod.nr

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,52 @@
1-
use crate::permutation::digest;
2-
3-
// compression benchmark is 41924
4-
// NOTE: does this align with expectations? Seems high
5-
// #[export]
6-
// fn bench_compression(input: [u8; 128]) {
7-
// let foo = msg_u8_to_u64(input);
8-
// let r = sha512_compression(foo, [0; 8]);
9-
// println(f"{r}");
10-
// }
11-
// cost of 2 hashes = 115,221
12-
// cost of 1 hash = 63,938
13-
// extra hash = 51k, 13k gate setup? seems appropriate
14-
// note: a lot of cost overhead vs compression algorithm. A lot of this will be witness extension, but maybe there are overheads we can cut?
15-
#[export]
16-
fn bench_digest(input: [u8; 128]) {
17-
let result = digest::<_, 1>(input);
18-
19-
let expected: [u8; 64] = [
20-
0xcf, 0x83, 0xe1, 0x35, 0x7e, 0xef, 0xb8, 0xbd, 0xf1, 0x54, 0x28, 0x50, 0xd6, 0x6d, 0x80,
21-
0x07, 0xd6, 0x20, 0xe4, 0x05, 0x0b, 0x57, 0x15, 0xdc, 0x83, 0xf4, 0xa9, 0x21, 0xd3, 0x6c,
22-
0xe9, 0xce, 0x47, 0xd0, 0xd1, 0x3c, 0x5d, 0x85, 0xf2, 0xb0, 0xff, 0x83, 0x18, 0xd2, 0x87,
23-
0x7e, 0xec, 0x2f, 0x63, 0xb9, 0x31, 0xbd, 0x47, 0x41, 0x7a, 0x81, 0xa5, 0x38, 0x32, 0x7a,
24-
0xf9, 0x27, 0xda, 0x3e,
25-
];
26-
27-
println(f"result {result}");
28-
println(f"expected {expected}");
29-
assert_eq(result, expected);
1+
use crate::formatting::msg_u8_to_u64;
2+
3+
global MAX_BYTES_1_BLOCK: u32 = 111;
4+
global MAX_BYTES_2_BLOCKS: u32 = MAX_BYTES_1_BLOCK + 128;
5+
global MAX_BYTES_3_BLOCKS: u32 = MAX_BYTES_2_BLOCKS + 128;
6+
global MAX_BYTES_4_BLOCKS: u32 = MAX_BYTES_3_BLOCKS + 128;
7+
8+
#[export]
9+
fn bench_sha512_compression(input: [u8; 128], h: [u64; 8]) -> [u64; 8] {
10+
let r = crate::sha512_compression(msg_u8_to_u64(input), h);
11+
r
12+
}
13+
14+
#[export]
15+
fn bench_sha512_1_block(input: [u8; MAX_BYTES_1_BLOCK]) -> [u8; 64] {
16+
crate::sha512::digest(input)
17+
}
18+
19+
#[export]
20+
fn bench_sha512_2_blocks(input: [u8; MAX_BYTES_2_BLOCKS]) -> [u8; 64] {
21+
crate::sha512::digest(input)
22+
}
23+
24+
#[export]
25+
fn bench_sha512_3_blocks(input: [u8; MAX_BYTES_3_BLOCKS]) -> [u8; 64] {
26+
crate::sha512::digest(input)
27+
}
28+
29+
#[export]
30+
fn bench_sha512_4_blocks(input: [u8; MAX_BYTES_4_BLOCKS]) -> [u8; 64] {
31+
crate::sha512::digest(input)
32+
}
33+
34+
#[export]
35+
fn bench_sha512_var_1_block(input: BoundedVec<u8, MAX_BYTES_1_BLOCK>) -> [u8; 64] {
36+
crate::sha512::sha512_var(input)
37+
}
38+
39+
#[export]
40+
fn bench_sha512_var_2_blocks(input: BoundedVec<u8, MAX_BYTES_2_BLOCKS>) -> [u8; 64] {
41+
crate::sha512::sha512_var(input)
42+
}
43+
44+
#[export]
45+
fn bench_sha512_var_3_blocks(input: BoundedVec<u8, MAX_BYTES_3_BLOCKS>) -> [u8; 64] {
46+
crate::sha512::sha512_var(input)
47+
}
48+
49+
#[export]
50+
fn bench_sha512_var_4_blocks(input: BoundedVec<u8, MAX_BYTES_4_BLOCKS>) -> [u8; 64] {
51+
crate::sha512::sha512_var(input)
3052
}

0 commit comments

Comments
 (0)