Skip to content

Commit e840bf4

Browse files
committed
feat(heartbeats): Verify block proofs
1 parent 26ed848 commit e840bf4

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/heartbeats-processor/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ dotenv = "0.15"
1515
clap = { version = "4.4", features = ["derive"] }
1616
gcloud-sdk = { version = "0.26.0", default-features = false, features = ["google-firestore-v1"] }
1717
base64 = "0.22"
18+
mina-tree = { path = "../../ledger" }
19+
snark = { path = "../../snark" }
1820

1921
mina-p2p-messages = { workspace = true }
2022
openmina-core = { path = "../../core" }

tools/heartbeats-processor/src/local_db.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::config::Config;
1111
use crate::remote_db::BlockInfo;
1212
use crate::remote_db::HeartbeatChunkState;
1313
use crate::time::*;
14+
use mina_tree::proofs::verification::verify_block;
1415

1516
#[derive(Debug)]
1617
pub struct HeartbeatPresence {
@@ -267,6 +268,10 @@ pub async fn process_heartbeats(
267268
last_timestamp: None,
268269
};
269270

271+
// Its ok to call these functions multiple times because the result is cached
272+
let verifier_index = snark::BlockVerifier::make();
273+
let verifier_srs = snark::get_srs();
274+
270275
loop {
271276
let heartbeats =
272277
crate::remote_db::fetch_heartbeat_chunk(db, &mut chunk_state, end_time).await?;
@@ -343,7 +348,7 @@ pub async fn process_heartbeats(
343348
.map(|bi| (bi.clone(), bi.block_header_decoded()))
344349
{
345350
None => (), // No block to process
346-
Some((block_info, Ok(_block_header))) => {
351+
Some((block_info, Ok(block_header))) => {
347352
let key = (public_key_id, block_info.hash.clone());
348353

349354
if let Some(first_seen) = seen_blocks.get(&key) {
@@ -360,6 +365,16 @@ pub async fn process_heartbeats(
360365
continue;
361366
}
362367

368+
// Verify block proof
369+
if !verify_block(&block_header, &verifier_index, &verifier_srs)
370+
{
371+
println!(
372+
"WARNING: Invalid block proof: {} (height: {}, producer: {})",
373+
block_info.hash, block_info.height, entry.submitter
374+
);
375+
continue;
376+
}
377+
363378
seen_blocks.insert(key.clone(), entry.create_time);
364379
produced_blocks_batch.push(ProducedBlock {
365380
window_id: window.id.unwrap(),

0 commit comments

Comments
 (0)