snarkvm_ledger_block/header/
verify.rs1#![allow(clippy::too_many_arguments)]
17
18use super::*;
19
20impl<N: Network> Header<N> {
21 pub fn verify(
23 &self,
24 expected_previous_state_root: N::StateRoot,
25 expected_transactions_root: Field<N>,
26 expected_finalize_root: Field<N>,
27 expected_ratifications_root: Field<N>,
28 expected_solutions_root: Field<N>,
29 expected_subdag_root: Field<N>,
30 expected_round: u64,
31 expected_height: u32,
32 expected_cumulative_weight: u128,
33 expected_cumulative_proof_target: u128,
34 expected_coinbase_target: u64,
35 expected_proof_target: u64,
36 expected_last_coinbase_target: u64,
37 expected_last_coinbase_timestamp: i64,
38 expected_timestamp: i64,
39 current_timestamp: i64,
40 ) -> Result<()> {
41 if let Err(err) = self.check_validity() {
43 anyhow::bail!("Header is malformed in block {expected_height}: {err}");
44 }
45
46 ensure!(
48 self.previous_state_root == expected_previous_state_root,
49 "Previous state root is incorrect in block {expected_height} (found '{}', expected '{}')",
50 self.previous_state_root,
51 expected_previous_state_root
52 );
53 ensure!(
55 self.transactions_root == expected_transactions_root,
56 "Transactions root is incorrect in block {expected_height} (found '{}', expected '{}')",
57 self.transactions_root,
58 expected_transactions_root
59 );
60 ensure!(
62 self.finalize_root == expected_finalize_root,
63 "Finalize root is incorrect in block {expected_height} (found '{}', expected '{}')",
64 self.finalize_root,
65 expected_finalize_root
66 );
67 ensure!(
69 self.ratifications_root == expected_ratifications_root,
70 "Ratifications root is incorrect in block {expected_height} (found '{}', expected '{}')",
71 self.ratifications_root,
72 expected_ratifications_root
73 );
74 ensure!(
76 self.solutions_root == expected_solutions_root,
77 "Solutions root is incorrect in block {expected_height} (found '{}', expected '{}')",
78 self.solutions_root,
79 expected_solutions_root
80 );
81 ensure!(
83 self.subdag_root == expected_subdag_root,
84 "Subdag root is incorrect in block {expected_height} (found '{}', expected '{}')",
85 self.subdag_root,
86 expected_subdag_root
87 );
88 self.metadata.verify(
90 expected_round,
91 expected_height,
92 expected_cumulative_weight,
93 expected_cumulative_proof_target,
94 expected_coinbase_target,
95 expected_proof_target,
96 expected_last_coinbase_target,
97 expected_last_coinbase_timestamp,
98 expected_timestamp,
99 current_timestamp,
100 )
101 }
102}