|
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) |
30 | 52 | } |
0 commit comments