From 6834c074542f73a2c6ff0ee6d0e2b4062ff9fa3e Mon Sep 17 00:00:00 2001 From: Janez Podhostnik Date: Mon, 18 Nov 2024 20:05:40 +0100 Subject: [PATCH] Copy slice when setting block hash list --- fvm/evm/handler/blockHashList.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fvm/evm/handler/blockHashList.go b/fvm/evm/handler/blockHashList.go index 86ea5738b5a..bf1d564c2a2 100644 --- a/fvm/evm/handler/blockHashList.go +++ b/fvm/evm/handler/blockHashList.go @@ -84,6 +84,7 @@ func (bhl *BlockHashList) Push(height uint64, bh gethCommon.Hash) error { if !bhl.IsEmpty() && height != bhl.height+1 { return fmt.Errorf("out of the order block hash, expected: %d, got: %d", bhl.height+1, height) } + // updates the block hash stored at index err := bhl.updateBlockHashAt(bhl.tail, bh) if err != nil { @@ -147,19 +148,22 @@ func (bhl *BlockHashList) updateBlockHashAt(idx int, bh gethCommon.Hash) error { // fetch the bucket bucketNumber := idx / hashCountPerBucket bucket, err := bhl.fetchBucket(bucketNumber) + cpy := make([]byte, len(bucket)) + copy(cpy, bucket) + if err != nil { return err } // update the block hash start := (idx % hashCountPerBucket) * hashEncodingSize end := start + hashEncodingSize - copy(bucket[start:end], bh.Bytes()) + copy(cpy[start:end], bh.Bytes()) // store bucket return bhl.backend.SetValue( bhl.rootAddress[:], []byte(fmt.Sprintf(blockHashListBucketKeyFormat, bucketNumber)), - bucket, + cpy, ) }