From 6a4a7039cb3dca2cd8618b00b75f4ff2c065ee96 Mon Sep 17 00:00:00 2001 From: behzad nouri Date: Wed, 15 Feb 2023 21:46:30 +0000 Subject: [PATCH] adds hash domain to merkle shreds (#29339) (cherry picked from commit 06bb71c79fca73ebbf3a2d4bbbc87890adc4e9c7) --- ledger/src/shred/merkle.rs | 6 ++++-- ledger/src/shredder.rs | 4 +--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ledger/src/shred/merkle.rs b/ledger/src/shred/merkle.rs index 41657ac5d582af..0c3b1af85b68d9 100644 --- a/ledger/src/shred/merkle.rs +++ b/ledger/src/shred/merkle.rs @@ -43,8 +43,10 @@ const_assert_eq!(ShredData::SIZE_OF_PAYLOAD, 1203); // Defense against second preimage attack: // https://en.wikipedia.org/wiki/Merkle_tree#Second_preimage_attack -const MERKLE_HASH_PREFIX_LEAF: &[u8] = &[0x00]; -const MERKLE_HASH_PREFIX_NODE: &[u8] = &[0x01]; +// Following Certificate Transparency, 0x00 and 0x01 bytes are prepended to +// hash data when computing leaf and internal node hashes respectively. +const MERKLE_HASH_PREFIX_LEAF: &[u8] = b"\x00SOLANA_MERKLE_SHREDS_LEAF"; +const MERKLE_HASH_PREFIX_NODE: &[u8] = b"\x01SOLANA_MERKLE_SHREDS_NODE"; pub(crate) type MerkleRoot = MerkleProofEntry; type MerkleProofEntry = [u8; 20]; diff --git a/ledger/src/shredder.rs b/ledger/src/shredder.rs index 6c1e6b0b4c6e64..9ef0a68fdc5c08 100644 --- a/ledger/src/shredder.rs +++ b/ledger/src/shredder.rs @@ -7,7 +7,7 @@ use { lru::LruCache, rayon::{prelude::*, ThreadPool}, reed_solomon_erasure::{ - galois_8::Field, + galois_8::ReedSolomon, Error::{InvalidIndex, TooFewDataShards, TooFewShardsPresent}, }, solana_entry::entry::Entry, @@ -38,8 +38,6 @@ pub(crate) const ERASURE_BATCH_SIZE: [usize; 33] = [ 55, 56, 58, 59, 60, 62, 63, 64, // 32 ]; -type ReedSolomon = reed_solomon_erasure::ReedSolomon; - pub struct ReedSolomonCache( Mutex>>, );