mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-04 00:44:27 +00:00
1065617087
* first commit, remote att types * no more agg attestation proto * regen mock * only attestations * proto * att process * fix att references * more tests passing * use att protos * complete * Update dependency com_github_deckarep_golang_set to v1 (#1159) * Update dependency com_github_edsrzf_mmap_go to v1 (#1160) * Update dependency com_github_go_stack_stack to v1 (#1161) * Update dependency com_github_rs_cors to v1 (#1162) * Update dependency in_gopkg_urfave_cli_v1 to v1 (#1163) * change visibility
70 lines
2.2 KiB
Go
70 lines
2.2 KiB
Go
package attestations
|
|
|
|
import (
|
|
"encoding/binary"
|
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
)
|
|
|
|
// CreateAttestationMsg hashes parentHashes + shardID + slotNumber +
|
|
// shardBlockHash + justifiedSlot into a message to use for verifying
|
|
// with aggregated public key and signature.
|
|
func CreateAttestationMsg(
|
|
blockHash []byte,
|
|
slot uint64,
|
|
shardID uint64,
|
|
justifiedSlot uint64,
|
|
forkVersion uint64,
|
|
) [32]byte {
|
|
msg := make([]byte, binary.MaxVarintLen64)
|
|
binary.BigEndian.PutUint64(msg, forkVersion)
|
|
binary.PutUvarint(msg, slot%params.BeaconConfig().CycleLength)
|
|
binary.PutUvarint(msg, shardID)
|
|
msg = append(msg, blockHash...)
|
|
binary.PutUvarint(msg, justifiedSlot)
|
|
return hashutil.Hash(msg)
|
|
}
|
|
|
|
// Key generates the blake2b hash of the following attestation fields:
|
|
// slotNumber + shardID + blockHash + obliqueParentHash
|
|
// This is used for attestation table look up in localDB.
|
|
func Key(att *pb.AttestationData) [32]byte {
|
|
key := make([]byte, binary.MaxVarintLen64)
|
|
binary.PutUvarint(key, att.GetSlot())
|
|
binary.PutUvarint(key, att.GetShard())
|
|
key = append(key, att.GetShardBlockRootHash32()...)
|
|
return hashutil.Hash(key)
|
|
}
|
|
|
|
// VerifyProposerAttestation verifies the proposer's attestation of the block.
|
|
// Proposers broadcast the attestation along with the block to its peers.
|
|
func VerifyProposerAttestation(att *pb.AttestationData, pubKey [32]byte, proposerShardID uint64) error {
|
|
// Verify the attestation attached with block response.
|
|
// Get proposer index and shardID.
|
|
attestationMsg := CreateAttestationMsg(
|
|
att.GetShardBlockRootHash32(),
|
|
att.GetSlot(),
|
|
proposerShardID,
|
|
att.GetJustifiedSlot(),
|
|
params.BeaconConfig().InitialForkVersion,
|
|
)
|
|
_ = attestationMsg
|
|
_ = pubKey
|
|
// TODO(#258): use attestationMsg to verify against signature
|
|
// and public key. Return error if incorrect.
|
|
return nil
|
|
}
|
|
|
|
// ContainsValidator checks if the validator is included in the attestation.
|
|
// TODO(#569): Modify method to accept a single index rather than a bitfield.
|
|
func ContainsValidator(attesterBitfield []byte, bitfield []byte) bool {
|
|
for i := 0; i < len(bitfield); i++ {
|
|
if bitfield[i]&attesterBitfield[i] != 0 {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|