Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions crates/generic_log_worker/src/log_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,14 @@ pub async fn prove_consistency(
prev_tree_size: u64,
object: &impl ObjectBackend,
) -> Result<Proof, ProofError> {
prove_subtree_consistency(cur_tree_hash, cur_tree_size, 0, prev_tree_size, object).await
prove_subtree_consistency(cur_tree_hash, cur_tree_size, 0, prev_tree_size, object)
.await
.map(|(p, _)| p)
}

/// Returns a consistency proof that the tree with size `cur_tree_size` and hash
/// `cur_tree_hash` is consistent with the subtree `[start, end)`.
/// Returns a consistency proof that the tree with size `cur_tree_size` and hash `cur_tree_hash` is
/// consistent with the subtree `[start, end)`. Returns the subtree hash that the verifier would
/// check the proof against.
///
/// # Errors
///
Expand All @@ -598,19 +601,19 @@ pub async fn prove_subtree_consistency(
start: u64,
end: u64,
object: &impl ObjectBackend,
) -> Result<Proof, ProofError> {
) -> Result<(Proof, Hash), ProofError> {
let m = &Subtree::new(start, end)?;
// Fetch the tiles needed for the proof.
let indexes = tlog_tiles::subtree_consistency_proof_indexes(cur_tree_size, m)?;
let tile_reader = tile_reader_for_indexes(cur_tree_size, &indexes, object).await?;
let hash_reader = TileHashReader::new(cur_tree_size, cur_tree_hash, &tile_reader);

// Construct the proof.
Ok(tlog_tiles::subtree_consistency_proof(
cur_tree_size,
m,
&hash_reader,
)?)
let proof = tlog_tiles::subtree_consistency_proof(cur_tree_size, m, &hash_reader)?;

// Compute the subtree hash.
let subtree_hash = tlog_tiles::subtree_hash(&m, &hash_reader)?;
Ok((proof, subtree_hash))
}

/// Fetch the tree tiles containing the nodes at the requested indexes, as well
Expand Down
9 changes: 6 additions & 3 deletions crates/mtc_worker/src/frontend_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ pub struct GetLandmarkBundleResponse<'a> {
pub struct SubtreeWithConsistencyProof {
pub start: u64,
pub end: u64,
#[serde_as(as = "Base64")]
pub hash: [u8; 32],
#[serde_as(as = "Vec<Base64>")]
pub consistency_proof: Vec<Vec<u8>>,
pub consistency_proof: Vec<[u8; 32]>,
}

/// Start is the first code run when the Wasm module is loaded.
Expand Down Expand Up @@ -421,7 +423,7 @@ async fn get_landmark_bundle(env: &Env, name: &str) -> Result<Response> {
// the checkpoint. Each signatureless MTC includes an inclusion proof in one of these subtrees.
let mut subtrees = Vec::new();
for landmark_subtree in landmark_sequence.subtrees() {
let consistency_proof = match prove_subtree_consistency(
let (consistency_proof, landmark_subtree_hash) = match prove_subtree_consistency(
*checkpoint.hash(),
checkpoint.size(),
landmark_subtree.lo(),
Expand All @@ -438,7 +440,8 @@ async fn get_landmark_bundle(env: &Env, name: &str) -> Result<Response> {
subtrees.push(SubtreeWithConsistencyProof {
start: landmark_subtree.lo(),
end: landmark_subtree.hi(),
consistency_proof: consistency_proof.iter().map(|h| h.0.to_vec()).collect(),
hash: landmark_subtree_hash.0,
consistency_proof: consistency_proof.iter().map(|h| h.0).collect(),
});
}

Expand Down