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 ensure!(self.is_valid(), "Header is malformed in block {expected_height}");
43 ensure!(
45 self.previous_state_root == expected_previous_state_root,
46 "Previous state root is incorrect in block {expected_height} (found '{}', expected '{}')",
47 self.previous_state_root,
48 expected_previous_state_root
49 );
50 ensure!(
52 self.transactions_root == expected_transactions_root,
53 "Transactions root is incorrect in block {expected_height} (found '{}', expected '{}')",
54 self.transactions_root,
55 expected_transactions_root
56 );
57 ensure!(
59 self.finalize_root == expected_finalize_root,
60 "Finalize root is incorrect in block {expected_height} (found '{}', expected '{}')",
61 self.finalize_root,
62 expected_finalize_root
63 );
64 ensure!(
66 self.ratifications_root == expected_ratifications_root,
67 "Ratifications root is incorrect in block {expected_height} (found '{}', expected '{}')",
68 self.ratifications_root,
69 expected_ratifications_root
70 );
71 ensure!(
73 self.solutions_root == expected_solutions_root,
74 "Solutions root is incorrect in block {expected_height} (found '{}', expected '{}')",
75 self.solutions_root,
76 expected_solutions_root
77 );
78 ensure!(
80 self.subdag_root == expected_subdag_root,
81 "Subdag root is incorrect in block {expected_height} (found '{}', expected '{}')",
82 self.subdag_root,
83 expected_subdag_root
84 );
85 self.metadata.verify(
87 expected_round,
88 expected_height,
89 expected_cumulative_weight,
90 expected_cumulative_proof_target,
91 expected_coinbase_target,
92 expected_proof_target,
93 expected_last_coinbase_target,
94 expected_last_coinbase_timestamp,
95 expected_timestamp,
96 current_timestamp,
97 )
98 }
99}