snarkvm_ledger_block/header/metadata/
verify.rs1#![allow(clippy::too_many_arguments)]
17
18use snarkvm_utilities::ensure_equals;
19
20use super::*;
21
22impl<N: Network> Metadata<N> {
23 pub fn verify(
25 &self,
26 expected_round: u64,
27 expected_height: u32,
28 expected_cumulative_weight: u128,
29 expected_cumulative_proof_target: u128,
30 expected_coinbase_target: u64,
31 expected_proof_target: u64,
32 expected_last_coinbase_target: u64,
33 expected_last_coinbase_timestamp: i64,
34 expected_timestamp: i64,
35 current_timestamp: i64,
36 ) -> Result<()> {
37 if let Err(err) = self.check_validity() {
39 bail!("Metadata is malformed in block {expected_height}: {err}");
40 }
41
42 ensure_equals!(self.round, expected_round, "Round is incorrect in block {expected_height}");
43 ensure_equals!(self.height, expected_height, "Height is incorrect in block {expected_height}");
44 ensure_equals!(
45 self.cumulative_weight,
46 expected_cumulative_weight,
47 "Cumulative weight is incorrect in block {expected_height}"
48 );
49 ensure_equals!(
50 self.cumulative_proof_target,
51 expected_cumulative_proof_target,
52 "Cumulative proof target is incorrect in block {expected_height}"
53 );
54 ensure_equals!(
55 self.coinbase_target,
56 expected_coinbase_target,
57 "Coinbase target is incorrect in block {expected_height}"
58 );
59 ensure_equals!(
60 self.proof_target,
61 expected_proof_target,
62 "Proof target is incorrect in block {expected_height}"
63 );
64 ensure_equals!(
65 self.last_coinbase_target,
66 expected_last_coinbase_target,
67 "Last coinbase target is incorrect in block {expected_height}"
68 );
69 ensure_equals!(
70 self.last_coinbase_timestamp,
71 expected_last_coinbase_timestamp,
72 "Last coinbase timestamp is incorrect in block {expected_height}"
73 );
74 ensure_equals!(self.timestamp, expected_timestamp, "Timestamp is incorrect in block {expected_height}");
75 ensure!(
76 self.timestamp <= current_timestamp,
77 "Timestamp is in the future in block {expected_height} (found '{}', expected before '{}')",
78 self.timestamp,
79 current_timestamp
80 );
81
82 Ok(())
83 }
84}