From c7a8bcecbed7b371f0d6ec97ab1a1ae33aa3ca85 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 28 Nov 2024 18:43:39 +0100 Subject: [PATCH] core/types: add length check in CalcRequestsHash (#30829) The existing implementation is correct when building and verifying blocks, since we will only collect non-empty requests into the block requests list. But it isn't correct for cases where a requests list containing empty items is sent by the consensus layer on the engine API. We want to ensure that empty requests do not cause a difference in validation there, so the commitment computation should explicitly skip them. --- core/types/block.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core/types/block.go b/core/types/block.go index f20fc7d778..ad6c86398d 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -463,9 +463,11 @@ func CalcRequestsHash(requests [][]byte) common.Hash { h1, h2 := sha256.New(), sha256.New() var buf common.Hash for _, item := range requests { - h1.Reset() - h1.Write(item) - h2.Write(h1.Sum(buf[:0])) + if len(item) > 1 { // skip items with only requestType and no data. + h1.Reset() + h1.Write(item) + h2.Write(h1.Sum(buf[:0])) + } } h2.Sum(buf[:0]) return buf