Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eth-reference-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies {
referenceTestImplementation project(':infrastructure:async')
referenceTestImplementation project(':infrastructure:io')
referenceTestImplementation testFixtures(project(':infrastructure:async'))
referenceTestImplementation testFixtures(project(':infrastructure:kzg'))
referenceTestImplementation testFixtures(project(':infrastructure:metrics'))
referenceTestImplementation project(':infrastructure:time')
referenceTestImplementation project(':data:dataexchange')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.google.common.collect.Maps;
import java.util.Map;
import tech.pegasys.teku.kzg.KZG;
import tech.pegasys.teku.kzg.NoOpKZG;
import tech.pegasys.teku.networks.Eth2NetworkConfiguration;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecMilestone;
Expand All @@ -29,7 +30,7 @@ public static KZG getKzgWithLoadedTrustedSetup(final Spec spec, final String net
|| spec.isMilestoneSupported(SpecMilestone.ELECTRA)) {
return getKzgWithLoadedTrustedSetup(network);
}
return KZG.NOOP;
return NoOpKZG.INSTANCE;
}

public static KZG getKzgWithLoadedTrustedSetup(final String network) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public ExecutionLayerChannelStub(
// trusted setup loading will be handled by the BeaconChainController
kzg = KZG.getInstance(false);
} else {
kzg = KZG.NOOP;
kzg = KZG.DISABLED;
}
this.blobsUtil = new BlobsUtil(spec, kzg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
import tech.pegasys.teku.infrastructure.async.SyncAsyncRunner;
import tech.pegasys.teku.infrastructure.ssz.SszList;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.kzg.KZG;
import tech.pegasys.teku.kzg.KZGCommitment;
import tech.pegasys.teku.kzg.KZGProof;
import tech.pegasys.teku.kzg.NoOpKZG;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.Blob;
Expand Down Expand Up @@ -111,7 +111,7 @@ private ChainBuilder(
final Optional<UInt64> maybeEarliestBlobSidecarSlot) {
this.spec = spec;
this.validatorKeys = validatorKeys;
this.blobsUtil = new BlobsUtil(spec, KZG.NOOP);
this.blobsUtil = new BlobsUtil(spec, NoOpKZG.INSTANCE);
this.attestationGenerator = new AttestationGenerator(spec, validatorKeys);
this.attesterSlashingGenerator = new AttesterSlashingGenerator(spec, validatorKeys);
this.proposerSlashingGenerator = new ProposerSlashingGenerator(spec, validatorKeys);
Expand Down
2 changes: 1 addition & 1 deletion gradle/versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencyManagement {
dependency 'io.libp2p:jvm-libp2p:1.2.2-RELEASE'
dependency 'tech.pegasys:jblst:0.3.12'
dependency 'io.consensys.protocols:jc-kzg-4844:2.1.1'
dependency 'io.github.crate-crypto:java-eth-kzg:0.5.2'
dependency 'io.github.crate-crypto:java-eth-kzg:0.5.4'

dependency 'org.hdrhistogram:HdrHistogram:2.2.2'

Expand Down
1 change: 1 addition & 0 deletions infrastructure/kzg/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ dependencies {
implementation 'commons-io:commons-io'

testFixturesImplementation 'com.google.guava:guava'
testFixturesImplementation 'io.consensys.tuweni:tuweni-bytes'
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ public KZGProof computeBlobKzgProof(final Bytes blob, final KZGCommitment kzgCom
}
}

@Override
public List<KZGCell> computeCells(final Bytes blob) throws KZGException {
try {
final byte[] cells = CKZG4844JNI.computeCells(blob.toArrayUnsafe());
return KZGCell.splitBytes(Bytes.wrap(cells));
} catch (final Exception ex) {
throw new KZGException("Failed to compute KZG cells for blob " + blob.toShortHexString(), ex);
}
}

@Override
public List<KZGCellAndProof> computeCellsAndProofs(final Bytes blob) {
final CellsAndProofs cellsAndProofs =
Expand Down
25 changes: 16 additions & 9 deletions infrastructure/kzg/src/main/java/tech/pegasys/teku/kzg/KZG.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.math.BigInteger;
import java.util.List;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes48;

/**
* This interface specifies all the KZG functions needed for the Deneb specification and is the
Expand All @@ -35,7 +34,7 @@ static KZG getInstance(final boolean rustKzgEnabled) {
return rustKzgEnabled ? RustWithCKZG.getInstance() : CKZG4844.getInstance();
}

KZG NOOP =
KZG DISABLED =
new KZG() {

@Override
Expand All @@ -48,7 +47,7 @@ public void freeTrustedSetup() throws KZGException {}
public boolean verifyBlobKzgProof(
final Bytes blob, final KZGCommitment kzgCommitment, final KZGProof kzgProof)
throws KZGException {
return true;
throw new UnsupportedOperationException("KZG is disabled");
}

@Override
Expand All @@ -57,36 +56,41 @@ public boolean verifyBlobKzgProofBatch(
final List<KZGCommitment> kzgCommitments,
final List<KZGProof> kzgProofs)
throws KZGException {
return true;
throw new UnsupportedOperationException("KZG is disabled");
}

@Override
public KZGCommitment blobToKzgCommitment(final Bytes blob) throws KZGException {
return KZGCommitment.fromBytesCompressed(Bytes48.ZERO);
throw new UnsupportedOperationException("KZG is disabled");
}

@Override
public KZGProof computeBlobKzgProof(final Bytes blob, final KZGCommitment kzgCommitment)
throws KZGException {
return KZGProof.fromBytesCompressed(Bytes48.ZERO);
throw new UnsupportedOperationException("KZG is disabled");
}

@Override
public List<KZGCell> computeCells(Bytes blob) {
throw new UnsupportedOperationException("KZG is disabled");
}

@Override
public List<KZGCellAndProof> computeCellsAndProofs(Bytes blob) {
throw new RuntimeException("Not implemented");
throw new UnsupportedOperationException("KZG is disabled");
}

@Override
public boolean verifyCellProofBatch(
List<KZGCommitment> commitments,
List<KZGCellWithColumnId> cellWithIDs,
List<KZGProof> proofs) {
return false;
throw new UnsupportedOperationException("KZG is disabled");
}

@Override
public List<KZGCellAndProof> recoverCellsAndProofs(List<KZGCellWithColumnId> cells) {
throw new RuntimeException("Not implemented");
throw new UnsupportedOperationException("KZG is disabled");
}
};

Expand All @@ -107,6 +111,9 @@ boolean verifyBlobKzgProofBatch(

// Fulu PeerDAS methods

List<KZGCell> computeCells(Bytes blob);

@Deprecated(since = "Use computeCells instead, computeCellsAndProof is not for production")
List<KZGCellAndProof> computeCellsAndProofs(Bytes blob);

boolean verifyCellProofBatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package tech.pegasys.teku.kzg;

import com.google.common.collect.Streams;
import ethereum.cryptography.Cells;
import ethereum.cryptography.CellsAndProofs;
import ethereum.cryptography.LibEthKZG;
import java.util.Arrays;
Expand Down Expand Up @@ -102,6 +103,12 @@ public KZGProof computeBlobKzgProof(final Bytes blob, final KZGCommitment kzgCom
throw new RuntimeException("LibPeerDASKZG library doesn't support computeBlobKzgProof");
}

@Override
public List<KZGCell> computeCells(final Bytes blob) {
final Cells cells = library.computeCells(blob.toArrayUnsafe());
return KZGCell.splitBytes(Bytes.wrap(cells.toBytes()));
}

@Override
public List<KZGCellAndProof> computeCellsAndProofs(final Bytes blob) {
final CellsAndProofs cellsAndProofs = library.computeCellsAndKZGProofs(blob.toArrayUnsafe());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class RustWithCKZG implements KZG {
private static RustWithCKZG instance;

private final CKZG4844 ckzg4844Delegate;
private final RustKZG rustKzgDelegeate;
private final RustKZG rustKzgDelegate;

static synchronized RustWithCKZG getInstance() {
if (instance == null) {
Expand All @@ -39,13 +39,13 @@ static synchronized RustWithCKZG getInstance() {

private RustWithCKZG() {
this.ckzg4844Delegate = CKZG4844.getInstance();
this.rustKzgDelegeate = RustKZG.getInstance();
this.rustKzgDelegate = RustKZG.getInstance();
}

@Override
public synchronized void loadTrustedSetup(final String trustedSetupFile) throws KZGException {
ckzg4844Delegate.loadTrustedSetup(trustedSetupFile);
rustKzgDelegeate.loadTrustedSetup(trustedSetupFile);
rustKzgDelegate.loadTrustedSetup(trustedSetupFile);
}

@Override
Expand All @@ -58,7 +58,7 @@ public synchronized void freeTrustedSetup() throws KZGException {
}
KZGException rustKzgDelegateException = null;
try {
rustKzgDelegeate.freeTrustedSetup();
rustKzgDelegate.freeTrustedSetup();
} catch (final KZGException ex) {
rustKzgDelegateException = ex;
}
Expand Down Expand Up @@ -102,21 +102,26 @@ public KZGProof computeBlobKzgProof(final Bytes blob, final KZGCommitment kzgCom
return ckzg4844Delegate.computeBlobKzgProof(blob, kzgCommitment);
}

@Override
public List<KZGCell> computeCells(final Bytes blob) {
return rustKzgDelegate.computeCells(blob);
}

@Override
public List<KZGCellAndProof> computeCellsAndProofs(final Bytes blob) {
return rustKzgDelegeate.computeCellsAndProofs(blob);
return rustKzgDelegate.computeCellsAndProofs(blob);
}

@Override
public boolean verifyCellProofBatch(
final List<KZGCommitment> commitments,
final List<KZGCellWithColumnId> cellWithIds,
final List<KZGProof> proofs) {
return rustKzgDelegeate.verifyCellProofBatch(commitments, cellWithIds, proofs);
return rustKzgDelegate.verifyCellProofBatch(commitments, cellWithIds, proofs);
}

@Override
public List<KZGCellAndProof> recoverCellsAndProofs(final List<KZGCellWithColumnId> cells) {
return rustKzgDelegeate.recoverCellsAndProofs(cells);
return rustKzgDelegate.recoverCellsAndProofs(cells);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@ public void testComputeRecoverCellsAndProofs() {
assertThat(recoveredCells).isEqualTo(cellAndProofs);
}

@Test
public void testComputeCellsAndProofsEqualsComputeCells() {
Bytes blob = getSampleBlob();
List<KZGCellAndProof> cellAndProofs = kzg.computeCellsAndProofs(blob);
Comment thread Dismissed
List<KZGCell> cells = kzg.computeCells(blob);
assertThat(cells).isEqualTo(cellAndProofs.stream().map(KZGCellAndProof::cell).toList());
}

private List<Bytes> getSampleBlobs(final int count) {
return IntStream.range(0, count).mapToObj(__ -> getSampleBlob()).collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright Consensys Software Inc., 2025
*
* 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.teku.kzg;

import java.util.List;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes48;

public class NoOpKZG implements KZG {

public static final NoOpKZG INSTANCE = new NoOpKZG();

@Override
public void loadTrustedSetup(final String trustedSetupFile) throws KZGException {
// DO NOTHING
}

@Override
public void freeTrustedSetup() throws KZGException {
// DO NOTHING
}

@Override
public boolean verifyCellProofBatch(
final List<KZGCommitment> commitments,
final List<KZGCellWithColumnId> cellWithIDs,
final List<KZGProof> proofs) {
return true;
}

@Override
public List<KZGCellAndProof> recoverCellsAndProofs(final List<KZGCellWithColumnId> cells) {
return List.of();
}

@Override
@Deprecated(since = "Use computeCells instead, computeCellsAndProof is not for production")
public List<KZGCellAndProof> computeCellsAndProofs(final Bytes blob) {
return List.of();
}

@Override
public List<KZGCell> computeCells(final Bytes blob) {
return List.of();
}

@Override
public KZGProof computeBlobKzgProof(final Bytes blob, final KZGCommitment kzgCommitment)
throws KZGException {
return KZGProof.fromBytesCompressed(Bytes48.ZERO);
}

@Override
public KZGCommitment blobToKzgCommitment(final Bytes blob) throws KZGException {
return KZGCommitment.fromBytesCompressed(Bytes48.ZERO);
}

@Override
public boolean verifyBlobKzgProofBatch(
final List<Bytes> blobs,
final List<KZGCommitment> kzgCommitments,
final List<KZGProof> kzgProofs)
throws KZGException {
return true;
}

@Override
public boolean verifyBlobKzgProof(
final Bytes blob, final KZGCommitment kzgCommitment, final KZGProof kzgProof)
throws KZGException {
return true;
}
}
1 change: 1 addition & 0 deletions networking/eth2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies {
testFixturesImplementation testFixtures(project(':infrastructure:async'))
testFixturesImplementation project(':infrastructure:bytes')
testFixturesImplementation testFixtures(project(':infrastructure:events'))
testFixturesImplementation testFixtures(project(':infrastructure:kzg'))
testFixturesImplementation testFixtures(project(':infrastructure:metrics'))
testFixturesImplementation testFixtures(project(':infrastructure:time'))
testFixturesImplementation testFixtures(project(':storage'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import tech.pegasys.teku.infrastructure.subscribers.Subscribers;
import tech.pegasys.teku.infrastructure.time.StubTimeProvider;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.kzg.KZG;
import tech.pegasys.teku.kzg.NoOpKZG;
import tech.pegasys.teku.network.p2p.jvmlibp2p.PrivateKeyGenerator;
import tech.pegasys.teku.networking.eth2.gossip.config.GossipConfigurator;
import tech.pegasys.teku.networking.eth2.gossip.encoding.GossipEncoding;
Expand Down Expand Up @@ -230,7 +230,7 @@ protected Eth2P2PNetwork buildNetwork(final P2PConfig config) {
P2PConfig.DEFAULT_PEER_BLOB_SIDECARS_RATE_LIMIT,
P2PConfig.DEFAULT_PEER_REQUEST_LIMIT,
spec,
KZG.NOOP,
NoOpKZG.INSTANCE,
(__) -> Optional.empty());

List<RpcMethod<?, ?, ?>> rpcMethods =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ protected void initKzg() {
"Trusted setup should be configured when Deneb is enabled"));
kzg.loadTrustedSetup(trustedSetupFile);
} else {
kzg = KZG.NOOP;
kzg = KZG.DISABLED;
}
}

Expand Down