Skip to content

Commit

Permalink
core/types: add length check in CalcRequestsHash (ethereum#30829)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fjl authored Nov 28, 2024
1 parent 53f66c1 commit c7a8bce
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c7a8bce

Please sign in to comment.