diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/block/AbstractBlockProcessor.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/block/AbstractBlockProcessor.java index 587db7557c3..acd4e37dbf5 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/block/AbstractBlockProcessor.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/block/AbstractBlockProcessor.java @@ -14,7 +14,6 @@ package tech.pegasys.teku.spec.logic.common.block; import static com.google.common.base.Preconditions.checkArgument; -import static tech.pegasys.teku.spec.config.SpecConfig.FAR_FUTURE_EPOCH; import com.google.common.annotations.VisibleForTesting; import it.unimi.dsi.fastutil.ints.IntList; @@ -54,7 +53,6 @@ import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; import tech.pegasys.teku.spec.datastructures.operations.Deposit; import tech.pegasys.teku.spec.datastructures.operations.DepositData; -import tech.pegasys.teku.spec.datastructures.operations.DepositMessage; import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation; import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing; import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit; @@ -682,7 +680,7 @@ private boolean batchVerifyDepositSignatures(final SszList deposits) { final BLSPublicKey pubkey = deposit.getData().getPubkey(); publicKeys.add(List.of(pubkey)); messages.add( - computeDepositSigningRoot( + miscHelpers.computeDepositSigningRoot( pubkey, deposit.getData().getWithdrawalCredentials(), deposit.getData().getAmount())); @@ -760,34 +758,18 @@ public void applyDeposit( // Verify the deposit signature (proof of possession) which is not checked by the deposit // contract if (signatureAlreadyVerified - || isValidDepositSignature(pubkey, withdrawalCredentials, amount, signature)) { - addValidatorToRegistry(state, pubkey, withdrawalCredentials, amount); + || miscHelpers.isValidDepositSignature( + pubkey, withdrawalCredentials, amount, signature)) { + beaconStateMutators.addValidatorToRegistry(state, pubkey, withdrawalCredentials, amount); } else { handleInvalidDeposit(pubkey, maybePubkeyToIndexMap); } } else { - applyDepositToValidatorIndex( - state, - withdrawalCredentials, - signatureAlreadyVerified, - existingIndex.get(), - amount, - pubkey, - signature); + // Increase balance by deposit amount + beaconStateMutators.increaseBalance(state, existingIndex.get(), amount); } } - protected void applyDepositToValidatorIndex( - final MutableBeaconState state, - final Bytes32 withdrawalCredentials, - final boolean signatureAlreadyVerified, - final int validatorIndex, - final UInt64 amount, - final BLSPublicKey pubkey, - final BLSSignature signature) { - beaconStateMutators.increaseBalance(state, validatorIndex, amount); - } - protected void handleInvalidDeposit( final BLSPublicKey pubkey, final Optional> maybePubkeyToIndexMap) { @@ -799,55 +781,6 @@ protected void handleInvalidDeposit( }); } - /** is_valid_deposit_signature */ - protected boolean isValidDepositSignature( - final BLSPublicKey pubkey, - final Bytes32 withdrawalCredentials, - final UInt64 amount, - final BLSSignature signature) { - try { - return depositSignatureVerifier.verify( - pubkey, computeDepositSigningRoot(pubkey, withdrawalCredentials, amount), signature); - } catch (final BlsException e) { - return false; - } - } - - private Bytes computeDepositSigningRoot( - final BLSPublicKey pubkey, final Bytes32 withdrawalCredentials, final UInt64 amount) { - final Bytes32 domain = miscHelpers.computeDomain(Domain.DEPOSIT); - final DepositMessage depositMessage = new DepositMessage(pubkey, withdrawalCredentials, amount); - return miscHelpers.computeSigningRoot(depositMessage, domain); - } - - protected void addValidatorToRegistry( - final MutableBeaconState state, - final BLSPublicKey pubkey, - final Bytes32 withdrawalCredentials, - final UInt64 amount) { - final Validator validator = getValidatorFromDeposit(pubkey, withdrawalCredentials, amount); - LOG.debug("Adding new validator with index {} to state", state.getValidators().size()); - state.getValidators().append(validator); - state.getBalances().appendElement(amount); - } - - protected Validator getValidatorFromDeposit( - final BLSPublicKey pubkey, final Bytes32 withdrawalCredentials, final UInt64 amount) { - final UInt64 effectiveBalance = - amount - .minus(amount.mod(specConfig.getEffectiveBalanceIncrement())) - .min(specConfig.getMaxEffectiveBalance()); - return new Validator( - pubkey, - withdrawalCredentials, - effectiveBalance, - false, - FAR_FUTURE_EPOCH, - FAR_FUTURE_EPOCH, - FAR_FUTURE_EPOCH, - FAR_FUTURE_EPOCH); - } - @Override public void processVoluntaryExits( final MutableBeaconState state, @@ -905,13 +838,6 @@ protected BlockValidationResult verifyVoluntaryExits( return BlockValidationResult.SUCCESSFUL; } - protected void processWithdrawalRequests( - final MutableBeaconState state, - final BeaconBlockBody beaconBlockBody, - final Supplier validatorExitContextSupplier) { - // No WithdrawalRequests until Electra - } - @Override public void processDepositRequests( final MutableBeaconState state, final List depositRequests) { @@ -952,13 +878,6 @@ protected void safelyProcess(final BlockProcessingAction action) throws BlockPro } } - protected void assertCondition(final boolean condition, final String errorMessage) - throws BlockProcessingException { - if (!condition) { - throw new BlockProcessingException(errorMessage); - } - } - public interface IndexedAttestationProvider { IndexedAttestation getIndexedAttestation(final Attestation attestation); diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/helpers/BeaconStateMutators.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/helpers/BeaconStateMutators.java index f0c5d6d85ef..628e5ff437d 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/helpers/BeaconStateMutators.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/helpers/BeaconStateMutators.java @@ -19,6 +19,10 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Supplier; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.tuweni.bytes.Bytes32; +import tech.pegasys.teku.bls.BLSPublicKey; import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.config.SpecConfig; import tech.pegasys.teku.spec.datastructures.state.Validator; @@ -27,6 +31,8 @@ import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState; public class BeaconStateMutators { + private static final Logger LOG = LogManager.getLogger(); + protected final SpecConfig specConfig; protected final MiscHelpers miscHelpers; private final BeaconStateAccessors beaconStateAccessors; @@ -142,6 +148,22 @@ public Supplier createValidatorExitContextSupplier( return Suppliers.memoize(() -> createValidatorExitContext(state)); } + /** + * add_validator_to_registry + */ + public void addValidatorToRegistry( + final MutableBeaconState state, + final BLSPublicKey pubkey, + final Bytes32 withdrawalCredentials, + final UInt64 amount) { + final Validator validator = + miscHelpers.getValidatorFromDeposit(pubkey, withdrawalCredentials, amount); + LOG.debug("Adding new validator with index {} to state", state.getValidators().size()); + state.getValidators().append(validator); + state.getBalances().appendElement(amount); + } + /** * This function implements an optimized version of exitQueueEpoch and exitQueueChurn calculation, * compared to the `initiate_validator_exit` reference implementation. diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/helpers/MiscHelpers.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/helpers/MiscHelpers.java index 3ff2ab071bf..559f3a01c87 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/helpers/MiscHelpers.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/helpers/MiscHelpers.java @@ -15,6 +15,8 @@ import static com.google.common.base.Preconditions.checkArgument; import static tech.pegasys.teku.infrastructure.crypto.Hash.getSha256Instance; +import static tech.pegasys.teku.spec.config.SpecConfig.FAR_FUTURE_EPOCH; +import static tech.pegasys.teku.spec.logic.common.block.AbstractBlockProcessor.depositSignatureVerifier; import static tech.pegasys.teku.spec.logic.common.helpers.MathHelpers.bytesToUInt64; import static tech.pegasys.teku.spec.logic.common.helpers.MathHelpers.uint64ToBytes; import static tech.pegasys.teku.spec.logic.common.helpers.MathHelpers.uintTo4Bytes; @@ -27,6 +29,9 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.units.bigints.UInt256; +import tech.pegasys.teku.bls.BLSPublicKey; +import tech.pegasys.teku.bls.BLSSignature; +import tech.pegasys.teku.bls.impl.BlsException; import tech.pegasys.teku.infrastructure.bytes.Bytes4; import tech.pegasys.teku.infrastructure.crypto.Hash; import tech.pegasys.teku.infrastructure.crypto.Sha256; @@ -37,10 +42,12 @@ import tech.pegasys.teku.kzg.KZG; import tech.pegasys.teku.kzg.KZGCommitment; import tech.pegasys.teku.spec.config.SpecConfig; +import tech.pegasys.teku.spec.constants.Domain; import tech.pegasys.teku.spec.constants.NetworkConstants; import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar; import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock; import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; +import tech.pegasys.teku.spec.datastructures.operations.DepositMessage; import tech.pegasys.teku.spec.datastructures.state.ForkData; import tech.pegasys.teku.spec.datastructures.state.SigningData; import tech.pegasys.teku.spec.datastructures.state.Validator; @@ -326,6 +333,13 @@ public Bytes32 computeSigningRoot(final Bytes bytes, final Bytes32 domain) { return domainWrappedObject.hashTreeRoot(); } + public Bytes computeDepositSigningRoot( + final BLSPublicKey pubkey, final Bytes32 withdrawalCredentials, final UInt64 amount) { + final Bytes32 domain = computeDomain(Domain.DEPOSIT); + final DepositMessage depositMessage = new DepositMessage(pubkey, withdrawalCredentials, amount); + return computeSigningRoot(depositMessage, domain); + } + public Bytes4 computeForkDigest( final Bytes4 currentVersion, final Bytes32 genesisValidatorsRoot) { return new Bytes4(computeForkDataRoot(currentVersion, genesisValidatorsRoot).slice(0, 4)); @@ -400,6 +414,38 @@ public boolean isFormerDepositMechanismDisabled(final BeaconState state) { return false; } + /** is_valid_deposit_signature */ + public boolean isValidDepositSignature( + final BLSPublicKey pubkey, + final Bytes32 withdrawalCredentials, + final UInt64 amount, + final BLSSignature signature) { + try { + return depositSignatureVerifier.verify( + pubkey, computeDepositSigningRoot(pubkey, withdrawalCredentials, amount), signature); + } catch (final BlsException e) { + return false; + } + } + + /** get_validator_from_deposit */ + public Validator getValidatorFromDeposit( + final BLSPublicKey pubkey, final Bytes32 withdrawalCredentials, final UInt64 amount) { + final UInt64 effectiveBalance = + amount + .minus(amount.mod(specConfig.getEffectiveBalanceIncrement())) + .min(specConfig.getMaxEffectiveBalance()); + return new Validator( + pubkey, + withdrawalCredentials, + effectiveBalance, + false, + FAR_FUTURE_EPOCH, + FAR_FUTURE_EPOCH, + FAR_FUTURE_EPOCH, + FAR_FUTURE_EPOCH); + } + public Optional toVersionDeneb() { return Optional.empty(); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/altair/block/BlockProcessorAltair.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/altair/block/BlockProcessorAltair.java index 0a90e8a1778..7f315226e5d 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/altair/block/BlockProcessorAltair.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/altair/block/BlockProcessorAltair.java @@ -213,20 +213,6 @@ public Optional processAttestationProposerReward( return Optional.empty(); } - @Override - protected void addValidatorToRegistry( - final MutableBeaconState state, - final BLSPublicKey pubkey, - final Bytes32 withdrawalCredentials, - final UInt64 amount) { - super.addValidatorToRegistry(state, pubkey, withdrawalCredentials, amount); - final MutableBeaconStateAltair stateAltair = MutableBeaconStateAltair.required(state); - - stateAltair.getPreviousEpochParticipation().append(SszByte.ZERO); - stateAltair.getCurrentEpochParticipation().append(SszByte.ZERO); - stateAltair.getInactivityScores().append(SszUInt64.ZERO); - } - @Override public void processSyncAggregate( final MutableBeaconState baseState, diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/altair/helpers/BeaconStateMutatorsAltair.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/altair/helpers/BeaconStateMutatorsAltair.java index 96dbbdd4859..4af34b7ed14 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/altair/helpers/BeaconStateMutatorsAltair.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/altair/helpers/BeaconStateMutatorsAltair.java @@ -17,10 +17,15 @@ import static tech.pegasys.teku.spec.constants.IncentivizationWeights.WEIGHT_DENOMINATOR; import java.util.function.Supplier; +import org.apache.tuweni.bytes.Bytes32; +import tech.pegasys.teku.bls.BLSPublicKey; +import tech.pegasys.teku.infrastructure.ssz.primitive.SszByte; +import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt64; import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.config.SpecConfigAltair; import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateCache; import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState; +import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.MutableBeaconStateAltair; import tech.pegasys.teku.spec.logic.common.helpers.BeaconStateAccessors; import tech.pegasys.teku.spec.logic.common.helpers.BeaconStateMutators; import tech.pegasys.teku.spec.logic.common.helpers.MiscHelpers; @@ -36,6 +41,20 @@ public BeaconStateMutatorsAltair( this.specConfigAltair = specConfig; } + @Override + public void addValidatorToRegistry( + final MutableBeaconState state, + final BLSPublicKey pubkey, + final Bytes32 withdrawalCredentials, + final UInt64 amount) { + super.addValidatorToRegistry(state, pubkey, withdrawalCredentials, amount); + final MutableBeaconStateAltair stateAltair = MutableBeaconStateAltair.required(state); + + stateAltair.getPreviousEpochParticipation().append(SszByte.ZERO); + stateAltair.getCurrentEpochParticipation().append(SszByte.ZERO); + stateAltair.getInactivityScores().append(SszUInt64.ZERO); + } + @Override protected UInt64 calculateProposerReward(final UInt64 whistleblowerReward) { return whistleblowerReward.times(PROPOSER_WEIGHT).dividedBy(WEIGHT_DENOMINATOR); 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 03c9228ec12..49493302242 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 @@ -33,7 +33,6 @@ import tech.pegasys.teku.infrastructure.ssz.SszList; import tech.pegasys.teku.infrastructure.ssz.SszMutableList; import tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist; -import tech.pegasys.teku.infrastructure.ssz.primitive.SszByte; import tech.pegasys.teku.infrastructure.ssz.primitive.SszBytes32; import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt64; import tech.pegasys.teku.infrastructure.unsigned.UInt64; @@ -196,18 +195,6 @@ protected void verifyOutstandingDepositsAreProcessed( } } - @Override - protected void processWithdrawalRequests( - final MutableBeaconState state, - final BeaconBlockBody beaconBlockBody, - final Supplier validatorExitContextSupplier) { - - this.processWithdrawalRequests( - state, - BeaconBlockBodyElectra.required(beaconBlockBody).getExecutionRequests().getWithdrawals(), - validatorExitContextSupplier); - } - // process_withdrawals @Override public void processWithdrawals( @@ -611,11 +598,7 @@ public boolean isValidSwitchToCompoundingRequest( } // Verify exit for source has not been initiated - if (!sourceValidator.getExitEpoch().equals(FAR_FUTURE_EPOCH)) { - return false; - } - - return true; + return sourceValidator.getExitEpoch().equals(FAR_FUTURE_EPOCH); } @Override @@ -647,8 +630,9 @@ public void applyDeposit( // Verify the deposit signature (proof of possession) which is not checked by the deposit // contract if (signatureAlreadyVerified - || isValidDepositSignature(pubkey, withdrawalCredentials, amount, signature)) { - addValidatorToRegistry(state, pubkey, withdrawalCredentials, ZERO); + || miscHelpers.isValidDepositSignature( + pubkey, withdrawalCredentials, amount, signature)) { + beaconStateMutators.addValidatorToRegistry(state, pubkey, withdrawalCredentials, ZERO); final PendingDeposit deposit = schemaDefinitionsElectra .getPendingDepositSchema() @@ -694,46 +678,6 @@ public void processDepositWithoutCheckingMerkleProof( signatureAlreadyVerified); } - /** add_validator_to_registry */ - @Override - protected void addValidatorToRegistry( - final MutableBeaconState state, - final BLSPublicKey pubkey, - final Bytes32 withdrawalCredentials, - final UInt64 amount) { - final Validator validator = getValidatorFromDeposit(pubkey, withdrawalCredentials, amount); - - final MutableBeaconStateElectra stateElectra = MutableBeaconStateElectra.required(state); - stateElectra.getValidators().append(validator); - stateElectra.getBalances().appendElement(amount); - stateElectra.getPreviousEpochParticipation().append(SszByte.ZERO); - stateElectra.getCurrentEpochParticipation().append(SszByte.ZERO); - stateElectra.getInactivityScores().append(SszUInt64.ZERO); - } - - @Override - protected Validator getValidatorFromDeposit( - final BLSPublicKey pubkey, final Bytes32 withdrawalCredentials, final UInt64 amount) { - final Validator validator = - new Validator( - pubkey, - withdrawalCredentials, - ZERO, - false, - FAR_FUTURE_EPOCH, - FAR_FUTURE_EPOCH, - FAR_FUTURE_EPOCH, - FAR_FUTURE_EPOCH); - - final UInt64 maxEffectiveBalance = miscHelpers.getMaxEffectiveBalance(validator); - final UInt64 validatorEffectiveBalance = - amount - .minusMinZero(amount.mod(specConfig.getEffectiveBalanceIncrement())) - .min(maxEffectiveBalance); - - return validator.withEffectiveBalance(validatorEffectiveBalance); - } - @Override protected void assertAttestationValid( final MutableBeaconState state, final Attestation attestation) { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/helpers/MiscHelpersElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/helpers/MiscHelpersElectra.java index 2c99e2236cf..52f05f74dea 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/helpers/MiscHelpersElectra.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/helpers/MiscHelpersElectra.java @@ -13,9 +13,13 @@ package tech.pegasys.teku.spec.logic.versions.electra.helpers; +import static tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO; +import static tech.pegasys.teku.spec.config.SpecConfig.FAR_FUTURE_EPOCH; + import it.unimi.dsi.fastutil.ints.IntList; import java.util.Optional; import org.apache.tuweni.bytes.Bytes32; +import tech.pegasys.teku.bls.BLSPublicKey; import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.config.SpecConfigDeneb; import tech.pegasys.teku.spec.config.SpecConfigElectra; @@ -71,6 +75,29 @@ public UInt64 getMaxEffectiveBalance(final Validator validator) { : specConfigElectra.getMinActivationBalance(); } + @Override + public Validator getValidatorFromDeposit( + final BLSPublicKey pubkey, final Bytes32 withdrawalCredentials, final UInt64 amount) { + final Validator validator = + new Validator( + pubkey, + withdrawalCredentials, + ZERO, + false, + FAR_FUTURE_EPOCH, + FAR_FUTURE_EPOCH, + FAR_FUTURE_EPOCH, + FAR_FUTURE_EPOCH); + + final UInt64 maxEffectiveBalance = getMaxEffectiveBalance(validator); + final UInt64 validatorEffectiveBalance = + amount + .minusMinZero(amount.mod(specConfig.getEffectiveBalanceIncrement())) + .min(maxEffectiveBalance); + + return validator.withEffectiveBalance(validatorEffectiveBalance); + } + @Override public Optional toVersionElectra() { return Optional.of(this); diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/statetransition/epoch/EpochProcessorElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/statetransition/epoch/EpochProcessorElectra.java index 2dafe8d7328..7c40eefecc1 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/statetransition/epoch/EpochProcessorElectra.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/statetransition/epoch/EpochProcessorElectra.java @@ -16,17 +16,14 @@ import static tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO; import static tech.pegasys.teku.spec.config.SpecConfig.FAR_FUTURE_EPOCH; import static tech.pegasys.teku.spec.config.SpecConfig.GENESIS_SLOT; -import static tech.pegasys.teku.spec.logic.common.block.AbstractBlockProcessor.depositSignatureVerifier; import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.function.Supplier; import java.util.stream.IntStream; -import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import tech.pegasys.teku.bls.BLSPublicKey; -import tech.pegasys.teku.bls.impl.BlsException; import tech.pegasys.teku.infrastructure.ssz.SszList; import tech.pegasys.teku.infrastructure.ssz.SszMutableList; import tech.pegasys.teku.infrastructure.ssz.collections.SszUInt64List; @@ -36,8 +33,6 @@ import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.config.SpecConfig; import tech.pegasys.teku.spec.config.SpecConfigElectra; -import tech.pegasys.teku.spec.constants.Domain; -import tech.pegasys.teku.spec.datastructures.operations.DepositMessage; import tech.pegasys.teku.spec.datastructures.state.Validator; import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateCache; import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState; @@ -204,7 +199,7 @@ public void applyPendingDeposits(final MutableBeaconState state, final PendingDe validatorIndex -> beaconStateMutators.increaseBalance(state, validatorIndex, deposit.getAmount()), () -> { - if (isValidDepositSignature(deposit)) { + if (isValidPendingDepositSignature(deposit)) { addValidatorToRegistry( state, deposit.getPublicKey(), @@ -214,25 +209,12 @@ public void applyPendingDeposits(final MutableBeaconState state, final PendingDe }); } - // TODO-lucas Duplicates method isValidDepositSignature from BlockProcessor - /** is_valid_deposit_signature */ - public boolean isValidDepositSignature(final PendingDeposit deposit) { - try { - return depositSignatureVerifier.verify( - deposit.getPublicKey(), - computeDepositSigningRoot( - deposit.getPublicKey(), deposit.getWithdrawalCredentials(), deposit.getAmount()), - deposit.getSignature()); - } catch (final BlsException e) { - return false; - } - } - - private Bytes computeDepositSigningRoot( - final BLSPublicKey pubkey, final Bytes32 withdrawalCredentials, final UInt64 amount) { - final Bytes32 domain = miscHelpers.computeDomain(Domain.DEPOSIT); - final DepositMessage depositMessage = new DepositMessage(pubkey, withdrawalCredentials, amount); - return miscHelpers.computeSigningRoot(depositMessage, domain); + private boolean isValidPendingDepositSignature(final PendingDeposit deposit) { + return miscHelpers.isValidDepositSignature( + deposit.getPublicKey(), + deposit.getWithdrawalCredentials(), + deposit.getAmount(), + deposit.getSignature()); } // TODO-lucas Duplicates method addValidatorToRegistry from BlockProcessor