From 92cef5dceb2c474f9625a7627be5e6b051c1d72c Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Wed, 27 Nov 2024 09:23:18 +1000 Subject: [PATCH 1/3] Update Teku and Besu version -- Teku 24.10.3 -- Besu 24.10.0 --- CHANGELOG.md | 1 + gradle.properties | 2 +- gradle/license-report-config/allowed-licenses.json | 4 ++++ gradle/versions.gradle | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fab48afe..d8955efa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Java 21 for build and runtime. [#995](https://github.com/Consensys/web3signer/pull/995) - Electra fork support. [#1020](https://github.com/Consensys/web3signer/pull/1020) and [#1023](https://github.com/Consensys/web3signer/pull/1023) - Commit boost API - Get Public Keys. [#1031](https://github.com/Consensys/web3signer/pull/1031) +- Teku and Besu libraries updated to 24.10.3 and 24.10.0 respectively. ### Bugs fixed - Override protobuf-java to 3.25.5 which is a transitive dependency from google-cloud-secretmanager. It fixes CVE-2024-7254. diff --git a/gradle.properties b/gradle.properties index f386909e8..f83fdf6a2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -besuVersion=24.7.0 +besuVersion=24.10.0 besuDistroUrl=https://github.com/hyperledger/besu/releases/download/${besuVersion}/besu-${besuVersion}.tar.gz hashicorpVaultVersion=1.9.2 diff --git a/gradle/license-report-config/allowed-licenses.json b/gradle/license-report-config/allowed-licenses.json index a9c8f292c..7fb6ca03c 100644 --- a/gradle/license-report-config/allowed-licenses.json +++ b/gradle/license-report-config/allowed-licenses.json @@ -107,6 +107,10 @@ "moduleName": "jakarta.validation:jakarta.validation-api", "moduleLicense": "Apache License, Version 2.0" }, + { + "moduleName": "jakarta.inject:jakarta.inject-api", + "moduleLicense": "Apache License, Version 2.0" + }, { "moduleName": "javax.xml.bind:jaxb-api", "moduleLicense": "COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.1" diff --git a/gradle/versions.gradle b/gradle/versions.gradle index 309dabe8b..4314b306f 100644 --- a/gradle/versions.gradle +++ b/gradle/versions.gradle @@ -92,7 +92,7 @@ dependencyManagement { dependency 'org.xipki.iaik:sunpkcs11-wrapper:1.4.10' - dependencySet(group: 'tech.pegasys.teku.internal', version: '24.8.0') { + dependencySet(group: 'tech.pegasys.teku.internal', version: '24.10.3') { entry ('bls') { exclude group: 'org.bouncycastle', name: 'bcprov-jdk15on' } From e8760b3a07cf442b828c7f596719cc21561f261c Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Wed, 27 Nov 2024 09:53:14 +1000 Subject: [PATCH 2/3] Use Teku DataStructureUtil in Acceptance Test --- .../dsl/utils/DataStructureUtilAdapter.java | 197 ------------------ .../utils/Eth2BlockSigningRequestUtil.java | 58 ++---- 2 files changed, 19 insertions(+), 236 deletions(-) delete mode 100644 acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/utils/DataStructureUtilAdapter.java diff --git a/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/utils/DataStructureUtilAdapter.java b/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/utils/DataStructureUtilAdapter.java deleted file mode 100644 index 93d90d1bf..000000000 --- a/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/utils/DataStructureUtilAdapter.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright 2023 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.web3signer.dsl.utils; - -import static java.util.stream.Collectors.toList; - -import tech.pegasys.teku.infrastructure.async.SafeFuture; -import tech.pegasys.teku.infrastructure.ssz.SszList; -import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema; -import tech.pegasys.teku.infrastructure.unsigned.UInt64; -import tech.pegasys.teku.spec.Spec; -import tech.pegasys.teku.spec.SpecVersion; -import tech.pegasys.teku.spec.config.SpecConfigBellatrix; -import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock; -import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody; -import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodySchema; -import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload; -import tech.pegasys.teku.spec.datastructures.execution.versions.capella.Withdrawal; -import tech.pegasys.teku.spec.datastructures.operations.BlsToExecutionChange; -import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange; -import tech.pegasys.teku.spec.schemas.SchemaDefinitionsBellatrix; -import tech.pegasys.teku.spec.schemas.SchemaDefinitionsCapella; -import tech.pegasys.teku.spec.util.DataStructureUtil; - -import java.util.List; -import java.util.Random; -import java.util.stream.IntStream; - -import org.apache.tuweni.bytes.Bytes32; - -/** - * This class provide different implementation of randomBeaconBlock than Teku's DataStructureUtil. - * Instead of using genesis schema definition, our implementation uses spec at slot number to derive - * the schema definition. - */ -public class DataStructureUtilAdapter { - private static final int MAX_EP_RANDOM_WITHDRAWALS = 4; - private final DataStructureUtil util; - private int seed = 92892824; - private final Spec spec; - - public DataStructureUtilAdapter(final Spec spec) { - this.spec = spec; - util = new DataStructureUtil(spec); - } - - public BeaconBlock randomBeaconBlock(final UInt64 slotNum) { - final UInt64 proposerIndex = util.randomUInt64(); - final Bytes32 previousRoot = util.randomBytes32(); - final Bytes32 stateRoot = util.randomBytes32(); - final BeaconBlockBody body = randomBeaconBlockBody(slotNum); - return new BeaconBlock( - spec.atSlot(slotNum).getSchemaDefinitions().getBeaconBlockSchema(), - slotNum, - proposerIndex, - previousRoot, - stateRoot, - body); - } - - private BeaconBlockBody randomBeaconBlockBody(final UInt64 slotNum) { - final BeaconBlockBodySchema schema = - spec.atSlot(slotNum).getSchemaDefinitions().getBeaconBlockBodySchema(); - return schema - .createBlockBody( - builder -> { - builder - .randaoReveal(util.randomSignature()) - .eth1Data(util.randomEth1Data()) - .graffiti(Bytes32.ZERO) - .proposerSlashings( - util.randomSszList( - schema.getProposerSlashingsSchema(), util::randomProposerSlashing, 1)) - .attesterSlashings( - util.randomSszList( - schema.getAttesterSlashingsSchema(), util::randomAttesterSlashing, 1)) - .attestations( - util.randomSszList( - schema.getAttestationsSchema(), util::randomAttestation, 3)) - .deposits( - util.randomSszList( - schema.getDepositsSchema(), util::randomDepositWithoutIndex, 1)) - .voluntaryExits( - util.randomSszList( - schema.getVoluntaryExitsSchema(), util::randomSignedVoluntaryExit, 1)); - if (builder.supportsSyncAggregate()) { - builder.syncAggregate(util.randomSyncAggregateIfRequiredBySchema(schema)); - } - if (builder.supportsExecutionPayload()) { - builder.executionPayload(randomExecutionPayload(spec.atSlot(slotNum))); - } - if (builder.supportsBlsToExecutionChanges()) { - builder.blsToExecutionChanges( - randomSignedBlsToExecutionChangesList(spec.atSlot(slotNum))); - } - if (builder.supportsKzgCommitments()) { - builder.blobKzgCommitments(util.randomBlobKzgCommitments()); - } - return SafeFuture.completedFuture(builder).toVoid(); - }) - .join(); - } - - private ExecutionPayload randomExecutionPayload(final SpecVersion specVersion) { - final SpecConfigBellatrix specConfigBellatrix = - SpecConfigBellatrix.required(specVersion.getConfig()); - return SchemaDefinitionsBellatrix.required(specVersion.getSchemaDefinitions()) - .getExecutionPayloadSchema() - .createExecutionPayload( - builder -> - builder - .parentHash(util.randomBytes32()) - .feeRecipient(util.randomBytes20()) - .stateRoot(util.randomBytes32()) - .receiptsRoot(util.randomBytes32()) - .logsBloom(util.randomBytes(specConfigBellatrix.getBytesPerLogsBloom())) - .prevRandao(util.randomBytes32()) - .blockNumber(util.randomUInt64()) - .gasLimit(util.randomUInt64()) - .gasUsed(util.randomUInt64()) - .timestamp(util.randomUInt64()) - .extraData(util.randomBytes(specConfigBellatrix.getMaxExtraDataBytes())) - .baseFeePerGas(util.randomUInt256()) - .blockHash(util.randomBytes32()) - .transactions(util.randomExecutionPayloadTransactions()) - .withdrawals(() -> randomExecutionPayloadWithdrawals(specVersion)) - .excessBlobGas(util::randomUInt64) - .blobGasUsed(util::randomUInt64) - .depositRequests(util::randomExecutionPayloadDepositRequests) - .withdrawalRequests(util::randomWithdrawalRequests) - .consolidationRequests(util::randomConsolidationRequests)); - } - - private List randomExecutionPayloadWithdrawals(final SpecVersion specVersion) { - return IntStream.rangeClosed(0, randomInt(MAX_EP_RANDOM_WITHDRAWALS)) - .mapToObj(__ -> randomWithdrawal(specVersion)) - .collect(toList()); - } - - private Withdrawal randomWithdrawal(final SpecVersion specVersion) { - return SchemaDefinitionsCapella.required(specVersion.getSchemaDefinitions()) - .getWithdrawalSchema() - .create( - util.randomUInt64(), - util.randomValidatorIndex(), - util.randomBytes20(), - util.randomUInt64()); - } - - private SszList randomSignedBlsToExecutionChangesList( - final SpecVersion specVersion) { - final SszListSchema signedBlsToExecutionChangeSchema = - SchemaDefinitionsCapella.required(specVersion.getSchemaDefinitions()) - .getBeaconBlockBodySchema() - .toVersionCapella() - .orElseThrow() - .getBlsToExecutionChangesSchema(); - final int maxBlsToExecutionChanges = - specVersion.getConfig().toVersionCapella().orElseThrow().getMaxBlsToExecutionChanges(); - - return util.randomSszList( - signedBlsToExecutionChangeSchema, - maxBlsToExecutionChanges, - () -> randomSignedBlsToExecutionChange(specVersion)); - } - - private SignedBlsToExecutionChange randomSignedBlsToExecutionChange( - final SpecVersion specVersion) { - return SchemaDefinitionsCapella.required(specVersion.getSchemaDefinitions()) - .getSignedBlsToExecutionChangeSchema() - .create(randomBlsToExecutionChange(specVersion), util.randomSignature()); - } - - private BlsToExecutionChange randomBlsToExecutionChange(final SpecVersion specVersion) { - return SchemaDefinitionsCapella.required(specVersion.getSchemaDefinitions()) - .getBlsToExecutionChangeSchema() - .create(util.randomValidatorIndex(), util.randomPublicKey(), util.randomBytes20()); - } - - private int randomInt(final int bound) { - return new Random(nextSeed()).nextInt(bound); - } - - private int nextSeed() { - return seed++; - } -} diff --git a/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/utils/Eth2BlockSigningRequestUtil.java b/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/utils/Eth2BlockSigningRequestUtil.java index 82356fb3a..051ef0637 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/utils/Eth2BlockSigningRequestUtil.java +++ b/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/utils/Eth2BlockSigningRequestUtil.java @@ -24,6 +24,7 @@ import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock; import tech.pegasys.teku.spec.datastructures.state.ForkInfo; import tech.pegasys.teku.spec.signatures.SigningRootUtil; +import tech.pegasys.teku.spec.util.DataStructureUtil; import tech.pegasys.web3signer.core.service.http.ArtifactType; import tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.BlockRequest; import tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody; @@ -32,7 +33,7 @@ public class Eth2BlockSigningRequestUtil { private final SpecMilestone specMilestone; - private final DataStructureUtilAdapter beaconBlockUtil; + private final DataStructureUtil beaconBlockUtil; private final SigningRootUtil signingRootUtil; private final ForkInfo tekuForkInfo; private final Fork tekuFork; @@ -41,23 +42,13 @@ public class Eth2BlockSigningRequestUtil { private final Bytes signingRoot; public Eth2BlockSigningRequestUtil(final SpecMilestone specMilestone) { - final Spec spec = TestSpecFactory.createMinimal(specMilestone); - this.specMilestone = specMilestone; - beaconBlockUtil = new DataStructureUtilAdapter(spec); - signingRootUtil = new SigningRootUtil(spec); - tekuForkInfo = Eth2RequestUtils.forkInfo().asInternalForkInfo(); - tekuFork = new Fork(tekuForkInfo.getFork()); - forkInfo = - new tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.ForkInfo( - tekuFork, tekuForkInfo.getGenesisValidatorsRoot()); - beaconBlock = beaconBlockUtil.randomBeaconBlock(UInt64.valueOf(0L)); - signingRoot = signingRootUtil.signingRootForSignBlock(beaconBlock, tekuForkInfo); + this(TestSpecFactory.createMinimal(specMilestone), UInt64.ONE, UInt64.ZERO); } public Eth2BlockSigningRequestUtil( final Spec spec, final UInt64 forkEpoch, final UInt64 beaconBlockSlot) { specMilestone = spec.atEpoch(forkEpoch).getMilestone(); - beaconBlockUtil = new DataStructureUtilAdapter(spec); + beaconBlockUtil = new DataStructureUtil(spec); signingRootUtil = new SigningRootUtil(spec); tekuForkInfo = Eth2RequestUtils.forkInfo(forkEpoch.longValue()).asInternalForkInfo(); tekuFork = new Fork(tekuForkInfo.getFork()); @@ -69,19 +60,11 @@ public Eth2BlockSigningRequestUtil( } public Eth2SigningRequestBody createBlockV2Request() { - switch (specMilestone) { - case PHASE0: - case ALTAIR: - return createBlockV2Request(new BlockRequest(specMilestone, getBeaconBlock())); - case BELLATRIX: - case CAPELLA: - case DENEB: - case ELECTRA: - return createBlockV2Request(new BlockRequest(specMilestone, getBeaconBlockHeader())); - default: - throw new IllegalStateException( - "Spec not yet implemented for BLOCKV2 Signing AT: " + specMilestone); - } + return switch (specMilestone) { + case PHASE0, ALTAIR -> createBlockV2Request(new BlockRequest(specMilestone, getBeaconBlock())); + case BELLATRIX, CAPELLA, DENEB, ELECTRA -> + createBlockV2Request(new BlockRequest(specMilestone, getBeaconBlockHeader())); + }; } public Eth2SigningRequestBody createBlockV2Request(final BlockRequest blockRequest) { @@ -117,19 +100,16 @@ private BeaconBlockHeader getBeaconBlockHeader() { } private tech.pegasys.teku.api.schema.BeaconBlock getBeaconBlock() { - switch (specMilestone) { - case PHASE0: - return new BeaconBlockPhase0(beaconBlock); - case ALTAIR: - return new BeaconBlockAltair( - beaconBlock.getSlot(), - beaconBlock.getProposerIndex(), - beaconBlock.getParentRoot(), - beaconBlock.getStateRoot(), - getBeaconBlockBodyAltair(beaconBlock.getBody())); - default: - throw new IllegalStateException("BeaconBlock only supported for PHASE0 and ALTAIR in AT"); - } + return switch (specMilestone) { + case PHASE0 -> new BeaconBlockPhase0(beaconBlock); + case ALTAIR -> new BeaconBlockAltair( + beaconBlock.getSlot(), + beaconBlock.getProposerIndex(), + beaconBlock.getParentRoot(), + beaconBlock.getStateRoot(), + getBeaconBlockBodyAltair(beaconBlock.getBody())); + default -> throw new IllegalStateException("BeaconBlock only supported for PHASE0 and ALTAIR in AT"); + }; } private BeaconBlockBodyAltair getBeaconBlockBodyAltair( From 674684874451572ca54a8aefbe95748104b9fea7 Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Wed, 27 Nov 2024 09:53:34 +1000 Subject: [PATCH 3/3] code cleanup --- .../utils/Eth2BlockSigningRequestUtil.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/utils/Eth2BlockSigningRequestUtil.java b/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/utils/Eth2BlockSigningRequestUtil.java index 051ef0637..5acd6f407 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/utils/Eth2BlockSigningRequestUtil.java +++ b/acceptance-tests/src/test/java/tech/pegasys/web3signer/dsl/utils/Eth2BlockSigningRequestUtil.java @@ -60,11 +60,12 @@ public Eth2BlockSigningRequestUtil( } public Eth2SigningRequestBody createBlockV2Request() { - return switch (specMilestone) { - case PHASE0, ALTAIR -> createBlockV2Request(new BlockRequest(specMilestone, getBeaconBlock())); - case BELLATRIX, CAPELLA, DENEB, ELECTRA -> - createBlockV2Request(new BlockRequest(specMilestone, getBeaconBlockHeader())); - }; + return switch (specMilestone) { + case PHASE0, ALTAIR -> + createBlockV2Request(new BlockRequest(specMilestone, getBeaconBlock())); + case BELLATRIX, CAPELLA, DENEB, ELECTRA -> + createBlockV2Request(new BlockRequest(specMilestone, getBeaconBlockHeader())); + }; } public Eth2SigningRequestBody createBlockV2Request(final BlockRequest blockRequest) { @@ -100,16 +101,18 @@ private BeaconBlockHeader getBeaconBlockHeader() { } private tech.pegasys.teku.api.schema.BeaconBlock getBeaconBlock() { - return switch (specMilestone) { - case PHASE0 -> new BeaconBlockPhase0(beaconBlock); - case ALTAIR -> new BeaconBlockAltair( - beaconBlock.getSlot(), - beaconBlock.getProposerIndex(), - beaconBlock.getParentRoot(), - beaconBlock.getStateRoot(), - getBeaconBlockBodyAltair(beaconBlock.getBody())); - default -> throw new IllegalStateException("BeaconBlock only supported for PHASE0 and ALTAIR in AT"); - }; + return switch (specMilestone) { + case PHASE0 -> new BeaconBlockPhase0(beaconBlock); + case ALTAIR -> + new BeaconBlockAltair( + beaconBlock.getSlot(), + beaconBlock.getProposerIndex(), + beaconBlock.getParentRoot(), + beaconBlock.getStateRoot(), + getBeaconBlockBodyAltair(beaconBlock.getBody())); + default -> + throw new IllegalStateException("BeaconBlock only supported for PHASE0 and ALTAIR in AT"); + }; } private BeaconBlockBodyAltair getBeaconBlockBodyAltair(