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

adding nil checks on attestation interface #14638

Merged
merged 18 commits into from
Nov 18, 2024

Conversation

james-prysm
Copy link
Contributor

@james-prysm james-prysm commented Nov 12, 2024

What type of PR is this?

Other

What does this PR do? Why is it needed?

nil checks are not working correctly for some checks as they are interfaces, tested in https://go.dev/play/p/T-wHFxweyxX
instead we should have IsNil functions to check the underlying type for nil like https://go.dev/play/p/YPJdA_LMuQz

interfaces in Go: An interface is nil only when its type and value are both nil.
Typed nil in Interfaces: An interface holding a typed nil is not nil.
IsNil() is needed because we cannot rely on a simple nil check on the interface and must check if the underlying value is nil.

Which issues(s) does this PR fix?

Fixes #

Other notes for review

Acknowledgements

  • I have read CONTRIBUTING.md.
  • I have made an appropriate entry to CHANGELOG.md.
  • I have added a description to this PR with sufficient context for reviewers to understand this PR.

@james-prysm james-prysm marked this pull request as ready for review November 12, 2024 20:57
@james-prysm james-prysm requested a review from a team as a code owner November 12, 2024 20:57
@james-prysm james-prysm added Electra electra hardfork Bug Something isn't working labels Nov 12, 2024
@james-prysm james-prysm marked this pull request as draft November 12, 2024 21:35
return errors.New("attestation aggregation bits is empty")
}

if len(a.GetSignature()) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we need to check this? The main risk is that code that prepares an attestation for validator signing could run into an error if it uses IsNil somewhere for runtime safety reasons. I feel like these IsNil implementations blur the line between runtime safety and value validation when we start checking for non-zero signature and aggregation bits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it might not be needed, this check was part of the existing REST implementation check, perhaps it's not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe i just need to check outside of this

// IsNil --
func (a *AggregateAttestationAndProof) IsNil() error {
if a == nil {
return errors.New("aggregateAttestationAndProof is nil")
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should lowercase the name of exported types in error messages.

Copy link
Contributor

Choose a reason for hiding this comment

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

you can always say nil AggregateAttestationAndProof value if you're trying to follow lowercase error style guide rules.

@james-prysm james-prysm marked this pull request as ready for review November 12, 2024 22:25
@james-prysm james-prysm marked this pull request as draft November 12, 2024 23:36
@james-prysm james-prysm marked this pull request as ready for review November 12, 2024 23:55
if a.GetData() == nil {
return errors.New("attestation data is nil")
}
if a.GetData().Source == nil || a.GetData().Target == nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

will remove this from here as it breaks a lot of existing unit tests, will keep it in the validate functions

@@ -185,12 +185,13 @@ func IsValidAttestationIndices(ctx context.Context, indexedAttestation ethpb.Ind
_, span := trace.StartSpan(ctx, "attestationutil.IsValidAttestationIndices")
defer span.End()

if indexedAttestation == nil ||
indexedAttestation.GetData() == nil ||
indexedAttestation.GetData().Target == nil ||
Copy link
Contributor Author

Choose a reason for hiding this comment

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

why does this only check target and not source?

@james-prysm james-prysm marked this pull request as draft November 13, 2024 02:58
@james-prysm james-prysm marked this pull request as ready for review November 13, 2024 03:20
indexedAttestation.GetData().Target == nil ||
indexedAttestation.GetAttestingIndices() == nil {
if indexedAttestation == nil || indexedAttestation.IsNil() ||
indexedAttestation.GetData().Target == nil || indexedAttestation.GetData().Source == nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a Source nil check here, is that ok?

proto/prysm/v1alpha1/attestation.go Outdated Show resolved Hide resolved
proto/prysm/v1alpha1/attestation.go Outdated Show resolved Hide resolved
@james-prysm james-prysm added this pull request to the merge queue Nov 18, 2024
Merged via the queue into develop with commit a7ba11d Nov 18, 2024
18 checks passed
@james-prysm james-prysm deleted the attestation-interface-nilcheck branch November 18, 2024 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Electra electra hardfork
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants