From 85676d9cd197e2f992a1e1acf60b1ba556eaca67 Mon Sep 17 00:00:00 2001 From: cboh4 Date: Fri, 12 Sep 2025 14:01:55 +0300 Subject: [PATCH 1/2] remove ImplicitHash from the blockheader hash calculation --- state/state.go | 10 +++++----- state/validation.go | 16 ++++++---------- types/block.go | 4 ++-- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/state/state.go b/state/state.go index f851bf84e01..e8fc523c544 100644 --- a/state/state.go +++ b/state/state.go @@ -280,10 +280,10 @@ func (state State) MakeBlock( panic("Failed to validate generated random") } - implicitHash, err := tmenclave.GetImplicitHash() - if err != nil { - panic("Failed to get implicit hash") - } + // implicitHash, err := tmenclave.GetImplicitHash() + // if err != nil { + // panic("Failed to get implicit hash") + // } // ScrtLabs changes out <- // Fill rest of header with state data. @@ -292,7 +292,7 @@ func (state State) MakeBlock( timestamp, state.LastBlockID, state.Validators.Hash(), state.NextValidators.Hash(), state.ConsensusParams.Hash(), state.AppHash, state.LastResultsHash, - proposerAddress, &encryptedRandom, implicitHash, + proposerAddress, &encryptedRandom, nil, ) return block diff --git a/state/validation.go b/state/validation.go index 81dbc2f315a..9abc1846d22 100644 --- a/state/validation.go +++ b/state/validation.go @@ -2,7 +2,6 @@ package state import ( "bytes" - "crypto/sha256" "encoding/hex" "errors" "fmt" @@ -121,15 +120,12 @@ func validateBlock(state State, block *types.Block) error { } } - expectedImplicitHash, err := tmenclave.GetImplicitHash() // hash from last block's scheduling - if err != nil { - return fmt.Errorf("failed to get implicit hash: %w", err) - } - if !bytes.Equal(block.Header.ImplicitHash, expectedImplicitHash) { - emptySha256 := sha256.Sum256([]byte{}) - if !(bytes.Equal(block.Header.ImplicitHash, []byte{}) && bytes.Equal(expectedImplicitHash, emptySha256[:])) { - return fmt.Errorf("implicit_hash mismatch: expected %X, got %X", hex.EncodeToString(expectedImplicitHash), hex.EncodeToString(block.Header.ImplicitHash)) - } + // expectedImplicitHash, err := tmenclave.GetImplicitHash() // hash from last block's scheduling + // if err != nil { + // return fmt.Errorf("failed to get implicit hash: %w", err) + // } + if !bytes.Equal(block.Header.ImplicitHash, nil) { + return fmt.Errorf("implicit_hash mismatch: expected nil, got %s", block.Header.ImplicitHash.String()) } // Validate block Time diff --git a/types/block.go b/types/block.go index aca900a54bf..e0f17119113 100644 --- a/types/block.go +++ b/types/block.go @@ -489,7 +489,7 @@ func (h *Header) Hash() cmtbytes.HexBytes { cdcEncode(h.LastResultsHash), cdcEncode(h.EvidenceHash), cdcEncode(h.ProposerAddress), - cdcEncode(h.ImplicitHash), + // cdcEncode(h.ImplicitHash), }) } @@ -529,7 +529,7 @@ func (h *Header) StringIndented(indent string) string { indent, h.LastResultsHash, indent, h.EvidenceHash, indent, h.ProposerAddress, - indent, h.ImplicitHash, + // indent, h.ImplicitHash, indent, h.Hash(), ) } From da747a4af98de189973f90ae0cd5feff62f39af0 Mon Sep 17 00:00:00 2001 From: cboh4 Date: Fri, 12 Sep 2025 14:26:33 +0300 Subject: [PATCH 2/2] add check if it's a hash of empty slice --- state/validation.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/state/validation.go b/state/validation.go index 9abc1846d22..b308fb43404 100644 --- a/state/validation.go +++ b/state/validation.go @@ -2,6 +2,7 @@ package state import ( "bytes" + "crypto/sha256" "encoding/hex" "errors" "fmt" @@ -124,8 +125,12 @@ func validateBlock(state State, block *types.Block) error { // if err != nil { // return fmt.Errorf("failed to get implicit hash: %w", err) // } - if !bytes.Equal(block.Header.ImplicitHash, nil) { - return fmt.Errorf("implicit_hash mismatch: expected nil, got %s", block.Header.ImplicitHash.String()) + if len(block.Header.ImplicitHash) > 0 { + emptySha256 := sha256.Sum256([]byte{}) + if !bytes.Equal(block.Header.ImplicitHash, emptySha256[:]) { + return fmt.Errorf("implicit_hash mismatch: expected nil or empty hash, got %s", + block.Header.ImplicitHash.String()) + } } // Validate block Time