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

Update slasher service to Electra #14812

Merged
merged 5 commits into from
Jan 22, 2025
Merged

Update slasher service to Electra #14812

merged 5 commits into from
Jan 22, 2025

Conversation

rkapka
Copy link
Contributor

@rkapka rkapka commented Jan 20, 2025

What type of PR is this?

Feature

What does this PR do? Why is it needed?

Updates the slasher service and the slasher simulator to handle IndexedAttestationElectra. Because it is possible for an attester slashing to have one offending attestation pre-Electra and the other offending attestation post-Electra, we convert the pre-Electra attestation to a post-Electra one and construct an AttesterSlashingElectra. Because the only difference between IndexedAttestation and IndexedAttestationElectra is the maximum number of attesting indices (increased in Electra), the signature is still valid after the conversion.

@rkapka rkapka requested a review from a team as a code owner January 20, 2025 17:06
@rkapka rkapka requested review from kasey, potuz and james-prysm January 20, 2025 17:06
@rkapka rkapka added Electra electra hardfork Slasher labels Jan 20, 2025

// Ensure the attestation with the lower data root is the first attestation.
if bytes.Compare(existingAttWrapper.DataRoot[:], incomingAttWrapper.DataRoot[:]) > 0 {
slashing = &ethpb.AttesterSlashingElectra{
Copy link
Contributor

Choose a reason for hiding this comment

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

Not covered (while the equivalent for pre-electra is covered).

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 don't think pre-Electra was covered. I added a Phase0 test too

@@ -239,6 +283,49 @@ func TestMaxSpanChunksSlice_CheckSlashable(t *testing.T) {
require.NotEqual(t, (*ethpb.AttesterSlashing)(nil), slashing)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this assert is not valid any more:
If slashing is nil but with (*ethpb.AttesterSlashingElectra) type, then this require.NotEqual will be successful.

slashing, err := chunk.CheckSlashable(ctx, slasherDB, validatorIdx, surroundedVote)
require.NoError(t, err)
// The old record should be converted to Electra and the resulting slashing should be an Electra slashing.
require.NotEqual(t, (*ethpb.AttesterSlashingElectra)(nil), slashing)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this assert is not valid any more:
If slashing is nil but with (*ethpb.AttesterSlashing) type, then this require.NotEqual will be successful.

(And it seems it is actually the case with this test.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. I decided to use the reflect package because I think it's the easiest way to check for a non-nil interface. Simply checking against nil doesn't work

Copy link
Contributor

Choose a reason for hiding this comment

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

Did this test change?

I still see require.NotEqual(t, (*ethpb.AttesterSlashingElectra)(nil), slashing) and slashing being actually nil of type AttSlashing in the test.

unifyAttWrapperVersion(existingAttWrapper, incomingAttWrapper)

postElectra := existingAttWrapper.IndexedAttestation.Version() >= version.Electra
if postElectra {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not covered. (Probably because of #14812 (comment))

// Ensure the attestation with the lower data root is the first attestation.
if bytes.Compare(wrapper_1.DataRoot[:], wrapper_2.DataRoot[:]) > 0 {
postElectra := wrapper_1.IndexedAttestation.Version() >= version.Electra
if postElectra {
Copy link
Contributor

Choose a reason for hiding this comment

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

postElectra not covered.

rkapka and others added 4 commits January 21, 2025 16:29
Co-authored-by: Manu NALEPA <enalepa@offchainlabs.com>
Co-authored-by: Manu NALEPA <enalepa@offchainlabs.com>
@rkapka rkapka added this pull request to the merge queue Jan 22, 2025
Merged via the queue into develop with commit a1eef44 Jan 22, 2025
15 checks passed
@rkapka rkapka deleted the eip-7549-slasher-pt1 branch January 22, 2025 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Electra electra hardfork Slasher
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants