Skip to content

Commit

Permalink
Move electra attestation's committeeBits at the end (#8344)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr authored Jun 21, 2024
1 parent b4ea254 commit 6daa0bc
Show file tree
Hide file tree
Showing 18 changed files with 54 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SszBitvector>) () -> committeeBits.sszDeserialize(committee_bits))
.orElse(() -> null),
signature.asInternalBLSSignature());
.orElse(() -> null));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public interface AttestationSchema<T extends Attestation> extends SszContainerSc
Attestation create(
final SszBitlist aggregationBits,
final AttestationData data,
final Supplier<SszBitvector> committeeBits,
final BLSSignature signature);
final BLSSignature signature,
final Supplier<SszBitvector> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import tech.pegasys.teku.spec.datastructures.type.SszSignature;

public class AttestationElectra
extends Container4<AttestationElectra, SszBitlist, AttestationData, SszBitvector, SszSignature>
extends Container4<AttestationElectra, SszBitlist, AttestationData, SszSignature, SszBitvector>
implements Attestation {

public AttestationElectra(final AttestationElectraSchema type, final TreeNode backingNode) {
Expand All @@ -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
Expand Down Expand Up @@ -73,12 +73,12 @@ public AttestationData getData() {

@Override
public Optional<SszBitvector> getCommitteeBits() {
return Optional.of(getField2());
return Optional.of(getField3());
}

@Override
public BLSSignature getAggregateSignature() {
return getField3().getSignature();
return getField2().getSignature();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

public class AttestationElectraSchema
extends ContainerSchema4<
AttestationElectra, SszBitlist, AttestationData, SszBitvector, SszSignature>
AttestationElectra, SszBitlist, AttestationData, SszSignature, SszBitvector>
implements AttestationSchema<AttestationElectra> {

public AttestationElectraSchema(
Expand All @@ -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
Expand All @@ -52,7 +52,7 @@ public SszBitlistSchema<?> getAggregationBitsSchema() {

@Override
public Optional<SszBitvectorSchema<?>> getCommitteeBitsSchema() {
return Optional.of((SszBitvectorSchema<?>) getFieldSchema2());
return Optional.of((SszBitvectorSchema<?>) getFieldSchema3());
}

@Override
Expand All @@ -64,19 +64,19 @@ public AttestationElectra createFromBackingNode(final TreeNode node) {
public Attestation create(
final SszBitlist aggregationBits,
final AttestationData data,
final Supplier<SszBitvector> committeeBits,
final BLSSignature signature) {
final BLSSignature signature,
final Supplier<SszBitvector> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public AttestationPhase0 createFromBackingNode(final TreeNode node) {
public Attestation create(
final SszBitlist aggregationBits,
final AttestationData data,
final Supplier<SszBitvector> committeeBits,
final BLSSignature signature) {
final BLSSignature signature,
final Supplier<SszBitvector> committeeBits) {
return new AttestationPhase0(this, aggregationBits, data, signature);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ private static Attestation aggregateAttestations(final List<Attestation> 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) {
Expand Down Expand Up @@ -416,8 +416,8 @@ private Attestation createAttestation(
return attestationSchema.create(
aggregationBitfield,
attestationData,
getCommitteeBitsSupplier(attestationSchema, committeeIndex),
signature);
signature,
getCommitteeBitsSupplier(attestationSchema, committeeIndex));
}

private SszBitlist getAggregationBits(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,8 @@ public Attestation randomAttestation() {
.create(
randomBitlist(),
randomAttestationData(),
this::randomCommitteeBitvector,
randomSignature());
randomSignature(),
this::randomCommitteeBitvector);
}

public Attestation randomAttestation(final long slot) {
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValidatableAttestation> getIncludedAttestations() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ private ValidatableAttestation createAttestation(
return ValidatableAttestation.from(
spec,
attestationSchema.create(
aggregationBits, attestationData, committeeBits, dataStructureUtil.randomSignature()),
aggregationBits, attestationData, dataStructureUtil.randomSignature(), committeeBits),
committeeSizes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static Attestation aggregateAttestations(
.create(
aggregateBits,
firstAttestation.getData(),
committeeBitsSupplier,
BLS.aggregate(signatures));
BLS.aggregate(signatures),
committeeBitsSupplier);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ private Attestation createExpectedAttestation(
}

return attestationSchema.create(
expectedAggregationBits, attestationData, committeeBits, signature);
expectedAggregationBits, attestationData, signature, committeeBits);
}

private void performAndReportDuty() {
Expand Down

0 comments on commit 6daa0bc

Please sign in to comment.