Search in sources :

Example 16 with Eth2SigningRequestBody

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);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) ForkInfo(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.ForkInfo) BeaconBlock(tech.pegasys.teku.api.schema.BeaconBlock) BeaconBlockBody(tech.pegasys.teku.api.schema.BeaconBlockBody) Eth2SigningRequestBody(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody) Eth1Data(tech.pegasys.teku.api.schema.Eth1Data)

Example 17 with Eth2SigningRequestBody

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);
}
Also used : AggregationSlot(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.AggregationSlot) Bytes(org.apache.tuweni.bytes.Bytes) ForkInfo(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.ForkInfo) Eth2SigningRequestBody(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody)

Example 18 with Eth2SigningRequestBody

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();
}
Also used : Response(io.restassured.response.Response) Path(java.nio.file.Path) Signer(tech.pegasys.web3signer.dsl.signer.Signer) SignerConfigurationBuilder(tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder) InterchangeV5Format(dsl.InterchangeV5Format) SignedArtifacts(dsl.SignedArtifacts) Eth2SigningRequestBody(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody) InterchangeJsonProvider(tech.pegasys.web3signer.slashingprotection.interchange.InterchangeJsonProvider) SignedAttestation(tech.pegasys.web3signer.slashingprotection.interchange.model.SignedAttestation) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 19 with Eth2SigningRequestBody

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");
}
Also used : Response(io.restassured.response.Response) Eth2SigningRequestBody(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody) Test(org.junit.jupiter.api.Test)

Example 20 with Eth2SigningRequestBody

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);
}
Also used : Response(io.restassured.response.Response) Eth2SigningRequestBody(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody) Test(org.junit.jupiter.api.Test)

Aggregations

Eth2SigningRequestBody (tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody)31 Bytes (org.apache.tuweni.bytes.Bytes)17 Response (io.restassured.response.Response)16 Test (org.junit.jupiter.api.Test)15 ForkInfo (tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.ForkInfo)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 BLSSignature (tech.pegasys.teku.bls.BLSSignature)5 Eth2BlockSigningRequestUtil (tech.pegasys.web3signer.dsl.utils.Eth2BlockSigningRequestUtil)5 Path (java.nio.file.Path)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 JsonObject (io.vertx.core.json.JsonObject)3 ExecutionException (java.util.concurrent.ExecutionException)3 AttestationData (tech.pegasys.teku.api.schema.AttestationData)2 Checkpoint (tech.pegasys.teku.api.schema.Checkpoint)2 DepositMessage (tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.DepositMessage)2 Signer (tech.pegasys.web3signer.dsl.signer.Signer)2 SignerConfigurationBuilder (tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InterchangeV5Format (dsl.InterchangeV5Format)1 SignedArtifacts (dsl.SignedArtifacts)1