use of tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody in project web3signer by ConsenSys.
the class Eth2RequestUtils method createBlockRequest.
public static Eth2SigningRequestBody createBlockRequest(final UInt64 slot, final Bytes32 stateRoot) {
final ForkInfo forkInfo = forkInfo();
final BeaconBlock block = new BeaconBlock(slot, UInt64.valueOf(5), Bytes32.fromHexString("0xb2eedb01adbd02c828d5eec09b4c70cbba12ffffba525ebf48aca33028e8ad89"), stateRoot, new BeaconBlockBody(BLSSignature.fromHexString("0xa686652aed2617da83adebb8a0eceea24bb0d2ccec9cd691a902087f90db16aa5c7b03172a35e874e07e3b60c5b2435c0586b72b08dfe5aee0ed6e5a2922b956aa88ad0235b36dfaa4d2255dfeb7bed60578d982061a72c7549becab19b3c12f"), new Eth1Data(Bytes32.fromHexString("0x6a0f9d6cb0868daa22c365563bb113b05f7568ef9ee65fdfeb49a319eaf708cf"), UInt64.valueOf(8), Bytes32.fromHexString("0x4242424242424242424242424242424242424242424242424242424242424242")), Bytes32.fromHexString("0x74656b752f76302e31322e31302d6465762d6338316361363235000000000000"), emptyList(), emptyList(), emptyList(), emptyList(), emptyList()));
final Bytes signingRoot = signingRootUtil.signingRootForSignBlock(block.asInternalBeaconBlock(spec), forkInfo.asInternalForkInfo());
return new Eth2SigningRequestBody(ArtifactType.BLOCK, signingRoot, forkInfo, block, null, null, null, null, null, null, null, null, null, null);
}
use of tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody in project web3signer by ConsenSys.
the class Eth2RequestUtils method createAggregationSlot.
private static Eth2SigningRequestBody createAggregationSlot() {
final ForkInfo forkInfo = forkInfo();
final AggregationSlot aggregationSlot = new AggregationSlot(UInt64.valueOf(119));
final Bytes signingRoot = signingRootUtil.signingRootForSignAggregationSlot(aggregationSlot.getSlot(), forkInfo.asInternalForkInfo());
return new Eth2SigningRequestBody(ArtifactType.AGGREGATION_SLOT, signingRoot, forkInfo, null, null, null, aggregationSlot, null, null, null, null, null, null, null);
}
use of tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody in project web3signer by ConsenSys.
the class SlashingExportAcceptanceTest method slashingDataIsExported.
@Test
void slashingDataIsExported(@TempDir Path testDirectory) throws IOException {
setupSigner(testDirectory, true);
final Eth2SigningRequestBody request = createAttestationRequest(5, 6, UInt64.ZERO);
final Response initialResponse = signer.eth2Sign(keyPair.getPublicKey().toString(), request);
assertThat(initialResponse.getStatusCode()).isEqualTo(200);
assertThat(signer.getMetricsMatching(blockSlashingMetrics)).containsOnly(blockSlashingMetrics.get(0) + " 1.0", blockSlashingMetrics.get(1) + " 0.0");
final Path exportFile = testDirectory.resolve("dbExport.json");
final SignerConfigurationBuilder builder = new SignerConfigurationBuilder();
builder.withMode("eth2");
builder.withSlashingEnabled(true);
builder.withSlashingProtectionDbUrl(signer.getSlashingDbUrl());
builder.withSlashingProtectionDbUsername("postgres");
builder.withSlashingProtectionDbPassword("postgres");
builder.withKeyStoreDirectory(testDirectory);
builder.withSlashingExportPath(exportFile);
// prevent wait for Ports file in AT
builder.withHttpPort(12345);
final Signer exportSigner = new Signer(builder.build(), null);
exportSigner.start();
waitFor(() -> assertThat(exportSigner.isRunning()).isFalse());
final ObjectMapper mapper = new InterchangeJsonProvider().getJsonMapper();
final InterchangeV5Format mappedData = mapper.readValue(exportFile.toFile(), InterchangeV5Format.class);
assertThat(mappedData.getMetadata().getFormatVersion()).isEqualTo("5");
assertThat(mappedData.getMetadata().getGenesisValidatorsRoot()).isEqualTo(Bytes.fromHexString(GENESIS_VALIDATORS_ROOT));
assertThat(mappedData.getSignedArtifacts()).hasSize(1);
final SignedArtifacts artifacts = mappedData.getSignedArtifacts().get(0);
assertThat(artifacts.getSignedBlocks()).hasSize(0);
assertThat(artifacts.getSignedAttestations()).hasSize(1);
final SignedAttestation attestation = artifacts.getSignedAttestations().get(0);
assertThat(attestation.getSourceEpoch().toLong()).isEqualTo(request.getAttestation().source.epoch.longValue());
assertThat(attestation.getTargetEpoch().toLong()).isEqualTo(request.getAttestation().target.epoch.longValue());
assertThat(attestation.getSigningRoot()).isNotNull();
}
use of tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody in project web3signer by ConsenSys.
the class SlashingProtectionAcceptanceTest method cannotSignASecondAttestationForSameSlotWithDifferentSigningRoot.
@Test
void cannotSignASecondAttestationForSameSlotWithDifferentSigningRoot(@TempDir Path testDirectory) throws JsonProcessingException {
setupSigner(testDirectory, true);
final Eth2SigningRequestBody initialRequest = createAttestationRequest(5, 6, UInt64.ZERO);
final Response initialResponse = signer.eth2Sign(keyPair.getPublicKey().toString(), initialRequest);
assertThat(initialResponse.getStatusCode()).isEqualTo(200);
assertThat(signer.getMetricsMatching(attestationSlashingMetrics)).containsOnly(attestationSlashingMetrics.get(0) + " 1.0", attestationSlashingMetrics.get(1) + " 0.0");
final Eth2SigningRequestBody secondRequest = createAttestationRequest(5, 6, UInt64.ONE);
final Response secondResponse = signer.eth2Sign(keyPair.getPublicKey().toString(), secondRequest);
assertThat(secondResponse.getStatusCode()).isEqualTo(SLASHING_PROTECTION_ENFORCED);
assertThat(signer.getMetricsMatching(attestationSlashingMetrics)).containsOnly(attestationSlashingMetrics.get(0) + " 1.0", attestationSlashingMetrics.get(1) + " 1.0");
}
use of tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody in project web3signer by ConsenSys.
the class SlashingProtectionAcceptanceTest method cannotSignSurroundedAttestationWhenSlashingEnabled.
@Test
void cannotSignSurroundedAttestationWhenSlashingEnabled(@TempDir Path testDirectory) throws JsonProcessingException {
setupSigner(testDirectory, true);
final Eth2SigningRequestBody initialRequest = createAttestationRequest(3, 6, UInt64.ONE);
final Response initialResponse = signer.eth2Sign(keyPair.getPublicKey().toString(), initialRequest);
assertThat(initialResponse.getStatusCode()).isEqualTo(200);
// attempt a surrounded Request
final Eth2SigningRequestBody surroundedRequest = createAttestationRequest(4, 5, UInt64.ONE);
final Response surroundedResponse = signer.eth2Sign(keyPair.getPublicKey().toString(), surroundedRequest);
assertThat(surroundedResponse.getStatusCode()).isEqualTo(SLASHING_PROTECTION_ENFORCED);
}
Aggregations