From 6daa0bc42515ba4425bd37a7730215d3f5b0da01 Mon Sep 17 00:00:00 2001 From: Enrico Del Fante Date: Fri, 21 Jun 2024 10:42:07 +0200 Subject: [PATCH] Move electra attestation's committeeBits at the end (#8344) --- .../beacon/schema/AttestationElectra.json | 6 +++--- .../v1/events/schema/AttestationElectra.json | 6 +++--- .../pegasys/teku/api/schema/Attestation.java | 4 ++-- .../operations/AttestationSchema.java | 6 +++--- .../versions/electra/AttestationElectra.java | 12 +++++------ .../electra/AttestationElectraSchema.java | 20 +++++++++---------- .../phase0/AttestationPhase0Schema.java | 4 ++-- .../spec/generator/AttestationGenerator.java | 8 ++++---- .../teku/spec/util/DataStructureUtil.java | 10 +++++----- .../AggregateAttestationBuilder.java | 4 ++-- .../AggregatingAttestationPoolTest.java | 2 +- .../MatchingDataAttestationGroupTest.java | 2 +- .../AttestationBitsAggregatorElectraTest.java | 4 ++-- .../AggregateAttestationValidatorTest.java | 4 ++-- .../ElectraAttestationValidatorTest.java | 8 ++++---- .../attestation/AggregatorUtil.java | 4 ++-- .../AttestationProductionDuty.java | 2 +- .../duties/AttestationProductionDutyTest.java | 2 +- 18 files changed, 54 insertions(+), 54 deletions(-) diff --git a/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/schema/AttestationElectra.json b/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/schema/AttestationElectra.json index ee382fcb268..59d61a7c416 100644 --- a/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/schema/AttestationElectra.json +++ b/data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/schema/AttestationElectra.json @@ -1,7 +1,7 @@ { "title" : "AttestationElectra", "type" : "object", - "required" : [ "aggregation_bits", "data", "committee_bits", "signature" ], + "required" : [ "aggregation_bits", "data", "signature", "committee_bits" ], "properties" : { "aggregation_bits" : { "type" : "string", @@ -12,13 +12,13 @@ "data" : { "$ref" : "#/components/schemas/AttestationData" }, - "committee_bits" : { + "signature" : { "type" : "string", "pattern" : "^0x[a-fA-F0-9]{2,}$", "description" : "SSZ hexadecimal", "format" : "bytes" }, - "signature" : { + "committee_bits" : { "type" : "string", "pattern" : "^0x[a-fA-F0-9]{2,}$", "description" : "SSZ hexadecimal", diff --git a/data/beaconrestapi/src/test/resources/tech/pegasys/teku/beaconrestapi/handlers/v1/events/schema/AttestationElectra.json b/data/beaconrestapi/src/test/resources/tech/pegasys/teku/beaconrestapi/handlers/v1/events/schema/AttestationElectra.json index ee382fcb268..59d61a7c416 100644 --- a/data/beaconrestapi/src/test/resources/tech/pegasys/teku/beaconrestapi/handlers/v1/events/schema/AttestationElectra.json +++ b/data/beaconrestapi/src/test/resources/tech/pegasys/teku/beaconrestapi/handlers/v1/events/schema/AttestationElectra.json @@ -1,7 +1,7 @@ { "title" : "AttestationElectra", "type" : "object", - "required" : [ "aggregation_bits", "data", "committee_bits", "signature" ], + "required" : [ "aggregation_bits", "data", "signature", "committee_bits" ], "properties" : { "aggregation_bits" : { "type" : "string", @@ -12,13 +12,13 @@ "data" : { "$ref" : "#/components/schemas/AttestationData" }, - "committee_bits" : { + "signature" : { "type" : "string", "pattern" : "^0x[a-fA-F0-9]{2,}$", "description" : "SSZ hexadecimal", "format" : "bytes" }, - "signature" : { + "committee_bits" : { "type" : "string", "pattern" : "^0x[a-fA-F0-9]{2,}$", "description" : "SSZ hexadecimal", diff --git a/data/serializer/src/main/java/tech/pegasys/teku/api/schema/Attestation.java b/data/serializer/src/main/java/tech/pegasys/teku/api/schema/Attestation.java index 448dda6ee13..0741720a7a0 100644 --- a/data/serializer/src/main/java/tech/pegasys/teku/api/schema/Attestation.java +++ b/data/serializer/src/main/java/tech/pegasys/teku/api/schema/Attestation.java @@ -76,13 +76,13 @@ public tech.pegasys.teku.spec.datastructures.operations.Attestation asInternalAt return attestationSchema.create( attestationSchema.getAggregationBitsSchema().sszDeserialize(aggregation_bits), data.asInternalAttestationData(), + signature.asInternalBLSSignature(), attestationSchema .getCommitteeBitsSchema() .map( committeeBits -> (Supplier) () -> committeeBits.sszDeserialize(committee_bits)) - .orElse(() -> null), - signature.asInternalBLSSignature()); + .orElse(() -> null)); } @Override diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AttestationSchema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AttestationSchema.java index bafb4b9aaac..3b0b0f880ec 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AttestationSchema.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AttestationSchema.java @@ -28,12 +28,12 @@ public interface AttestationSchema extends SszContainerSc Attestation create( final SszBitlist aggregationBits, final AttestationData data, - final Supplier committeeBits, - final BLSSignature signature); + final BLSSignature signature, + final Supplier committeeBits); default Attestation create( final SszBitlist aggregationBits, final AttestationData data, final BLSSignature signature) { - return create(aggregationBits, data, () -> null, signature); + return create(aggregationBits, data, signature, () -> null); } default SszBitlist createEmptyAggregationBits() { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttestationElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttestationElectra.java index 2a2dca8f1dc..1842c46e897 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttestationElectra.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttestationElectra.java @@ -30,7 +30,7 @@ import tech.pegasys.teku.spec.datastructures.type.SszSignature; public class AttestationElectra - extends Container4 + extends Container4 implements Attestation { public AttestationElectra(final AttestationElectraSchema type, final TreeNode backingNode) { @@ -41,9 +41,9 @@ public AttestationElectra( final AttestationElectraSchema schema, final SszBitlist aggregationBits, final AttestationData data, - final SszBitvector committeeBits, - final BLSSignature signature) { - super(schema, aggregationBits, data, committeeBits, new SszSignature(signature)); + final BLSSignature signature, + final SszBitvector committeeBits) { + super(schema, aggregationBits, data, new SszSignature(signature), committeeBits); } @Override @@ -73,12 +73,12 @@ public AttestationData getData() { @Override public Optional getCommitteeBits() { - return Optional.of(getField2()); + return Optional.of(getField3()); } @Override public BLSSignature getAggregateSignature() { - return getField3().getSignature(); + return getField2().getSignature(); } @Override diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttestationElectraSchema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttestationElectraSchema.java index 23228ab0e2f..1f6597738d1 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttestationElectraSchema.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttestationElectraSchema.java @@ -32,7 +32,7 @@ public class AttestationElectraSchema extends ContainerSchema4< - AttestationElectra, SszBitlist, AttestationData, SszBitvector, SszSignature> + AttestationElectra, SszBitlist, AttestationData, SszSignature, SszBitvector> implements AttestationSchema { public AttestationElectraSchema( @@ -41,8 +41,8 @@ public AttestationElectraSchema( "AttestationElectra", namedSchema("aggregation_bits", SszBitlistSchema.create(maxValidatorsPerAttestation)), namedSchema("data", AttestationData.SSZ_SCHEMA), - namedSchema("committee_bits", SszBitvectorSchema.create(maxCommitteePerSlot)), - namedSchema("signature", SszSignatureSchema.INSTANCE)); + namedSchema("signature", SszSignatureSchema.INSTANCE), + namedSchema("committee_bits", SszBitvectorSchema.create(maxCommitteePerSlot))); } @Override @@ -52,7 +52,7 @@ public SszBitlistSchema getAggregationBitsSchema() { @Override public Optional> getCommitteeBitsSchema() { - return Optional.of((SszBitvectorSchema) getFieldSchema2()); + return Optional.of((SszBitvectorSchema) getFieldSchema3()); } @Override @@ -64,19 +64,19 @@ public AttestationElectra createFromBackingNode(final TreeNode node) { public Attestation create( final SszBitlist aggregationBits, final AttestationData data, - final Supplier committeeBits, - final BLSSignature signature) { + final BLSSignature signature, + final Supplier committeeBits) { final SszBitvector suppliedCommitteeBits = committeeBits.get(); checkNotNull(suppliedCommitteeBits, "committeeBits must be provided in Electra"); - return new AttestationElectra(this, aggregationBits, data, suppliedCommitteeBits, signature); + return new AttestationElectra(this, aggregationBits, data, signature, suppliedCommitteeBits); } public AttestationElectra create( final SszBitlist aggregationBits, final AttestationData data, - final SszBitvector committeeBits, - final BLSSignature signature) { - return new AttestationElectra(this, aggregationBits, data, committeeBits, signature); + final BLSSignature signature, + final SszBitvector committeeBits) { + return new AttestationElectra(this, aggregationBits, data, signature, committeeBits); } @Override diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/AttestationPhase0Schema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/AttestationPhase0Schema.java index 77f3af7f762..322e49abc00 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/AttestationPhase0Schema.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/AttestationPhase0Schema.java @@ -59,8 +59,8 @@ public AttestationPhase0 createFromBackingNode(final TreeNode node) { public Attestation create( final SszBitlist aggregationBits, final AttestationData data, - final Supplier committeeBits, - final BLSSignature signature) { + final BLSSignature signature, + final Supplier committeeBits) { return new AttestationPhase0(this, aggregationBits, data, signature); } diff --git a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/generator/AttestationGenerator.java b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/generator/AttestationGenerator.java index 80828e78e4e..472e2021089 100644 --- a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/generator/AttestationGenerator.java +++ b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/generator/AttestationGenerator.java @@ -110,8 +110,8 @@ private static Attestation aggregateAttestations(final List srcAtte return attestationSchema.create( targetBitlist, srcAttestations.get(0).getData(), - () -> srcAttestations.get(0).getCommitteeBitsRequired(), - targetSig); + targetSig, + () -> srcAttestations.get(0).getCommitteeBitsRequired()); } public Attestation validAttestation(final StateAndBlockSummary blockAndState) { @@ -416,8 +416,8 @@ private Attestation createAttestation( return attestationSchema.create( aggregationBitfield, attestationData, - getCommitteeBitsSupplier(attestationSchema, committeeIndex), - signature); + signature, + getCommitteeBitsSupplier(attestationSchema, committeeIndex)); } private SszBitlist getAggregationBits( diff --git a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/util/DataStructureUtil.java b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/util/DataStructureUtil.java index 55af00cabbf..d715081f5f7 100644 --- a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/util/DataStructureUtil.java +++ b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/util/DataStructureUtil.java @@ -800,8 +800,8 @@ public Attestation randomAttestation() { .create( randomBitlist(), randomAttestationData(), - this::randomCommitteeBitvector, - randomSignature()); + randomSignature(), + this::randomCommitteeBitvector); } public Attestation randomAttestation(final long slot) { @@ -814,15 +814,15 @@ public Attestation randomAttestation(final UInt64 slot) { .create( randomBitlist(), randomAttestationData(slot), - this::randomCommitteeBitvector, - randomSignature()); + randomSignature(), + this::randomCommitteeBitvector); } public Attestation randomAttestation(final AttestationData attestationData) { return spec.getGenesisSchemaDefinitions() .getAttestationSchema() .create( - randomBitlist(), attestationData, this::randomCommitteeBitvector, randomSignature()); + randomBitlist(), attestationData, randomSignature(), this::randomCommitteeBitvector); } public AggregateAndProof randomAggregateAndProof() { diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/AggregateAttestationBuilder.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/AggregateAttestationBuilder.java index 30b7d69fd0b..ef1e4903530 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/AggregateAttestationBuilder.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/AggregateAttestationBuilder.java @@ -71,12 +71,12 @@ public ValidatableAttestation buildAggregate() { .create( currentAggregateBits.getAggregationBits(), attestationData, - currentAggregateBits::getCommitteeBits, BLS.aggregate( includedAttestations.stream() .map(ValidatableAttestation::getAttestation) .map(Attestation::getAggregateSignature) - .toList()))); + .toList()), + currentAggregateBits::getCommitteeBits)); } public Collection getIncludedAttestations() { diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/AggregatingAttestationPoolTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/AggregatingAttestationPoolTest.java index 6e4551cce7e..cd48b97ae74 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/AggregatingAttestationPoolTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/AggregatingAttestationPoolTest.java @@ -586,6 +586,6 @@ private Attestation createAttestation(final AttestationData data, final int... v committeeBits = () -> null; } return attestationSchema.create( - bitlist, data, committeeBits, dataStructureUtil.randomSignature()); + bitlist, data, dataStructureUtil.randomSignature(), committeeBits); } } diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/MatchingDataAttestationGroupTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/MatchingDataAttestationGroupTest.java index 141a90864d8..c19dd5af076 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/MatchingDataAttestationGroupTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/MatchingDataAttestationGroupTest.java @@ -368,7 +368,7 @@ private ValidatableAttestation createAttestation( return ValidatableAttestation.from( spec, attestationSchema.create( - aggregationBits, attestationData, committeeBits, dataStructureUtil.randomSignature()), + aggregationBits, attestationData, dataStructureUtil.randomSignature(), committeeBits), committeeSizes); } } diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/utils/AttestationBitsAggregatorElectraTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/utils/AttestationBitsAggregatorElectraTest.java index 7dab2b056b7..cd0a102dcb7 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/utils/AttestationBitsAggregatorElectraTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/utils/AttestationBitsAggregatorElectraTest.java @@ -545,8 +545,8 @@ private ValidatableAttestation createAttestation( attestationSchema.create( aggregationBits, attestationData, - committeeBits, - dataStructureUtil.randomSignature())); + dataStructureUtil.randomSignature(), + committeeBits)); when(attestation.getCommitteesSize()).thenReturn(Optional.of(committeeSizes)); return attestation; diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/AggregateAttestationValidatorTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/AggregateAttestationValidatorTest.java index f231d642837..b930437cd4c 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/AggregateAttestationValidatorTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/AggregateAttestationValidatorTest.java @@ -448,9 +448,9 @@ private ValidatableAttestation createValidAggregate( .create( sszAggregationBits, attestationData, + BLSSignature.empty(), getCommitteeBitsSupplier( - aggregateAndProofSchema.getAttestationSchema(), committeeIndex), - BLSSignature.empty()); + aggregateAndProofSchema.getAttestationSchema(), committeeIndex)); final SignedAggregateAndProof signedAggregate = signedAggregateAndProofSchema.create( aggregateAndProofSchema.create(validatorIndex, attestation, BLSSignature.empty()), diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/ElectraAttestationValidatorTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/ElectraAttestationValidatorTest.java index c96846d4d6c..b663e664092 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/ElectraAttestationValidatorTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/ElectraAttestationValidatorTest.java @@ -40,8 +40,8 @@ public void shouldRejectAttestationForMultipleCommittees() { .create( attestation.getAggregationBits(), attestation.getData(), - () -> attestation.getSchema().getCommitteeBitsSchema().orElseThrow().ofBits(1, 3), - attestation.getAggregateSignature()); + attestation.getAggregateSignature(), + () -> attestation.getSchema().getCommitteeBitsSchema().orElseThrow().ofBits(1, 3)); // Sanity check assertThat(wrongAttestation.getCommitteeBitsRequired().getBitCount()).isGreaterThan(1); @@ -73,8 +73,8 @@ public void shouldRejectAggregateWithAttestationDataIndexNonZero() { .create( attestation.getAggregationBits(), nonZeroIndexData, - attestation::getCommitteeBitsRequired, - attestation.getAggregateSignature()); + attestation.getAggregateSignature(), + attestation::getCommitteeBitsRequired); // Sanity check assertThat(wrongAttestation.getData().getIndex()).isNotEqualTo(UInt64.ZERO); diff --git a/ethereum/statetransition/src/testFixtures/java/tech/pegasys/teku/statetransition/attestation/AggregatorUtil.java b/ethereum/statetransition/src/testFixtures/java/tech/pegasys/teku/statetransition/attestation/AggregatorUtil.java index 5794d508b2f..03f31a4a0db 100644 --- a/ethereum/statetransition/src/testFixtures/java/tech/pegasys/teku/statetransition/attestation/AggregatorUtil.java +++ b/ethereum/statetransition/src/testFixtures/java/tech/pegasys/teku/statetransition/attestation/AggregatorUtil.java @@ -66,7 +66,7 @@ public static Attestation aggregateAttestations( .create( aggregateBits, firstAttestation.getData(), - committeeBitsSupplier, - BLS.aggregate(signatures)); + BLS.aggregate(signatures), + committeeBitsSupplier); } } diff --git a/validator/client/src/main/java/tech/pegasys/teku/validator/client/duties/attestations/AttestationProductionDuty.java b/validator/client/src/main/java/tech/pegasys/teku/validator/client/duties/attestations/AttestationProductionDuty.java index 72f31680259..c6d97eab41e 100644 --- a/validator/client/src/main/java/tech/pegasys/teku/validator/client/duties/attestations/AttestationProductionDuty.java +++ b/validator/client/src/main/java/tech/pegasys/teku/validator/client/duties/attestations/AttestationProductionDuty.java @@ -218,6 +218,6 @@ private Attestation createSignedAttestation( committeeBitsSchema -> () -> committeeBitsSchema.ofBits(validator.committeeIndex())) .orElse(() -> null); return attestationSchema.create( - aggregationBits, attestationData, committeeBitsSupplier, signature); + aggregationBits, attestationData, signature, committeeBitsSupplier); } } diff --git a/validator/client/src/test/java/tech/pegasys/teku/validator/client/duties/AttestationProductionDutyTest.java b/validator/client/src/test/java/tech/pegasys/teku/validator/client/duties/AttestationProductionDutyTest.java index 0f7d72cba9e..6a2d0a9e215 100644 --- a/validator/client/src/test/java/tech/pegasys/teku/validator/client/duties/AttestationProductionDutyTest.java +++ b/validator/client/src/test/java/tech/pegasys/teku/validator/client/duties/AttestationProductionDutyTest.java @@ -547,7 +547,7 @@ private Attestation createExpectedAttestation( } return attestationSchema.create( - expectedAggregationBits, attestationData, committeeBits, signature); + expectedAggregationBits, attestationData, signature, committeeBits); } private void performAndReportDuty() {