The final circuit that verifies the output of the header chain circuit.
(guest: &impl ZkvmGuest)
| 39 | |
| 40 | /// The final circuit that verifies the output of the header chain circuit. |
| 41 | pub fn final_circuit(guest: &impl ZkvmGuest) { |
| 42 | let start = env::cycle_count(); |
| 43 | let input: FinalCircuitInput = guest.read_from_host::<FinalCircuitInput>(); |
| 44 | guest.verify(HEADER_CHAIN_GUEST_ID, &input.block_header_circuit_output); |
| 45 | input.spv.verify( |
| 46 | input |
| 47 | .block_header_circuit_output |
| 48 | .chain_state |
| 49 | .block_hashes_mmr, |
| 50 | ); |
| 51 | let mut hasher = blake3::Hasher::new(); |
| 52 | |
| 53 | hasher.update(&input.spv.transaction.txid()); |
| 54 | hasher.update( |
| 55 | &input |
| 56 | .block_header_circuit_output |
| 57 | .chain_state |
| 58 | .best_block_hash, |
| 59 | ); |
| 60 | hasher.update(&input.block_header_circuit_output.chain_state.total_work); |
| 61 | let final_output = hasher.finalize(); |
| 62 | guest.commit(final_output.as_bytes()); |
| 63 | let end = env::cycle_count(); |
| 64 | println!("Final circuit took {:?} cycles", end - start); |
| 65 | } |