Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
- Loading branch information
Showing
4 changed files
with
67 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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[:]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters