Skip to content

Commit

Permalink
fix hash verification for in-mem
Browse files Browse the repository at this point in the history
  • Loading branch information
badgersrus committed Nov 5, 2024
1 parent e537241 commit f50cae9
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions go/enclave/components/rollup_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,26 +159,21 @@ func (rc *rollupConsumerImpl) extractAndVerifyRollups(br *common.BlockAndReceipt
return rollups, nil
}

// given the blobHashes are extracted from the block and receipts, and the transactions are decoded to get the rollup hashes,
// we should always get an equal number of hashes to compare
// there may be many rollups in one block so the blobHashes array, so it is possible that the rollupHashes array is a
// subset of the blobHashes array
func verifyBlobHashes(rollupHashes *ethadapter.L1RollupHashes, blobHashes []gethcommon.Hash) error {
numBlobHashes := len(blobHashes)
numRollupHashes := len(rollupHashes.BlobHashes)
if numRollupHashes != numBlobHashes {
return fmt.Errorf(
"length mismatch: rollupHashes (%d) != blobHashes (%d)",
numRollupHashes,
numBlobHashes,
)
// more efficient lookup
blobHashSet := make(map[gethcommon.Hash]struct{}, len(blobHashes))
for _, h := range blobHashes {
blobHashSet[h] = struct{}{}
}

for i := 0; i < numBlobHashes; i++ {
if rollupHashes.BlobHashes[i] != blobHashes[i] {
for i, rollupHash := range rollupHashes.BlobHashes {
if _, exists := blobHashSet[rollupHash]; !exists {
return fmt.Errorf(
"hash mismatch at index %d: rollupHash (%s) != blobHash (%s)",
"rollupHash at index %d (%s) not found in blobHashes",
i,
rollupHashes.BlobHashes[i].Hex(),
blobHashes[i].Hex(),
rollupHash.Hex(),
)
}
}
Expand Down

0 comments on commit f50cae9

Please sign in to comment.