Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check equality of proposer slashing signed block header messages #3151

Merged
merged 10 commits into from
Nov 5, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public Optional<OperationInvalidReason> validate(
ProposerSlashingInvalidReason.PROPOSER_INDICES_DIFFERENT),
() ->
check(
!Objects.equals(proposerSlashing.getHeader_1(), proposerSlashing.getHeader_2()),
!Objects.equals(
proposerSlashing.getHeader_1().getMessage(),
proposerSlashing.getHeader_2().getMessage()),
cemozerr marked this conversation as resolved.
Show resolved Hide resolved
ProposerSlashingInvalidReason.SAME_HEADER),
() ->
check(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.bls.BLSKeyPair;
import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.bls.BLSSignatureVerifier;
import tech.pegasys.teku.core.operationsignatureverifiers.ProposerSlashingSignatureVerifier;
import tech.pegasys.teku.core.operationvalidators.ProposerSlashingStateTransitionValidator;
import tech.pegasys.teku.datastructures.blocks.SignedBeaconBlockHeader;
import tech.pegasys.teku.datastructures.interop.MockStartValidatorKeyPairFactory;
import tech.pegasys.teku.datastructures.operations.ProposerSlashing;
import tech.pegasys.teku.datastructures.util.DataStructureUtil;
Expand Down Expand Up @@ -117,4 +119,26 @@ public void shouldIgnoreProposerSlashingForTheSameProposer() throws Exception {
assertThat(proposerSlashingValidator.validate(slashing1)).isEqualTo(ACCEPT);
assertThat(proposerSlashingValidator.validate(slashing2)).isEqualTo(IGNORE);
}

@Test
public void shouldRejectProposerSlashingForTwoSignedHeadersWithSameMessageButDifferentSignature()
throws Exception {
beaconChainUtil.initializeStorage();
beaconChainUtil.createAndImportBlockAtSlot(6);
stateTransitionValidator = new ProposerSlashingStateTransitionValidator();
SignedBeaconBlockHeader signedBeaconBlockHeader =
dataStructureUtil.randomSignedBeaconBlockHeader();
ProposerSlashing slashing =
new ProposerSlashing(
new SignedBeaconBlockHeader(
signedBeaconBlockHeader.getMessage(), BLSSignature.random(100)),
signedBeaconBlockHeader);
cemozerr marked this conversation as resolved.
Show resolved Hide resolved
assertThat(
stateTransitionValidator.validate(
recentChainData.getBestState().orElseThrow(), slashing))
.isEqualTo(
Optional.of(
ProposerSlashingStateTransitionValidator.ProposerSlashingInvalidReason
.SAME_HEADER));
}
}