Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect attestation with source or target lower then min as slahsable #7902

Closed

Conversation

shayzluf
Copy link
Contributor

Builds off #7868

Feature

What does this PR do? Why is it needed?
To conform with minimal format of the data interchange format of slashing protection we have to apply the minimal source and target rules to the isslashable attestation method and to store those values during json import and by using db functions

Which issues(s) does this PR fix?

Part of #7813

Other notes for review

@shayzluf shayzluf requested a review from a team as a code owner November 22, 2020 16:58
@shayzluf shayzluf requested review from rauljordan, prestonvanloon and terencechain and removed request for a team November 22, 2020 16:58
@shayzluf shayzluf changed the base branch from protection-refactor to minimal_block_signing November 22, 2020 16:59
@@ -35,6 +37,21 @@ func (store *Store) AttestationHistoryForPubKeys(
} else {
attestationHistory = enc
}
var minAtt attHist.MinAttestation
var setMin bool
enc = bucket.Get(attHist.GetMinSourceKey(key))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming here is confusing, on one hand we have bucket keys and also public keys, let's refactor this better

minAtt.Source = bytesutil.BytesToUint64BigEndian(enc)
setMin = true
}
enc = bucket.Get(attHist.GetMinTargetKey(key))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that our attestinghistory package knows about boltdb keys? Is there a way we can better separate those concerns so they are independent?

@@ -44,16 +61,18 @@ func (store *Store) AttestationHistoryForPubKeys(
copy(ehd, ah)
attestationHistoryForVals[pk] = ehd
}
return attestationHistoryForVals, err

return attestationHistoryForVals, minAttForVal, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with these changes, we just need to make sure to amend the godoc for the db function to clarify what it returns

ctx, span := trace.StartSpan(ctx, "Validator.AttestationHistoryForPubKey")
defer span.End()

var err error
var attestingHistory attHist.History
minAtt := attHist.MinAttestation{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if they are empty? Should we consider it as 0 or as far future epoch?

})
return err
}

// SaveMinAttestation saves min attestation values if they are lower from the ones that are currently set in db.
func (store *Store) SaveMinAttestation(ctx context.Context, pubKey [48]byte, minAtt attHist.MinAttestation) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name MinAttestation isn't very informative. We need to rename this to something more explicit that is clear regardless of someone's background in slashing protection. I propose something like EarliestSignedAttestationForPubKey and make public functions follow that convention. EarliestSignedAttestation is more readable


}

func (store *Store) MinAttestation(ctx context.Context, pubKey [48]byte) (*attHist.MinAttestation, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs godoc

@@ -90,6 +91,21 @@ func differenceOutsideWeakSubjectivityBounds(latestEpochWritten, targetEpoch uin
return latestEpochWritten >= wsPeriod && targetEpoch <= latestEpochWritten-wsPeriod
}

func isLowerThenMin(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func isLowerThenMin(
func isLowerThanMin(

targetEpoch uint64,
) bool {
if minAtt == nil {
return false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add a comment where why false. To me, I think it's false because if you don't have a min attestation, that probably means the validator has never attested. Is that right?

return false
}
// Check if source of target epoch of the attestation is lower then the minimum.
if sourceEpoch < minAtt.Source || targetEpoch < minAtt.Target {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if it's equal to min source and target?

@@ -19,8 +19,18 @@ const (
signingRootSize = 32
historySize = targetSize + sourceSize + signingRootSize
minimalSize = latestEpochWrittenSize
// Key prefix to minimal attestation source epoch in attestation bucket.
minimalAttestationSourceEpochKeyPrefix = "minimal-attestation-source-epoch"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are mixing up bolt logic with this package that knows nothing about bolt. Perhaps move to bolt itself or refactor into something more general

@stale
Copy link

stale bot commented Nov 30, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale There hasn't been any activity here in some time... label Nov 30, 2020
@rauljordan rauljordan changed the base branch from minimal_block_signing to develop November 30, 2020 21:41
@rauljordan rauljordan changed the base branch from develop to feature/slashing-interchange November 30, 2020 22:29
@rauljordan
Copy link
Contributor

Closing in favor of #7966

@rauljordan rauljordan closed this Dec 2, 2020
@rauljordan rauljordan deleted the minimal_attestation_signing_take_2 branch March 12, 2021 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale There hasn't been any activity here in some time...
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants