-
Notifications
You must be signed in to change notification settings - Fork 367
KZG updates from das branch #9335
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,6 +71,8 @@ public class Eth2NetworkConfiguration { | |
|
|
||
| public static final int DEFAULT_ASYNC_P2P_MAX_QUEUE = DEFAULT_MAX_QUEUE_SIZE; | ||
|
|
||
| public static final boolean DEFAULT_RUST_KZG_ENABLED = false; | ||
|
|
||
| // at least 5, but happily up to 12 | ||
| public static final int DEFAULT_VALIDATOR_EXECUTOR_THREADS = | ||
| Math.max(5, Math.min(Runtime.getRuntime().availableProcessors(), 12)); | ||
|
|
@@ -114,6 +116,7 @@ public class Eth2NetworkConfiguration { | |
| private final boolean forkChoiceLateBlockReorgEnabled; | ||
| private final boolean forkChoiceUpdatedAlwaysSendPayloadAttributes; | ||
| private final int pendingAttestationsMaxQueue; | ||
| private final boolean rustKzgEnabled; | ||
|
|
||
| private Eth2NetworkConfiguration( | ||
| final Spec spec, | ||
|
|
@@ -141,7 +144,8 @@ private Eth2NetworkConfiguration( | |
| final int asyncBeaconChainMaxQueue, | ||
| final boolean forkChoiceLateBlockReorgEnabled, | ||
| final boolean forkChoiceUpdatedAlwaysSendPayloadAttributes, | ||
| final int pendingAttestationsMaxQueue) { | ||
| final int pendingAttestationsMaxQueue, | ||
| final boolean rustKzgEnabled) { | ||
| this.spec = spec; | ||
| this.constants = constants; | ||
| this.stateBoostrapConfig = stateBoostrapConfig; | ||
|
|
@@ -172,6 +176,7 @@ private Eth2NetworkConfiguration( | |
| this.forkChoiceUpdatedAlwaysSendPayloadAttributes = | ||
| forkChoiceUpdatedAlwaysSendPayloadAttributes; | ||
| this.pendingAttestationsMaxQueue = pendingAttestationsMaxQueue; | ||
| this.rustKzgEnabled = rustKzgEnabled; | ||
|
|
||
| LOG.debug( | ||
| "P2P async queue - {} threads, max queue size {} ", asyncP2pMaxThreads, asyncP2pMaxQueue); | ||
|
|
@@ -293,6 +298,10 @@ public boolean isForkChoiceUpdatedAlwaysSendPayloadAttributes() { | |
| return forkChoiceUpdatedAlwaysSendPayloadAttributes; | ||
| } | ||
|
|
||
| public boolean isRustKzgEnabled() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needs revisiting of |
||
| return rustKzgEnabled; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return constants; | ||
|
|
@@ -316,6 +325,7 @@ public boolean equals(final Object o) { | |
| && forkChoiceLateBlockReorgEnabled == that.forkChoiceLateBlockReorgEnabled | ||
| && forkChoiceUpdatedAlwaysSendPayloadAttributes | ||
| == that.forkChoiceUpdatedAlwaysSendPayloadAttributes | ||
| && rustKzgEnabled == that.rustKzgEnabled | ||
| && Objects.equals(spec, that.spec) | ||
| && Objects.equals(constants, that.constants) | ||
| && Objects.equals(stateBoostrapConfig, that.stateBoostrapConfig) | ||
|
|
@@ -362,7 +372,8 @@ public int hashCode() { | |
| asyncBeaconChainMaxQueue, | ||
| asyncP2pMaxQueue, | ||
| forkChoiceLateBlockReorgEnabled, | ||
| forkChoiceUpdatedAlwaysSendPayloadAttributes); | ||
| forkChoiceUpdatedAlwaysSendPayloadAttributes, | ||
| rustKzgEnabled); | ||
| } | ||
|
|
||
| public static class Builder { | ||
|
|
@@ -400,6 +411,7 @@ public static class Builder { | |
| private boolean forkChoiceUpdatedAlwaysSendPayloadAttributes = | ||
| DEFAULT_FORK_CHOICE_UPDATED_ALWAYS_SEND_PAYLOAD_ATTRIBUTES; | ||
| private OptionalInt pendingAttestationsMaxQueue = OptionalInt.empty(); | ||
| private boolean rustKzgEnabled = DEFAULT_RUST_KZG_ENABLED; | ||
|
|
||
| public void spec(final Spec spec) { | ||
| this.spec = spec; | ||
|
|
@@ -498,7 +510,8 @@ public Eth2NetworkConfiguration build() { | |
| asyncBeaconChainMaxQueue.orElse(DEFAULT_ASYNC_BEACON_CHAIN_MAX_QUEUE), | ||
| forkChoiceLateBlockReorgEnabled, | ||
| forkChoiceUpdatedAlwaysSendPayloadAttributes, | ||
| pendingAttestationsMaxQueue.orElse(DEFAULT_MAX_QUEUE_PENDING_ATTESTATIONS)); | ||
| pendingAttestationsMaxQueue.orElse(DEFAULT_MAX_QUEUE_PENDING_ATTESTATIONS), | ||
| rustKzgEnabled); | ||
| } | ||
|
|
||
| private void validateCommandLineParameters() { | ||
|
|
@@ -737,6 +750,11 @@ public Builder epochsStoreBlobs(final String epochsStoreBlobs) { | |
| return this; | ||
| } | ||
|
|
||
| public Builder rustKzgEnabled(final boolean rustKzgEnabled) { | ||
| this.rustKzgEnabled = rustKzgEnabled; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder applyNetworkDefaults(final String networkName) { | ||
| Eth2Network.fromStringLenient(networkName) | ||
| .ifPresentOrElse( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
|
|
||
| package tech.pegasys.teku.kzg; | ||
|
|
||
| import java.math.BigInteger; | ||
| import java.util.List; | ||
| import org.apache.tuweni.bytes.Bytes; | ||
| import org.apache.tuweni.bytes.Bytes48; | ||
|
|
@@ -22,12 +23,16 @@ | |
| * entry-point for all KZG operations in Teku. | ||
| */ | ||
| public interface KZG { | ||
|
|
||
| BigInteger BLS_MODULUS = | ||
| new BigInteger( | ||
| "52435875175126190479447740508185965837690552500527637822603658699938581184513"); | ||
| int BYTES_PER_G1 = 48; | ||
| int BYTES_PER_G2 = 96; | ||
| int CELLS_PER_EXT_BLOB = 128; | ||
| int FIELD_ELEMENTS_PER_BLOB = 4096; | ||
|
|
||
| static KZG getInstance() { | ||
| return CKZG4844.getInstance(); | ||
| static KZG getInstance(final boolean rustKzgEnabled) { | ||
| return rustKzgEnabled ? RustWithCKZG.getInstance() : CKZG4844.getInstance(); | ||
| } | ||
|
|
||
| KZG NOOP = | ||
|
|
@@ -65,6 +70,24 @@ public KZGProof computeBlobKzgProof(final Bytes blob, final KZGCommitment kzgCom | |
| throws KZGException { | ||
| return KZGProof.fromBytesCompressed(Bytes48.ZERO); | ||
| } | ||
|
|
||
| @Override | ||
| public List<KZGCellAndProof> computeCellsAndProofs(Bytes blob) { | ||
| throw new RuntimeException("Not implemented"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean verifyCellProofBatch( | ||
| List<KZGCommitment> commitments, | ||
| List<KZGCellWithColumnId> cellWithIDs, | ||
| List<KZGProof> proofs) { | ||
| return false; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd make old (deneb) boolean methods return false in default too. If accidentally NOOP leaks in production we'd better fail all checks
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes it harder for unit tests. Most of the time we want NOOP to do nothing and stick to the "standard" flow. |
||
| } | ||
|
|
||
| @Override | ||
| public List<KZGCellAndProof> recoverCellsAndProofs(List<KZGCellWithColumnId> cells) { | ||
| throw new RuntimeException("Not implemented"); | ||
| } | ||
| }; | ||
|
|
||
| void loadTrustedSetup(String trustedSetupFile) throws KZGException; | ||
|
|
@@ -81,4 +104,15 @@ boolean verifyBlobKzgProofBatch( | |
| KZGCommitment blobToKzgCommitment(Bytes blob) throws KZGException; | ||
|
|
||
| KZGProof computeBlobKzgProof(Bytes blob, KZGCommitment kzgCommitment) throws KZGException; | ||
|
|
||
| // Fulu PeerDAS methods | ||
|
|
||
| List<KZGCellAndProof> computeCellsAndProofs(Bytes blob); | ||
|
|
||
| boolean verifyCellProofBatch( | ||
| List<KZGCommitment> commitments, | ||
| List<KZGCellWithColumnId> cellWithIDs, | ||
| List<KZGProof> proofs); | ||
|
|
||
| List<KZGCellAndProof> recoverCellsAndProofs(List<KZGCellWithColumnId> cells); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * Copyright Consensys Software Inc., 2024 | ||
| * | ||
| * 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 static ethereum.ckzg4844.CKZG4844JNI.BYTES_PER_CELL; | ||
|
|
||
| import java.util.List; | ||
| import org.apache.tuweni.bytes.Bytes; | ||
|
|
||
| public record KZGCell(Bytes bytes) { | ||
|
|
||
| static final KZGCell ZERO = new KZGCell(Bytes.wrap(new byte[BYTES_PER_CELL])); | ||
|
|
||
| static List<KZGCell> splitBytes(final Bytes bytes) { | ||
| return CKZG4844Utils.bytesChunked(bytes, BYTES_PER_CELL).stream().map(KZGCell::new).toList(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /* | ||
| * Copyright Consensys Software Inc., 2024 | ||
| * | ||
| * 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; | ||
|
|
||
| public record KZGCellAndProof(KZGCell cell, KZGProof proof) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have a task to make master pass reference tests fo FULU? I think we have several test executors already made, just needs revisiting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll work on it.