mirror of
https://github.com/babybear-labs/benchmark.git
synced 2026-01-10 07:47:55 -05:00
Jolt poseidon bench update
This commit is contained in:
@@ -282,4 +282,53 @@ thread 'main' panicked at /Users/muhtasim/.cargo/git/checkouts/jolt-6b856340b98d
|
||||
assertion failed: program_io.inputs.len() <= program_io.memory_layout.max_input_size as usize
|
||||
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
|
||||
|
||||
```
|
||||
|
||||
### Poseidon
|
||||
```rust
|
||||
use starknet_crypto::{PoseidonHasher};
|
||||
use starknet_types_core::felt::Felt;
|
||||
|
||||
/// Converts an arbitrary byte slice into `Felt` elements.
|
||||
fn bytes_to_felts(input: &[u8]) -> Vec<Felt> {
|
||||
const FELT_BYTE_SIZE: usize = 31; // Maximum bytes for a Felt element in BN254
|
||||
|
||||
input
|
||||
.chunks(FELT_BYTE_SIZE)
|
||||
.map(|chunk| {
|
||||
let mut buffer = [0u8; 32]; // BN254 requires 32 bytes, pad with zeroes
|
||||
buffer[32 - chunk.len()..].copy_from_slice(chunk); // Right-align the chunk
|
||||
Felt::from_bytes_be(&buffer)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Ref: https://github.com/xJonathanLEI/starknet-rs/blob/master/starknet-crypto/benches/poseidon_hash.rs
|
||||
#[no_mangle]
|
||||
#[jolt::provable]
|
||||
pub fn pos() {
|
||||
let input = &[5u8; 32];
|
||||
// Convert input into `Felt` chunks
|
||||
let felt_chunks = bytes_to_felts(input);
|
||||
|
||||
let mut hasher = PoseidonHasher::new();
|
||||
for chunk in &felt_chunks {
|
||||
hasher.update(*chunk);
|
||||
}
|
||||
let hash = hasher.finalize();
|
||||
}
|
||||
```
|
||||
|
||||
#### Result
|
||||
- Input 32 bytes
|
||||
```shell
|
||||
Trace length: 554595
|
||||
Prover Time 434.08379375s
|
||||
Proof Size 477746
|
||||
|
||||
Verify Time 238.556041ms
|
||||
|
||||
result: ()
|
||||
valid: true
|
||||
Total Time elapsed: 434.536444333s
|
||||
```
|
||||
Reference in New Issue
Block a user