mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
93195b762b
* add cache * Update beacon-chain/state/stateutil/blocks.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update beacon-chain/state/stateutil/blocks.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update beacon-chain/state/stateutil/hash_function.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Merge branch 'master' into improveHTR * add back string casting * fix imports
27 lines
765 B
Go
27 lines
765 B
Go
package stateutil
|
|
|
|
import "encoding/binary"
|
|
|
|
// HashFn describes a hash function and its associated bytes buffer
|
|
type HashFn struct {
|
|
f func(input []byte) [32]byte
|
|
bytesBuffer [64]byte
|
|
}
|
|
|
|
// Combi describes a method which merges two 32-byte arrays and hashes
|
|
// them.
|
|
func (h HashFn) Combi(a [32]byte, b [32]byte) [32]byte {
|
|
copy(h.bytesBuffer[:32], a[:])
|
|
copy(h.bytesBuffer[32:], b[:])
|
|
return h.f(h.bytesBuffer[:])
|
|
}
|
|
|
|
// MixIn describes a method where we add in the provided
|
|
// integer to the end of the byte array and hash it.
|
|
func (h HashFn) MixIn(a [32]byte, i uint64) [32]byte {
|
|
copy(h.bytesBuffer[:32], a[:])
|
|
copy(h.bytesBuffer[32:], make([]byte, 32, 32))
|
|
binary.LittleEndian.PutUint64(h.bytesBuffer[32:], i)
|
|
return h.f(h.bytesBuffer[:])
|
|
}
|