From 4d459b2bbf023ebbdd9bc6bfd38cdc66daa29cdf Mon Sep 17 00:00:00 2001 From: Mehdi AOUADI Date: Mon, 9 Dec 2024 11:17:49 +0100 Subject: [PATCH 1/6] add missing electra attestation processing committee check --- .../common/operations/OperationsTestExecutor.java | 9 --------- .../versions/electra/block/BlockProcessorElectra.java | 11 +++++++++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/common/operations/OperationsTestExecutor.java b/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/common/operations/OperationsTestExecutor.java index 3651eae033d..df11615cc16 100644 --- a/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/common/operations/OperationsTestExecutor.java +++ b/eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/common/operations/OperationsTestExecutor.java @@ -21,7 +21,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.collect.ImmutableMap; -import java.util.List; import java.util.Optional; import tech.pegasys.teku.ethtests.finder.TestDefinition; import tech.pegasys.teku.infrastructure.ssz.SszData; @@ -68,9 +67,6 @@ public class OperationsTestExecutor implements TestExecutor { public static final String EXPECTED_STATE_FILE = "post.ssz_snappy"; - // TODO remove https://github.com/Consensys/teku/issues/8892 - private static final List IGNORED_TEST = List.of("invalid_nonset_bits_for_one_committee"); - private enum Operation { ATTESTER_SLASHING, PROPOSER_SLASHING, @@ -148,11 +144,6 @@ public OperationsTestExecutor(final String dataFileName, final Operation operati @Override public void runTest(final TestDefinition testDefinition) throws Exception { - // TODO remove https://github.com/Consensys/teku/issues/8892 - if (IGNORED_TEST.contains(testDefinition.getTestName())) { - return; - } - final BeaconState preState = loadStateFromSsz(testDefinition, "pre.ssz_snappy"); final DefaultOperationProcessor standardProcessor = diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java index 9bfe1da33b4..9939efd47cb 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Optional; import java.util.function.Supplier; +import java.util.stream.IntStream; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.tuweni.bytes.Bytes32; @@ -732,6 +733,16 @@ private Optional checkCommittees( } final IntList committee = beaconStateAccessorsElectra.getBeaconCommittee(state, slot, committeeIndex); + final int committeeOffset = participantsCount; + long committeeAttesters = + IntStream.range(0, committee.size()) + .filter( + committeeParticipantIndex -> + aggregationBits.isSet(committeeOffset + committeeParticipantIndex)) + .count(); + if (committeeAttesters == 0) { + return Optional.of(AttestationInvalidReason.PARTICIPANTS_COUNT_MISMATCH); + } participantsCount += committee.size(); } if (participantsCount != aggregationBits.size()) { From 1275cd9fd18872a34bc0ba6c0f4af790e9c2f63a Mon Sep 17 00:00:00 2001 From: Mehdi AOUADI Date: Mon, 9 Dec 2024 11:45:36 +0100 Subject: [PATCH 2/6] missing final --- .../logic/versions/electra/block/BlockProcessorElectra.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java index 9939efd47cb..5e9b1486226 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java @@ -734,7 +734,7 @@ private Optional checkCommittees( final IntList committee = beaconStateAccessorsElectra.getBeaconCommittee(state, slot, committeeIndex); final int committeeOffset = participantsCount; - long committeeAttesters = + final long committeeAttesters = IntStream.range(0, committee.size()) .filter( committeeParticipantIndex -> From 8f291ea277a3ace4e1aee6e9c388cc6e325efedc Mon Sep 17 00:00:00 2001 From: Mehdi AOUADI Date: Mon, 9 Dec 2024 11:47:42 +0100 Subject: [PATCH 3/6] rename variable --- .../logic/versions/electra/block/BlockProcessorElectra.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java index 5e9b1486226..49d63c1b4a7 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java @@ -734,13 +734,13 @@ private Optional checkCommittees( final IntList committee = beaconStateAccessorsElectra.getBeaconCommittee(state, slot, committeeIndex); final int committeeOffset = participantsCount; - final long committeeAttesters = + final long committeeAttesterCount = IntStream.range(0, committee.size()) .filter( committeeParticipantIndex -> aggregationBits.isSet(committeeOffset + committeeParticipantIndex)) .count(); - if (committeeAttesters == 0) { + if (committeeAttesterCount == 0) { return Optional.of(AttestationInvalidReason.PARTICIPANTS_COUNT_MISMATCH); } participantsCount += committee.size(); From d916a56cda4c2e44b63ca814641240a40539d44a Mon Sep 17 00:00:00 2001 From: Mehdi AOUADI Date: Mon, 9 Dec 2024 16:43:31 +0100 Subject: [PATCH 4/6] refactoring --- .../electra/block/BlockProcessorElectra.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java index 49d63c1b4a7..89dc366260a 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java @@ -726,26 +726,25 @@ private Optional checkCommittees( final BeaconState state, final UInt64 slot, final SszBitlist aggregationBits) { - int participantsCount = 0; + int committeeOffset = 0; for (final UInt64 committeeIndex : committeeIndices) { if (committeeIndex.isGreaterThanOrEqualTo(committeeCountPerSlot)) { return Optional.of(AttestationInvalidReason.COMMITTEE_INDEX_TOO_HIGH); } final IntList committee = beaconStateAccessorsElectra.getBeaconCommittee(state, slot, committeeIndex); - final int committeeOffset = participantsCount; - final long committeeAttesterCount = + int currentCommitteeOffset = committeeOffset; + final boolean hasAtLeastOneParticipant = IntStream.range(0, committee.size()) - .filter( + .anyMatch( committeeParticipantIndex -> - aggregationBits.isSet(committeeOffset + committeeParticipantIndex)) - .count(); - if (committeeAttesterCount == 0) { + aggregationBits.isSet(currentCommitteeOffset + committeeParticipantIndex)); + if (!hasAtLeastOneParticipant) { return Optional.of(AttestationInvalidReason.PARTICIPANTS_COUNT_MISMATCH); } - participantsCount += committee.size(); + committeeOffset += committee.size(); } - if (participantsCount != aggregationBits.size()) { + if (committeeOffset != aggregationBits.size()) { return Optional.of(AttestationInvalidReason.PARTICIPANTS_COUNT_MISMATCH); } return Optional.empty(); From f9bb956cc7641ace81c16437fd0536d5cb5003a3 Mon Sep 17 00:00:00 2001 From: Mehdi AOUADI Date: Mon, 9 Dec 2024 16:45:49 +0100 Subject: [PATCH 5/6] missing final --- .../logic/versions/electra/block/BlockProcessorElectra.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java index 89dc366260a..f49cd04fb86 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java @@ -733,7 +733,7 @@ private Optional checkCommittees( } final IntList committee = beaconStateAccessorsElectra.getBeaconCommittee(state, slot, committeeIndex); - int currentCommitteeOffset = committeeOffset; + final int currentCommitteeOffset = committeeOffset; final boolean hasAtLeastOneParticipant = IntStream.range(0, committee.size()) .anyMatch( From 425db21ce9c1ad1ec12d08c82da67c7efc8e8ff8 Mon Sep 17 00:00:00 2001 From: Mehdi AOUADI Date: Mon, 9 Dec 2024 17:15:12 +0100 Subject: [PATCH 6/6] rename variable --- .../logic/versions/electra/block/BlockProcessorElectra.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java index f49cd04fb86..8693f37efc0 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java @@ -734,12 +734,12 @@ private Optional checkCommittees( final IntList committee = beaconStateAccessorsElectra.getBeaconCommittee(state, slot, committeeIndex); final int currentCommitteeOffset = committeeOffset; - final boolean hasAtLeastOneParticipant = + final boolean committeeHasAtLeastOneAttester = IntStream.range(0, committee.size()) .anyMatch( committeeParticipantIndex -> aggregationBits.isSet(currentCommitteeOffset + committeeParticipantIndex)); - if (!hasAtLeastOneParticipant) { + if (!committeeHasAtLeastOneAttester) { return Optional.of(AttestationInvalidReason.PARTICIPANTS_COUNT_MISMATCH); } committeeOffset += committee.size();