Search in sources :

Example 1 with BeaconBlockHeader

use of tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader in project teku by ConsenSys.

the class OperationSignatureVerifier method verifyProposerSlashingSignature.

public boolean verifyProposerSlashingSignature(Fork fork, BeaconState state, ProposerSlashing proposerSlashing, BLSSignatureVerifier signatureVerifier) {
    final BeaconBlockHeader header1 = proposerSlashing.getHeader_1().getMessage();
    final BeaconBlockHeader header2 = proposerSlashing.getHeader_2().getMessage();
    Optional<BLSPublicKey> maybePublicKey = beaconStateAccessors.getValidatorPubKey(state, header1.getProposerIndex());
    if (maybePublicKey.isEmpty()) {
        return false;
    }
    BLSPublicKey publicKey = maybePublicKey.get();
    if (!signatureVerifier.verify(publicKey, miscHelpers.computeSigningRoot(header1, beaconStateAccessors.getDomain(Domain.BEACON_PROPOSER, miscHelpers.computeEpochAtSlot(header1.getSlot()), fork, state.getGenesis_validators_root())), proposerSlashing.getHeader_1().getSignature())) {
        LOG.trace("Header1 signature is invalid {}", header1);
        return false;
    }
    if (!signatureVerifier.verify(publicKey, miscHelpers.computeSigningRoot(header2, beaconStateAccessors.getDomain(Domain.BEACON_PROPOSER, miscHelpers.computeEpochAtSlot(header2.getSlot()), fork, state.getGenesis_validators_root())), proposerSlashing.getHeader_2().getSignature())) {
        LOG.trace("Header2 signature is invalid {}", header1);
        return false;
    }
    return true;
}
Also used : BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) BeaconBlockHeader(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader)

Example 2 with BeaconBlockHeader

use of tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader in project teku by ConsenSys.

the class DataStructureUtil method randomBlockAndState.

private BeaconBlockAndState randomBlockAndState(final UInt64 slot, final BeaconState state, final Bytes32 parentRoot) {
    final BeaconBlockBody body = randomBeaconBlockBody();
    final UInt64 proposer_index = randomUInt64();
    final BeaconBlockHeader latestHeader = new BeaconBlockHeader(slot, proposer_index, parentRoot, Bytes32.ZERO, body.hashTreeRoot());
    final BeaconState matchingState = state.updated(s -> s.setLatest_block_header(latestHeader));
    final BeaconBlock block = new BeaconBlock(spec.atSlot(slot).getSchemaDefinitions().getBeaconBlockSchema(), slot, proposer_index, parentRoot, matchingState.hashTreeRoot(), body);
    return new BeaconBlockAndState(block, matchingState);
}
Also used : BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BeaconBlockBody(tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody) BeaconBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockAndState) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BeaconBlockHeader(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader) SignedBeaconBlockHeader(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockHeader) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Example 3 with BeaconBlockHeader

use of tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader in project teku by ConsenSys.

the class StateTransition method processSlot.

private BeaconState processSlot(final SpecVersion spec, final BeaconState preState) {
    // Cache state root
    Bytes32 previous_state_root = preState.hashTreeRoot();
    return preState.updated(state -> {
        int index = state.getSlot().mod(spec.getSlotsPerHistoricalRoot()).intValue();
        state.getState_roots().setElement(index, previous_state_root);
        // Cache latest block header state root
        BeaconBlockHeader latest_block_header = state.getLatest_block_header();
        if (latest_block_header.getStateRoot().equals(Bytes32.ZERO)) {
            BeaconBlockHeader latest_block_header_new = new BeaconBlockHeader(latest_block_header.getSlot(), latest_block_header.getProposerIndex(), latest_block_header.getParentRoot(), previous_state_root, latest_block_header.getBodyRoot());
            state.setLatest_block_header(latest_block_header_new);
        }
        // Cache block root
        Bytes32 previous_block_root = state.getLatest_block_header().hashTreeRoot();
        state.getBlock_roots().setElement(index, previous_block_root);
    });
}
Also used : Bytes32(org.apache.tuweni.bytes.Bytes32) BeaconBlockHeader(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader)

Example 4 with BeaconBlockHeader

use of tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader in project teku by ConsenSys.

the class AbstractBlockProcessor method processBlockHeader.

@Override
public void processBlockHeader(MutableBeaconState state, BeaconBlockSummary blockHeader) throws BlockProcessingException {
    safelyProcess(() -> {
        checkArgument(blockHeader.getSlot().equals(state.getSlot()), "process_block_header: Verify that the slots match");
        checkArgument(blockHeader.getProposerIndex().longValue() == beaconStateAccessors.getBeaconProposerIndex(state), "process_block_header: Verify that proposer index is the correct index");
        checkArgument(blockHeader.getParentRoot().equals(state.getLatest_block_header().hashTreeRoot()), "process_block_header: Verify that the parent matches");
        checkArgument(blockHeader.getSlot().compareTo(state.getLatest_block_header().getSlot()) > 0, "process_block_header: Verify that the block is newer than latest block header");
        // Cache the current block as the new latest block
        state.setLatest_block_header(new BeaconBlockHeader(blockHeader.getSlot(), blockHeader.getProposerIndex(), blockHeader.getParentRoot(), // Overwritten in the next `process_slot` call
        Bytes32.ZERO, blockHeader.getBodyRoot()));
        // Only if we are processing blocks (not proposing them)
        Validator proposer = state.getValidators().get(toIntExact(blockHeader.getProposerIndex().longValue()));
        checkArgument(!proposer.isSlashed(), "process_block_header: Verify proposer is not slashed");
    });
}
Also used : BeaconBlockHeader(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader) OperationValidator(tech.pegasys.teku.spec.logic.common.operations.validation.OperationValidator) Validator(tech.pegasys.teku.spec.datastructures.state.Validator)

Example 5 with BeaconBlockHeader

use of tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader in project teku by ConsenSys.

the class AnchorPoint method fromInitialState.

public static AnchorPoint fromInitialState(final Spec spec, final BeaconState state) {
    if (isGenesisState(state)) {
        return fromGenesisState(spec, state);
    } else {
        final BeaconBlockHeader header = BeaconBlockHeader.fromState(state);
        // Calculate closest epoch boundary to use for the checkpoint
        final UInt64 epoch = spec.computeNextEpochBoundary(state.getSlot());
        final Checkpoint checkpoint = new Checkpoint(epoch, header.hashTreeRoot());
        return new AnchorPoint(spec, checkpoint, state, header);
    }
}
Also used : UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BeaconBlockHeader(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader)

Aggregations

BeaconBlockHeader (tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader)8 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)3 Optional (java.util.Optional)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 Test (org.junit.jupiter.api.Test)1 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)1 BeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock)1 BeaconBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockAndState)1 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)1 SignedBeaconBlockHeader (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockHeader)1 SlotAndBlockRoot (tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot)1 BeaconBlockBody (tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody)1 Validator (tech.pegasys.teku.spec.datastructures.state.Validator)1 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)1 BeaconStateAltair (tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.BeaconStateAltair)1 OperationValidator (tech.pegasys.teku.spec.logic.common.operations.validation.OperationValidator)1 ChainHead (tech.pegasys.teku.storage.client.ChainHead)1