Skip to content

Commit c7a8bce

Browse files
authored
core/types: add length check in CalcRequestsHash (ethereum#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.
1 parent 53f66c1 commit c7a8bce

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

core/types/block.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,11 @@ func CalcRequestsHash(requests [][]byte) common.Hash {
463463
h1, h2 := sha256.New(), sha256.New()
464464
var buf common.Hash
465465
for _, item := range requests {
466-
h1.Reset()
467-
h1.Write(item)
468-
h2.Write(h1.Sum(buf[:0]))
466+
if len(item) > 1 { // skip items with only requestType and no data.
467+
h1.Reset()
468+
h1.Write(item)
469+
h2.Write(h1.Sum(buf[:0]))
470+
}
469471
}
470472
h2.Sum(buf[:0])
471473
return buf

0 commit comments

Comments
 (0)