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 @@ -43,10 +43,7 @@ public Optional<OperationInvalidReason> validate(
check(
header1.getProposer_index().equals(header2.getProposer_index()),
ProposerSlashingInvalidReason.PROPOSER_INDICES_DIFFERENT),
() ->
check(
!Objects.equals(proposerSlashing.getHeader_1(), proposerSlashing.getHeader_2()),
ProposerSlashingInvalidReason.SAME_HEADER),
() -> check(!Objects.equals(header1, header2), ProposerSlashingInvalidReason.SAME_HEADER),
() ->
check(
UInt64.valueOf(state.getValidators().size()).compareTo(header1.getProposer_index())
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,24 @@ 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 header1 = dataStructureUtil.randomSignedBeaconBlockHeader();
SignedBeaconBlockHeader header2 =
new SignedBeaconBlockHeader(header1.getMessage(), BLSSignature.random(100));
assertThat(header2).isNotEqualTo(header1);
ProposerSlashing slashing = new ProposerSlashing(header1, header2);
assertThat(
stateTransitionValidator.validate(
recentChainData.getBestState().orElseThrow(), slashing))
.isEqualTo(
Optional.of(
ProposerSlashingStateTransitionValidator.ProposerSlashingInvalidReason
.SAME_HEADER));
}
}