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

Ensure validator indices in attester slashings are valid #2348

Merged
merged 2 commits into from
Jul 14, 2020

Conversation

ajsutton
Copy link
Contributor

PR Description

AttestaterSlashing objects include an IndexedAttestation opening up the possibility that the validator indices it specifies are out of bounds for the validator list. Normally this isn't an issue because we index the attestation ourselves so know the indices are valid.

SignedAggregateAndProof also includes a validator index which must be verified to be in range before looking up the validator public key.

To ensure this category of errors is avoided, ValidatorsUtil.getValidatorPubKey now performs bounds checking and returns an empty Optional if the index is out of range. Callers are updated to handle this and fail validation of the public key is not available.

Fixed Issue(s)

fix #2345

Documentation

  • I thought about documentation and added the documentation label to this PR if updates are required.

Avoid IndexOutOfBoundsException when looking up validator public keys.
@zedt3ster
Copy link

Awesome, thanks @ajsutton.

Normally this isn't an issue because we index the attestation ourselves so know the indices are valid.

Am I right in understanding that this bug would be triggerable when processing a malicious AttesterSlashing contained within a valid block?

@ajsutton
Copy link
Contributor Author

I don't think you could create a valid block with a malicious AttesterSlashing - the block would be invalid if the slashing was but yes you could trigger it from within an invalid block.

@zedt3ster
Copy link

Thanks @ajsutton! Apologies, my wording in the previous comment was poor. What I meant was that nothing prevents a malicious proposer from including this AttesterSlashing in a proposed block. This block would fail the validation process, but in this case would cause Teku to panic. I believe we're on the same page, please feel free to correct me if I'm wrong. Thanks again for the prompt fix!

@ajsutton
Copy link
Contributor Author

Ok yes agreed with that. Except that panic probably isn't the right term for Teku. It's an unhandled exception which gets logged very noisily but it doesn't cause Teku to crash. Essentially any exception produced from processing messages (from gossip or requested blocks) just causes that message to be treated as invalid. It's good to fix things up so that we don't log misleading error messages but the observed behaviour of Teku will wind up correct for any exception thrown from the processing or validation code.

@zedt3ster
Copy link

Great to know, thanks for clarifying!

Copy link
Contributor

@Nashatyrev Nashatyrev left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -150,13 +147,17 @@ public static AttestationProcessingResult is_valid_indexed_attestation(
SSZList<UnsignedLong> indices = indexed_attestation.getAttesting_indices();

List<UnsignedLong> bit_0_indices_sorted =
indices.stream().sorted().distinct().collect(Collectors.toList());
indices.stream().sorted().distinct().collect(toList());
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, is it allowed by our codestyle? I mean methods static import.
(would be just happy is yes 👍)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it is as long as the method name isn't too generic (so this is fine but a static import of valueOf is not). I it passes error prone and aids readability go for it. :)

@ajsutton ajsutton merged commit 016000d into Consensys:master Jul 14, 2020
@ajsutton ajsutton deleted the invalid-validator-index branch July 14, 2020 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Fuzzing] Illegal Index Array Access in Attester Slashing Processing
3 participants