57 lines
1.4 KiB
Rust
57 lines
1.4 KiB
Rust
|
//! Client side zkvm program.
|
||
|
#![no_main]
|
||
|
sp1_zkvm::entrypoint!(main);
|
||
|
|
||
|
use ed25519_dalek_patched::{VerifyingKey, Signature, SecretKey}
|
||
|
|
||
|
type InputLengh = u64;
|
||
|
|
||
|
type Secret = [u8: 32];
|
||
|
|
||
|
struct InputHead {
|
||
|
salt: [u8: 32],
|
||
|
from: [u8: 32],
|
||
|
val: u32,
|
||
|
to: [u8: 32],
|
||
|
hash: [u8: 32],
|
||
|
signature: [u8: 64],
|
||
|
public_key: [u8: 32],
|
||
|
root: [u8: 32],
|
||
|
}
|
||
|
|
||
|
|
||
|
// Input Head length in bytes.
|
||
|
// Could be turned into Phantom attribute or somethin?
|
||
|
const HL = 260;
|
||
|
|
||
|
pub fn main() {
|
||
|
let length = sp1_zkvm::io::read::<InputLengh>();
|
||
|
let input = sp1_zkvm::io::read::<InputHead>();
|
||
|
let secret = sp1_zkvm::io::read::<Secret>();
|
||
|
let mut my_slice = [0_u8; 32];
|
||
|
sp1_zkvm::io::read_slice(&mut my_slice);
|
||
|
let hashes = sp1_zkvm::io::read::<Vec<u8>>();
|
||
|
|
||
|
let pk = VerifyingKey::from_bytes(input.public_key).unwrap();
|
||
|
assert!(pk.verify_strict(
|
||
|
&input.from
|
||
|
.iter()
|
||
|
.chain(input.val.to_le_bytes().iter())
|
||
|
.chain(input.to.iter())
|
||
|
.cloned()
|
||
|
.collect(),
|
||
|
Signature::from_bytes(&input.signature),
|
||
|
).unwrap());
|
||
|
|
||
|
let mut h = Sha256::new();
|
||
|
let chunks = hashes.chunks(32);
|
||
|
chunks.fold(chunks.next().unwrap(), |acc, e| {
|
||
|
h.update();
|
||
|
assert!(*e == *h.finalize_reset());
|
||
|
});
|
||
|
assert!(input.root == *self.hashes.last().unwrap());
|
||
|
|
||
|
sp1_zkvm::io::commit_slice(&input.hash);
|
||
|
sp1_zkvm::io::commit_slice(&input.root);
|
||
|
}
|