Skip to main content

charms_proof_wrapper/
lib.rs

1use sp1_primitives::io::sha256_hash;
2use sp1_zkvm::lib::verify::verify_sp1_proof;
3
4pub const SPELL_CHECKER_VK: [u32; 8] = [
5    128641635, 1307662796, 31074232, 1385511702, 1385924035, 1463747598, 1152047826, 1263855208,
6];
7
8pub fn main() {
9    let input_vec = sp1_zkvm::io::read_vec();
10    verify_proof(&SPELL_CHECKER_VK, &input_vec);
11    sp1_zkvm::io::commit_slice(&input_vec);
12}
13
14fn verify_proof(vk: &[u32; 8], committed_data: &[u8]) {
15    let Ok(pv) = sha256_hash(committed_data).try_into() else {
16        unreachable!()
17    };
18    verify_sp1_proof(vk, &pv);
19}
20
21#[cfg(test)]
22mod test {
23    use super::*;
24    use sp1_sdk::{
25        HashableKey, ProvingKey,
26        blocking::{Prover, ProverClient},
27    };
28
29    /// RISC-V binary compiled from `charms-spell-checker`.
30    pub const SPELL_CHECKER_BINARY: &[u8] = include_bytes!("../../src/bin/charms-spell-checker");
31
32    #[test]
33    fn test_spell_vk() {
34        let client = ProverClient::builder().light().build();
35
36        dbg!("client built");
37
38        let pk = client.setup(SPELL_CHECKER_BINARY.into()).unwrap();
39
40        dbg!("pk obtained");
41
42        assert_eq!(SPELL_CHECKER_VK, pk.verifying_key().hash_u32());
43    }
44}