Tidying up a few core functions (#6995)

* DB: add block roots test
* Merge branch 'master' of github.com:prysmaticlabs/prysm
* Merge branch 'master' of github.com:prysmaticlabs/prysm
* Pool: add seen atts map
* Pool: use seen atts map
* Pool: clear seen map
* Merge branch 'master' of github.com:prysmaticlabs/prysm
* Core: clean up unused noverify and tidy up namings
* Gaz
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Core: Add no verify back. Better namings
* Merge branch 'rm-no-verify' of github.com:prysmaticlabs/prysm into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Core: fixed a test
* Merge branch 'rm-no-verify' of github.com:prysmaticlabs/prysm into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
* Merge refs/heads/master into rm-no-verify
This commit is contained in:
terence tsao 2020-08-20 12:53:22 -07:00 committed by GitHub
parent 89e279f9c8
commit 55074bcc6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 45 additions and 46 deletions

View File

@ -61,7 +61,7 @@ func (s *Service) IsValidAttestation(ctx context.Context, att *ethpb.Attestation
return false
}
if err := blocks.VerifyAttestation(ctx, baseState, att); err != nil {
if err := blocks.VerifyAttestationSignature(ctx, baseState, att); err != nil {
log.WithError(err).Error("Failed to validate attestation")
return false
}

View File

@ -67,23 +67,23 @@ func ProcessAttestation(
beaconState *stateTrie.BeaconState,
att *ethpb.Attestation,
) (*stateTrie.BeaconState, error) {
beaconState, err := ProcessAttestationNoVerify(ctx, beaconState, att)
beaconState, err := ProcessAttestationNoVerifySignature(ctx, beaconState, att)
if err != nil {
return nil, err
}
return beaconState, VerifyAttestation(ctx, beaconState, att)
return beaconState, VerifyAttestationSignature(ctx, beaconState, att)
}
// ProcessAttestationsNoVerify applies processing operations to a block's inner attestation
// ProcessAttestationsNoVerifySignature applies processing operations to a block's inner attestation
// records. The only difference would be that the attestation signature would not be verified.
func ProcessAttestationsNoVerify(
func ProcessAttestationsNoVerifySignature(
ctx context.Context,
beaconState *stateTrie.BeaconState,
body *ethpb.BeaconBlockBody,
) (*stateTrie.BeaconState, error) {
var err error
for idx, attestation := range body.Attestations {
beaconState, err = ProcessAttestationNoVerify(ctx, beaconState, attestation)
beaconState, err = ProcessAttestationNoVerifySignature(ctx, beaconState, attestation)
if err != nil {
return nil, errors.Wrapf(err, "could not verify attestation at index %d in block", idx)
}
@ -91,14 +91,14 @@ func ProcessAttestationsNoVerify(
return beaconState, nil
}
// ProcessAttestationNoVerify processes the attestation without verifying the attestation signature. This
// ProcessAttestationNoVerifySignature processes the attestation without verifying the attestation signature. This
// method is used to validate attestations whose signatures have already been verified.
func ProcessAttestationNoVerify(
func ProcessAttestationNoVerifySignature(
ctx context.Context,
beaconState *stateTrie.BeaconState,
att *ethpb.Attestation,
) (*stateTrie.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "core.ProcessAttestationNoVerify")
ctx, span := trace.StartSpan(ctx, "core.ProcessAttestationNoVerifySignature")
defer span.End()
if att == nil || att.Data == nil || att.Data.Target == nil {
@ -199,13 +199,13 @@ func ProcessAttestationNoVerify(
return beaconState, nil
}
// VerifyAttestations will verify the signatures of the provided attestations. This method performs
// VerifyAttestationsSignatures will verify the signatures of the provided attestations. This method performs
// a single BLS verification call to verify the signatures of all of the provided attestations. All
// of the provided attestations must have valid signatures or this method will return an error.
// This method does not determine which attestation signature is invalid, only that one or more
// attestation signatures were not valid.
func VerifyAttestations(ctx context.Context, beaconState *stateTrie.BeaconState, atts []*ethpb.Attestation) error {
ctx, span := trace.StartSpan(ctx, "core.VerifyAttestations")
func VerifyAttestationsSignatures(ctx context.Context, beaconState *stateTrie.BeaconState, atts []*ethpb.Attestation) error {
ctx, span := trace.StartSpan(ctx, "core.VerifyAttestationsSignatures")
defer span.End()
span.AddAttributes(trace.Int64Attribute("attestations", int64(len(atts))))
@ -234,7 +234,7 @@ func VerifyAttestations(ctx context.Context, beaconState *stateTrie.BeaconState,
if err != nil {
return err
}
if err := verifyAttestationsWithDomain(ctx, beaconState, preForkAtts, prevDomain); err != nil {
if err := verifyAttestationsSigWithDomain(ctx, beaconState, preForkAtts, prevDomain); err != nil {
return err
}
} else if len(preForkAtts) > 0 {
@ -249,12 +249,12 @@ func VerifyAttestations(ctx context.Context, beaconState *stateTrie.BeaconState,
return err
}
return verifyAttestationsWithDomain(ctx, beaconState, postForkAtts, currDomain)
return verifyAttestationsSigWithDomain(ctx, beaconState, postForkAtts, currDomain)
}
// VerifyAttestation converts and attestation into an indexed attestation and verifies
// VerifyAttestationSignature converts and attestation into an indexed attestation and verifies
// the signature in that attestation.
func VerifyAttestation(ctx context.Context, beaconState *stateTrie.BeaconState, att *ethpb.Attestation) error {
func VerifyAttestationSignature(ctx context.Context, beaconState *stateTrie.BeaconState, att *ethpb.Attestation) error {
if att == nil || att.Data == nil || att.AggregationBits.Count() == 0 {
return fmt.Errorf("nil or missing attestation data: %v", att)
}
@ -308,7 +308,7 @@ func VerifyIndexedAttestation(ctx context.Context, beaconState *stateTrie.Beacon
// Inner method to verify attestations. This abstraction allows for the domain to be provided as an
// argument.
func verifyAttestationsWithDomain(ctx context.Context, beaconState *stateTrie.BeaconState, atts []*ethpb.Attestation, domain []byte) error {
func verifyAttestationsSigWithDomain(ctx context.Context, beaconState *stateTrie.BeaconState, atts []*ethpb.Attestation, domain []byte) error {
if len(atts) == 0 {
return nil
}

View File

@ -388,7 +388,7 @@ func TestProcessAttestationsNoVerify_IncorrectSlotTargetEpoch(t *testing.T) {
},
}
wanted := fmt.Sprintf("data slot is not in the same epoch as target %d != %d", helpers.SlotToEpoch(att.Data.Slot), att.Data.Target.Epoch)
_, err := blocks.ProcessAttestationNoVerify(context.TODO(), beaconState, att)
_, err := blocks.ProcessAttestationNoVerifySignature(context.TODO(), beaconState, att)
assert.ErrorContains(t, wanted, err)
}
@ -419,7 +419,7 @@ func TestProcessAttestationsNoVerify_OK(t *testing.T) {
require.NoError(t, beaconState.SetCurrentJustifiedCheckpoint(ckp))
require.NoError(t, beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{}))
_, err = blocks.ProcessAttestationNoVerify(context.TODO(), beaconState, att)
_, err = blocks.ProcessAttestationNoVerifySignature(context.TODO(), beaconState, att)
assert.NoError(t, err)
}
@ -444,7 +444,7 @@ func TestProcessAttestationsNoVerify_BadAttIdx(t *testing.T) {
copy(ckp.Root, "hello-world")
require.NoError(t, beaconState.SetCurrentJustifiedCheckpoint(ckp))
require.NoError(t, beaconState.SetCurrentEpochAttestations([]*pb.PendingAttestation{}))
_, err := blocks.ProcessAttestationNoVerify(context.TODO(), beaconState, att)
_, err := blocks.ProcessAttestationNoVerifySignature(context.TODO(), beaconState, att)
require.ErrorContains(t, "committee index 100 >= committee count 1", err)
}
@ -711,7 +711,7 @@ func TestVerifyAttestations_VerifiesMultipleAttestations(t *testing.T) {
}
att2.Signature = bls.AggregateSignatures(sigs).Marshal()
require.NoError(t, blocks.VerifyAttestations(ctx, st, []*ethpb.Attestation{att1, att2}))
require.NoError(t, blocks.VerifyAttestationsSignatures(ctx, st, []*ethpb.Attestation{att1, att2}))
}
func TestVerifyAttestations_HandlesPlannedFork(t *testing.T) {
@ -782,7 +782,7 @@ func TestVerifyAttestations_HandlesPlannedFork(t *testing.T) {
}
att2.Signature = bls.AggregateSignatures(sigs).Marshal()
require.NoError(t, blocks.VerifyAttestations(ctx, st, []*ethpb.Attestation{att1, att2}))
require.NoError(t, blocks.VerifyAttestationsSignatures(ctx, st, []*ethpb.Attestation{att1, att2}))
}
func TestRetrieveAttestationSignatureSet_VerifiesMultipleAttestations(t *testing.T) {

View File

@ -25,7 +25,7 @@ func TestFuzzProcessAttestationNoVerify_10000(t *testing.T) {
fuzzer.Fuzz(state)
fuzzer.Fuzz(att)
s, err := beaconstate.InitializeFromProtoUnsafe(state)
_, err = ProcessAttestationNoVerify(ctx, s, att)
_, err = ProcessAttestationNoVerifySignature(ctx, s, att)
_ = err
}
}
@ -263,7 +263,7 @@ func TestFuzzProcessAttestationsNoVerify_10000(t *testing.T) {
fuzzer.Fuzz(state)
fuzzer.Fuzz(blockBody)
s, err := beaconstate.InitializeFromProtoUnsafe(state)
r, err := ProcessAttestationsNoVerify(ctx, s, blockBody)
r, err := ProcessAttestationsNoVerifySignature(ctx, s, blockBody)
if err != nil && r != nil {
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, blockBody)
}
@ -309,7 +309,7 @@ func TestFuzzVerifyAttestation_10000(t *testing.T) {
fuzzer.Fuzz(state)
fuzzer.Fuzz(attestation)
s, err := beaconstate.InitializeFromProtoUnsafe(state)
err = VerifyAttestation(ctx, s, attestation)
err = VerifyAttestationSignature(ctx, s, attestation)
_ = err
}
}
@ -400,7 +400,7 @@ func TestFuzzProcessVoluntaryExitsNoVerify_10000(t *testing.T) {
fuzzer.Fuzz(state)
fuzzer.Fuzz(blockBody)
s, err := beaconstate.InitializeFromProtoUnsafe(state)
r, err := ProcessVoluntaryExitsNoVerify(s, blockBody)
r, err := ProcessVoluntaryExits(context.Background(), s, blockBody)
if err != nil && r != nil {
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, blockBody)
}
@ -419,7 +419,7 @@ func TestFuzzVerifyExit_10000(t *testing.T) {
fuzzer.Fuzz(val)
fuzzer.Fuzz(fork)
fuzzer.Fuzz(&slot)
err := VerifyExit(val, slot, fork, ve, params.BeaconConfig().ZeroHash[:])
err := VerifyExitAndSignature(val, slot, fork, ve, params.BeaconConfig().ZeroHash[:])
_ = err
}
}

View File

@ -50,7 +50,7 @@ func ProcessVoluntaryExits(
if err != nil {
return nil, err
}
if err := VerifyExit(val, beaconState.Slot(), beaconState.Fork(), exit, beaconState.GenesisValidatorRoot()); err != nil {
if err := VerifyExitAndSignature(val, beaconState.Slot(), beaconState.Fork(), exit, beaconState.GenesisValidatorRoot()); err != nil {
return nil, errors.Wrapf(err, "could not verify exit %d", idx)
}
beaconState, err = v.InitiateValidatorExit(beaconState, exit.Exit.ValidatorIndex)
@ -61,9 +61,10 @@ func ProcessVoluntaryExits(
return beaconState, nil
}
// ProcessVoluntaryExitsNoVerify processes all the voluntary exits in
// ProcessVoluntaryExitsNoVerifySignature processes all the voluntary exits in
// a block body, without verifying their BLS signatures.
func ProcessVoluntaryExitsNoVerify(
// This function is here to satisfy fuzz tests.
func ProcessVoluntaryExitsNoVerifySignature(
beaconState *stateTrie.BeaconState,
body *ethpb.BeaconBlockBody,
) (*stateTrie.BeaconState, error) {
@ -93,7 +94,7 @@ func ProcessVoluntaryExitsNoVerify(
return beaconState, nil
}
// VerifyExit implements the spec defined validation for voluntary exits.
// VerifyExitAndSignature implements the spec defined validation for voluntary exits.
//
// Spec pseudocode definition:
// def process_voluntary_exit(state: BeaconState, exit: VoluntaryExit) -> None:
@ -112,7 +113,7 @@ func ProcessVoluntaryExitsNoVerify(
// # Verify signature
// domain = get_domain(state, DOMAIN_VOLUNTARY_EXIT, exit.epoch)
// assert bls_verify(validator.pubkey, signing_root(exit), exit.signature, domain)
func VerifyExit(validator *stateTrie.ReadOnlyValidator, currentSlot uint64, fork *pb.Fork, signed *ethpb.SignedVoluntaryExit, genesisRoot []byte) error {
func VerifyExitAndSignature(validator *stateTrie.ReadOnlyValidator, currentSlot uint64, fork *pb.Fork, signed *ethpb.SignedVoluntaryExit, genesisRoot []byte) error {
if signed == nil || signed.Exit == nil {
return errors.New("nil exit")
}

View File

@ -43,7 +43,7 @@ func TestProcessVoluntaryExits_ValidatorNotActive(t *testing.T) {
assert.ErrorContains(t, want, err)
// Check conformance of no verify method.
_, err = blocks.ProcessVoluntaryExitsNoVerify(state, block.Body)
_, err = blocks.ProcessVoluntaryExitsNoVerifySignature(state, block.Body)
assert.ErrorContains(t, want, err)
}
@ -76,9 +76,8 @@ func TestProcessVoluntaryExits_InvalidExitEpoch(t *testing.T) {
assert.ErrorContains(t, want, err)
// Check conformance of no verify method.
_, err = blocks.ProcessVoluntaryExitsNoVerify(state, block.Body)
_, err = blocks.ProcessVoluntaryExitsNoVerifySignature(state, block.Body)
assert.ErrorContains(t, want, err)
}
func TestProcessVoluntaryExits_NotActiveLongEnoughToExit(t *testing.T) {
@ -162,12 +161,11 @@ func TestProcessVoluntaryExits_AppliesCorrectStatus(t *testing.T) {
}
// Check conformance with NoVerify Exit Method.
newState, err = blocks.ProcessVoluntaryExitsNoVerify(stateCopy, block.Body)
newState, err = blocks.ProcessVoluntaryExitsNoVerifySignature(stateCopy, block.Body)
require.NoError(t, err, "Could not process exits")
newRegistry = newState.Validators()
if newRegistry[0].ExitEpoch != helpers.ActivationExitEpoch(stateCopy.Slot()/params.BeaconConfig().SlotsPerEpoch) {
t.Errorf("Expected validator exit epoch to be %d, got %d",
helpers.ActivationExitEpoch(stateCopy.Slot()/params.BeaconConfig().SlotsPerEpoch), newRegistry[0].ExitEpoch)
}
}

View File

@ -579,11 +579,11 @@ func ProcessOperations(
if err != nil {
return nil, errors.Wrap(err, "could not process block attester slashings")
}
state, err = b.ProcessAttestationsNoVerify(ctx, state, body)
state, err = b.ProcessAttestationsNoVerifySignature(ctx, state, body)
if err != nil {
return nil, errors.Wrap(err, "could not process block attestations")
}
if err := b.VerifyAttestations(ctx, state, body.Attestations); err != nil {
if err := b.VerifyAttestationsSignatures(ctx, state, body.Attestations); err != nil {
return nil, errors.Wrap(err, "could not verify attestations")
}
state, err = b.ProcessDeposits(ctx, state, body.Deposits)
@ -642,7 +642,7 @@ func ProcessOperationsNoVerifyAttsSigs(
if err != nil {
return nil, errors.Wrap(err, "could not process block attester slashings")
}
state, err = b.ProcessAttestationsNoVerify(ctx, state, body)
state, err = b.ProcessAttestationsNoVerifySignature(ctx, state, body)
if err != nil {
return nil, errors.Wrap(err, "could not process block attestations")
}

View File

@ -35,7 +35,7 @@ func (vs *Server) ProposeExit(ctx context.Context, req *ethpb.SignedVoluntaryExi
if err != nil {
return nil, status.Error(codes.InvalidArgument, "validator index exceeds validator set length")
}
if err := blocks.VerifyExit(val, helpers.StartSlot(req.Exit.Epoch), s.Fork(), req, s.GenesisValidatorRoot()); err != nil {
if err := blocks.VerifyExitAndSignature(val, helpers.StartSlot(req.Exit.Epoch), s.Fork(), req, s.GenesisValidatorRoot()); err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}

View File

@ -130,7 +130,7 @@ func (s *Service) validateAggregatedAtt(ctx context.Context, signed *ethpb.Signe
// Verify aggregated attestation has a valid signature.
if !featureconfig.Get().DisableStrictAttestationPubsubVerification {
if err := blocks.VerifyAttestation(ctx, bs, signed.Message.Aggregate); err != nil {
if err := blocks.VerifyAttestationSignature(ctx, bs, signed.Message.Aggregate); err != nil {
traceutil.AnnotateError(span, err)
return pubsub.ValidationReject
}

View File

@ -131,7 +131,7 @@ func (s *Service) validateCommitteeIndexBeaconAttestation(ctx context.Context, p
// Attestation's signature is a valid BLS signature and belongs to correct public key..
if !featureconfig.Get().DisableStrictAttestationPubsubVerification {
if err := blocks.VerifyAttestation(ctx, preState, att); err != nil {
if err := blocks.VerifyAttestationSignature(ctx, preState, att); err != nil {
log.WithError(err).Error("Could not verify attestation")
traceutil.AnnotateError(span, err)
return pubsub.ValidationReject

View File

@ -61,7 +61,7 @@ func (s *Service) validateVoluntaryExit(ctx context.Context, pid peer.ID, msg *p
if err != nil {
return pubsub.ValidationIgnore
}
if err := blocks.VerifyExit(val, exitedEpochSlot, headState.Fork(), exit, headState.GenesisValidatorRoot()); err != nil {
if err := blocks.VerifyExitAndSignature(val, exitedEpochSlot, headState.Fork(), exit, headState.GenesisValidatorRoot()); err != nil {
return pubsub.ValidationReject
}

View File

@ -24,7 +24,7 @@ func BeaconFuzzAttestation(b []byte) ([]byte, bool) {
if err != nil {
return fail(err)
}
post, err := blocks.ProcessAttestationNoVerify(context.Background(), st, input.Attestation)
post, err := blocks.ProcessAttestationNoVerifySignature(context.Background(), st, input.Attestation)
if err != nil {
return fail(err)
}

View File

@ -23,7 +23,7 @@ func BeaconFuzzVoluntaryExit(b []byte) ([]byte, bool) {
if err != nil {
return fail(err)
}
post, err := blocks.ProcessVoluntaryExitsNoVerify(st, &ethpb.BeaconBlockBody{VoluntaryExits: []*ethpb.SignedVoluntaryExit{{Exit: input.VoluntaryExit}}})
post, err := blocks.ProcessVoluntaryExitsNoVerifySignature(st, &ethpb.BeaconBlockBody{VoluntaryExits: []*ethpb.SignedVoluntaryExit{{Exit: input.VoluntaryExit}}})
if err != nil {
return fail(err)
}