ChainSafe / ChainSafe/gossamer

Replace `common.NewHash` and `common.Hash()` with `common.BytesToHash`

Open
#2,356 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
454
Forks
144
PR merge metrics
No merged PRs in 30d

Description

## Issue summary

- `common.BytesToHash`, `common.NewHash` and `common.Hash` changes bytes to hash (does not hash, just converts). Both of these functions are used interchangeably, but `common.BytesToHash` puts 0 bytes in the front and `common.NewHash` puts 0 bytes in the back.

- Say `[]byte` argument is `0x44102080304545b0b6579496e736964656368696c6414766f696c61`
`common.BytesToHash` will give hash like `0x00000000044102080304545b0b6579496e736964656368696c6414766f696c61` and `common.NewHash` will give a hash like `0x44102080304545b0b6579496e736964656368696c6414766f696c61000000000`

- We should pick one of them and use it across the project to avoid any mismatching in the value of hash. I have gone with `common.BytesToHash` so far.

## Other information and links

- inspired from this pr https://github.com/ChainSafe/gossamer/pull/2302

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.