Skip to content

Commit

Permalink
add inclusion list signature verification (#8999)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-aouadi authored Jan 15, 2025
1 parent 381b07d commit f011b0b
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 11 deletions.
5 changes: 5 additions & 0 deletions ethereum/spec/src/main/java/tech/pegasys/teku/spec/Spec.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
import tech.pegasys.teku.spec.datastructures.operations.BlsToExecutionChange;
import tech.pegasys.teku.spec.datastructures.operations.Deposit;
import tech.pegasys.teku.spec.datastructures.operations.InclusionList;
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
Expand Down Expand Up @@ -467,6 +468,10 @@ public Bytes computeSigningRoot(final UInt64 slot, final Bytes32 domain) {
return atSlot(slot).miscHelpers().computeSigningRoot(slot, domain);
}

public Bytes computeSigningRoot(final InclusionList inclusionList, final Bytes32 domain) {
return atSlot(inclusionList.getSlot()).miscHelpers().computeSigningRoot(inclusionList, domain);
}

public Bytes computeBuilderApplicationSigningRoot(final UInt64 slot, final Merkleizable object) {
final MiscHelpers miscHelpers = atSlot(slot).miscHelpers();
return miscHelpers.computeSigningRoot(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ public class Domain {
public static final Bytes4 DOMAIN_BLS_TO_EXECUTION_CHANGE = Bytes4.fromHexString("0x0A000000");

// EIP-7805
public static final Bytes4 DOMAIN_IL_COMMITTEE = Bytes4.fromHexString("0x0C000000");
public static final Bytes4 DOMAIN_INCLUSION_LIST_COMMITTEE = Bytes4.fromHexString("0x0C000000");
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateCache;
import tech.pegasys.teku.spec.logic.versions.deneb.helpers.MiscHelpersDeneb;
import tech.pegasys.teku.spec.logic.versions.deneb.types.VersionedHash;
import tech.pegasys.teku.spec.logic.versions.eip7805.helpers.MiscHelpersEip7805;
import tech.pegasys.teku.spec.logic.versions.electra.helpers.MiscHelpersElectra;

public class MiscHelpers {
Expand Down Expand Up @@ -459,4 +460,8 @@ public Optional<MiscHelpersDeneb> toVersionDeneb() {
public Optional<MiscHelpersElectra> toVersionElectra() {
return Optional.empty();
}

public Optional<MiscHelpersEip7805> toVersionEip7805() {
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import java.util.Optional;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.spec.config.SpecConfigElectra;
import tech.pegasys.teku.spec.config.SpecConfigEip7805;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionRequestsDataCodec;
import tech.pegasys.teku.spec.logic.common.AbstractSpecLogic;
import tech.pegasys.teku.spec.logic.common.helpers.Predicates;
Expand All @@ -37,18 +37,19 @@
import tech.pegasys.teku.spec.logic.versions.capella.operations.validation.OperationValidatorCapella;
import tech.pegasys.teku.spec.logic.versions.deneb.helpers.MiscHelpersDeneb;
import tech.pegasys.teku.spec.logic.versions.deneb.util.ForkChoiceUtilDeneb;
import tech.pegasys.teku.spec.logic.versions.eip7805.block.BlockProcessorEip7805;
import tech.pegasys.teku.spec.logic.versions.eip7805.helpers.BeaconStateAccessorsEip7805;
import tech.pegasys.teku.spec.logic.versions.eip7805.helpers.MiscHelpersEip7805;
import tech.pegasys.teku.spec.logic.versions.electra.block.BlockProcessorElectra;
import tech.pegasys.teku.spec.logic.versions.electra.forktransition.ElectraStateUpgrade;
import tech.pegasys.teku.spec.logic.versions.electra.helpers.BeaconStateAccessorsElectra;
import tech.pegasys.teku.spec.logic.versions.electra.helpers.BeaconStateMutatorsElectra;
import tech.pegasys.teku.spec.logic.versions.electra.helpers.MiscHelpersElectra;
import tech.pegasys.teku.spec.logic.versions.electra.helpers.PredicatesElectra;
import tech.pegasys.teku.spec.logic.versions.electra.operations.validation.AttestationDataValidatorElectra;
import tech.pegasys.teku.spec.logic.versions.electra.operations.validation.VoluntaryExitValidatorElectra;
import tech.pegasys.teku.spec.logic.versions.electra.statetransition.epoch.EpochProcessorElectra;
import tech.pegasys.teku.spec.logic.versions.electra.util.AttestationUtilElectra;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsElectra;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsEip7805;

public class SpecLogicEip7805 extends AbstractSpecLogic {
private final Optional<SyncCommitteeUtil> syncCommitteeUtil;
Expand Down Expand Up @@ -95,13 +96,13 @@ private SpecLogicEip7805(
}

public static SpecLogicEip7805 create(
final SpecConfigElectra config,
final SchemaDefinitionsElectra schemaDefinitions,
final SpecConfigEip7805 config,
final SchemaDefinitionsEip7805 schemaDefinitions,
final TimeProvider timeProvider) {
// Helpers
final PredicatesElectra predicates = new PredicatesElectra(config);
final MiscHelpersElectra miscHelpers =
new MiscHelpersElectra(config, predicates, schemaDefinitions);
final MiscHelpersEip7805 miscHelpers =
new MiscHelpersEip7805(config, predicates, schemaDefinitions);
final BeaconStateAccessorsEip7805 beaconStateAccessors =
new BeaconStateAccessorsEip7805(config, predicates, miscHelpers);
final BeaconStateMutatorsElectra beaconStateMutators =
Expand Down Expand Up @@ -157,8 +158,8 @@ public static SpecLogicEip7805 create(
new LightClientUtil(beaconStateAccessors, syncCommitteeUtil, schemaDefinitions);
final ExecutionRequestsDataCodec executionRequestsDataCodec =
new ExecutionRequestsDataCodec(schemaDefinitions.getExecutionRequestsSchema());
final BlockProcessorElectra blockProcessor =
new BlockProcessorElectra(
final BlockProcessorEip7805 blockProcessor =
new BlockProcessorEip7805(
config,
predicates,
miscHelpers,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright Consensys Software Inc., 2025
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.spec.logic.versions.eip7805.block;

import org.apache.tuweni.bytes.Bytes;
import tech.pegasys.teku.bls.BLS;
import tech.pegasys.teku.bls.BLSPublicKey;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.config.SpecConfigElectra;
import tech.pegasys.teku.spec.constants.Domain;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionRequestsDataCodec;
import tech.pegasys.teku.spec.datastructures.operations.InclusionList;
import tech.pegasys.teku.spec.datastructures.operations.SignedInclusionList;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.logic.common.helpers.Predicates;
import tech.pegasys.teku.spec.logic.common.operations.OperationSignatureVerifier;
import tech.pegasys.teku.spec.logic.common.operations.validation.OperationValidator;
import tech.pegasys.teku.spec.logic.common.util.AttestationUtil;
import tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil;
import tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil;
import tech.pegasys.teku.spec.logic.common.util.ValidatorsUtil;
import tech.pegasys.teku.spec.logic.versions.eip7805.helpers.MiscHelpersEip7805;
import tech.pegasys.teku.spec.logic.versions.electra.block.BlockProcessorElectra;
import tech.pegasys.teku.spec.logic.versions.electra.helpers.BeaconStateAccessorsElectra;
import tech.pegasys.teku.spec.logic.versions.electra.helpers.BeaconStateMutatorsElectra;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsElectra;

public class BlockProcessorEip7805 extends BlockProcessorElectra {

public BlockProcessorEip7805(
final SpecConfigElectra specConfig,
final Predicates predicates,
final MiscHelpersEip7805 miscHelpers,
final SyncCommitteeUtil syncCommitteeUtil,
final BeaconStateAccessorsElectra beaconStateAccessors,
final BeaconStateMutatorsElectra beaconStateMutators,
final OperationSignatureVerifier operationSignatureVerifier,
final BeaconStateUtil beaconStateUtil,
final AttestationUtil attestationUtil,
final ValidatorsUtil validatorsUtil,
final OperationValidator operationValidator,
final SchemaDefinitionsElectra schemaDefinitions,
final ExecutionRequestsDataCodec executionRequestsDataCodec) {
super(
specConfig,
predicates,
miscHelpers,
syncCommitteeUtil,
beaconStateAccessors,
beaconStateMutators,
operationSignatureVerifier,
beaconStateUtil,
attestationUtil,
validatorsUtil,
operationValidator,
schemaDefinitions,
executionRequestsDataCodec);
}

/** Check if ``signed_inclusion_list`` has a valid signature. */
public boolean isValidInclusionListSignature(
final BeaconState state, final SignedInclusionList signedInclusionList) {
final InclusionList message = signedInclusionList.getMessage();
final UInt64 index = message.getValidatorIndex();
final BLSPublicKey pubkey = state.getValidators().get(index.intValue()).getPublicKey();
final Bytes signingRoot =
miscHelpers.computeSigningRoot(
message,
beaconStateAccessors.getDomain(
state.getForkInfo(),
Domain.DOMAIN_INCLUSION_LIST_COMMITTEE,
miscHelpers.computeEpochAtSlot(state.getSlot())));
return BLS.verify(pubkey, signingRoot, signedInclusionList.getSignature());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static BeaconStateAccessorsEip7805 required(

public IntList getInclusionListCommittee(final BeaconState state, final UInt64 slot) {
final UInt64 epoch = miscHelpers.computeEpochAtSlot(slot);
final Bytes32 seed = getSeed(state, epoch, Domain.DOMAIN_IL_COMMITTEE);
final Bytes32 seed = getSeed(state, epoch, Domain.DOMAIN_INCLUSION_LIST_COMMITTEE);
final IntList indices = getActiveValidatorIndices(state, epoch);
final int activeValidatorCount = indices.size();
final UInt64 start =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright Consensys Software Inc., 2025
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.spec.logic.versions.eip7805.helpers;

import java.util.Optional;
import tech.pegasys.teku.spec.config.SpecConfigEip7805;
import tech.pegasys.teku.spec.config.SpecConfigElectra;
import tech.pegasys.teku.spec.logic.common.helpers.MiscHelpers;
import tech.pegasys.teku.spec.logic.versions.electra.helpers.MiscHelpersElectra;
import tech.pegasys.teku.spec.logic.versions.electra.helpers.PredicatesElectra;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsEip7805;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsElectra;

public class MiscHelpersEip7805 extends MiscHelpersElectra {

public MiscHelpersEip7805(
final SpecConfigEip7805 specConfig,
final PredicatesElectra predicates,
final SchemaDefinitionsEip7805 schemaDefinitions) {
super(
SpecConfigElectra.required(specConfig),
predicates,
SchemaDefinitionsElectra.required(schemaDefinitions));
}

public static MiscHelpersEip7805 required(final MiscHelpers miscHelpers) {
return miscHelpers
.toVersionEip7805()
.orElseThrow(
() ->
new IllegalArgumentException(
"Expected Eip7805 misc helpers but got: "
+ miscHelpers.getClass().getSimpleName()));
}

@Override
public Optional<MiscHelpersEip7805> toVersionEip7805() {
return Optional.of(this);
}
}

0 comments on commit f011b0b

Please sign in to comment.