mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-09 03:01:19 +00:00
1b5b8a57e0
* Update io_kubernetes_build commit hash to 1246899 * Update dependency build_bazel_rules_nodejs to v0.33.1 * Update dependency com_github_hashicorp_golang_lru to v0.5.1 * Update libp2p * Update io_bazel_rules_k8s commit hash to e68d5d7 * Starting to remove old protos * Bazel build proto passes * Fixing pb version * Cleaned up core package * Fixing tests * 6 tests failing * Update proto bugs * Fixed incorrect validator ordering proto * Sync with master * Update go-ssz commit * Removed bad copies from v1alpha1 folder * add json spec json to pb handler * add nested proto example * proto/testing test works * fix refactoring build failures * use merged ssz * push latest changes * used forked json encoding * used forked json encoding * fix warning * fix build issues * fix test and lint * fix build * lint
43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
package hashutil
|
|
|
|
import (
|
|
"reflect"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
|
)
|
|
|
|
// DepositHash returns the sha256 of the information contained in the deposit
|
|
// data as specified in the deposit contract.
|
|
// Spec:
|
|
// pubkey_root: bytes32 = sha256(concat(pubkey, slice(zero_bytes_32, start=0, len=16)))
|
|
// signature_root: bytes32 = sha256(concat(
|
|
// sha256(slice(signature, start=0, len=64)),
|
|
// sha256(concat(slice(signature, start=64, len=32), zero_bytes_32))
|
|
// ))
|
|
// value: bytes32 = sha256(concat(
|
|
// sha256(concat(pubkey_root, withdrawal_credentials)),
|
|
// sha256(concat(
|
|
// amount,
|
|
// slice(zero_bytes_32, start=0, len=24),
|
|
// signature_root,
|
|
// ))
|
|
// ))
|
|
func DepositHash(dep *ethpb.Deposit_Data) ([32]byte, error) {
|
|
if dep == nil || reflect.ValueOf(dep).IsNil() {
|
|
return [32]byte{}, ErrNilProto
|
|
}
|
|
|
|
var zeroBytes [32]byte
|
|
|
|
pubkeyRoot := Hash(append(dep.PublicKey, zeroBytes[:16]...))
|
|
sigHash := Hash(dep.Signature[:64])
|
|
sigZeroBytesHash := Hash(append(dep.Signature[64:96], zeroBytes[:]...))
|
|
sigRoot := Hash(append(sigHash[:], sigZeroBytesHash[:]...))
|
|
|
|
pubRootWCredsHash := Hash(append(pubkeyRoot[:], dep.WithdrawalCredentials...))
|
|
amountSigHash := Hash(append(append(bytesutil.Bytes8(dep.Amount), zeroBytes[:24]...), sigRoot[:]...))
|
|
|
|
return Hash(append(pubRootWCredsHash[:], amountSigHash[:]...)), nil
|
|
}
|