Skip to content

Commit

Permalink
node: fix overflow while faults validation
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Aug 8, 2024
1 parent 2ad5860 commit 9a701ae
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions node/src/chain/header_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,17 @@ pub async fn verify_faults<DB: database::DB>(
let prev_header = db
.fetch_block_header(&fault_header.prev_block_hash)?
.ok_or(anyhow::anyhow!("Slashing a non accepted header"))?;
// No overflow here, since the header has been already validated
// not to be 0
if prev_header.height != fault_header.round - 1 {
anyhow::bail!("Invalid height for fault");
}

// FIX_ME: Instead of fetching all store faults, check the fault
// id directly This needs the fault id to be
// changed into "HEIGHT|TYPE|PROV_KEY"
let stored_faults =
db.fetch_faults_by_block(fault_header.round - EPOCH)?;
let start_height = fault_header.round.saturating_sub(EPOCH);
let stored_faults = db.fetch_faults_by_block(start_height)?;
if stored_faults.iter().any(|other| f.same(other)) {
anyhow::bail!("Double fault detected");
}
Expand Down

0 comments on commit 9a701ae

Please sign in to comment.