Check block commitment before updating hist tree

This commit is contained in:
Marek 2022-07-26 22:11:22 +02:00
parent 0822a4ce32
commit 50518fb15c
1 changed files with 26 additions and 16 deletions

View File

@ -292,8 +292,33 @@ impl FinalizedState {
// Update the note commitment trees.
note_commitment_trees.update_trees_parallel(&finalized.block)?;
// Check the block commitment if the history tree was not
// supplied by the non-finalized state. Note that we don't do
// this check for history trees supplied by the non-finalized
// state because the non-finalized state checks the block
// commitment.
//
// For Nu5-onward, the block hash commits only to
// non-authorizing data (see ZIP-244). This checks the
// authorizing data commitment, making sure the entire block
// contents were committed to. The test is done here (and not
// during semantic validation) because it needs the history tree
// root. While it _is_ checked during contextual validation,
// that is not called by the checkpoint verifier, and keeping a
// history tree there would be harder to implement.
//
// TODO: run this CPU-intensive cryptography in a parallel rayon
// thread, if it shows up in profiles
check::block_commitment_is_valid_for_chain_history(
finalized.block.clone(),
self.network,
&history_tree,
)?;
// Update the history tree.
// TODO: run this CPU-intensive cryptography in a parallel rayon thread, if it shows up in profiles
//
// TODO: run this CPU-intensive cryptography in a parallel rayon
// thread, if it shows up in profiles
let history_tree_mut = Arc::make_mut(&mut history_tree);
let sapling_root = note_commitment_trees.sapling.root();
let orchard_root = note_commitment_trees.orchard.root();
@ -308,21 +333,6 @@ impl FinalizedState {
}
};
// Check the block commitment. For Nu5-onward, the block hash commits only
// to non-authorizing data (see ZIP-244). This checks the authorizing data
// commitment, making sure the entire block contents were committed to.
// The test is done here (and not during semantic validation) because it needs
// the history tree root. While it _is_ checked during contextual validation,
// that is not called by the checkpoint verifier, and keeping a history tree there
// would be harder to implement.
//
// TODO: run this CPU-intensive cryptography in a parallel rayon thread, if it shows up in profiles
check::block_commitment_is_valid_for_chain_history(
finalized.block.clone(),
self.network,
&history_tree,
)?;
let finalized_height = finalized.height;
let finalized_hash = finalized.hash;