-
Notifications
You must be signed in to change notification settings - Fork 300
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
Add kzg reference tests support #7571
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...enceTest/java/tech/pegasys/teku/reference/phase0/kzg/KzgBlobToCommitmentTestExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2022 | ||
* | ||
* 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.reference.phase0.kzg; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.apache.tuweni.bytes.Bytes; | ||
import tech.pegasys.teku.ethtests.finder.TestDefinition; | ||
import tech.pegasys.teku.kzg.KZGCommitment; | ||
import tech.pegasys.teku.kzg.ckzg4844.CKZG4844; | ||
|
||
public class KzgBlobToCommitmentTestExecutor extends KzgTestExecutor { | ||
|
||
@Override | ||
public void runTestImpl(final TestDefinition testDefinition) throws Throwable { | ||
final Data data = loadDataFile(testDefinition, Data.class); | ||
final KZGCommitment expectedKzgCommitment = data.getOutput(); | ||
KZGCommitment actualKzgCommitment; | ||
try { | ||
final Bytes blob = data.getInput().getBlob(); | ||
actualKzgCommitment = CKZG4844.getInstance().blobToKzgCommitment(blob); | ||
} catch (RuntimeException e) { | ||
actualKzgCommitment = null; | ||
} | ||
assertThat(actualKzgCommitment).isEqualTo(expectedKzgCommitment); | ||
} | ||
|
||
private static class Data { | ||
@JsonProperty(value = "input", required = true) | ||
private Input input; | ||
|
||
@JsonProperty(value = "output", required = true) | ||
private String output; | ||
|
||
public Input getInput() { | ||
return input; | ||
} | ||
|
||
public KZGCommitment getOutput() { | ||
return output == null ? null : KZGCommitment.fromHexString(output); | ||
} | ||
|
||
private static class Input { | ||
@JsonProperty(value = "blob", required = true) | ||
private String blob; | ||
|
||
public Bytes getBlob() { | ||
return Bytes.fromHexString(blob); | ||
} | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...enceTest/java/tech/pegasys/teku/reference/phase0/kzg/KzgComputeBlobProofTestExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2022 | ||
* | ||
* 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.reference.phase0.kzg; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.apache.tuweni.bytes.Bytes; | ||
import tech.pegasys.teku.ethtests.finder.TestDefinition; | ||
import tech.pegasys.teku.kzg.KZGCommitment; | ||
import tech.pegasys.teku.kzg.KZGProof; | ||
import tech.pegasys.teku.kzg.ckzg4844.CKZG4844; | ||
|
||
public class KzgComputeBlobProofTestExecutor extends KzgTestExecutor { | ||
|
||
@Override | ||
public void runTestImpl(final TestDefinition testDefinition) throws Throwable { | ||
final Data data = loadDataFile(testDefinition, Data.class); | ||
final KZGProof expectedKzgProof = data.getOutput(); | ||
KZGProof actualKzgProof; | ||
try { | ||
final Bytes blob = data.getInput().getBlob(); | ||
final KZGCommitment commitment = data.getInput().getCommitment(); | ||
actualKzgProof = CKZG4844.getInstance().computeBlobKzgProof(blob, commitment); | ||
} catch (RuntimeException e) { | ||
actualKzgProof = null; | ||
} | ||
assertThat(actualKzgProof).isEqualTo(expectedKzgProof); | ||
} | ||
|
||
private static class Data { | ||
@JsonProperty(value = "input", required = true) | ||
private Input input; | ||
|
||
@JsonProperty(value = "output", required = true) | ||
private String output; | ||
|
||
public Input getInput() { | ||
return input; | ||
} | ||
|
||
public KZGProof getOutput() { | ||
return output == null ? null : KZGProof.fromHexString(output); | ||
} | ||
|
||
private static class Input { | ||
@JsonProperty(value = "blob", required = true) | ||
private String blob; | ||
|
||
@JsonProperty(value = "commitment", required = true) | ||
private String commitment; | ||
|
||
public Bytes getBlob() { | ||
return Bytes.fromHexString(blob); | ||
} | ||
|
||
public KZGCommitment getCommitment() { | ||
return KZGCommitment.fromHexString(commitment); | ||
} | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...-tests/src/referenceTest/java/tech/pegasys/teku/reference/phase0/kzg/KzgTestExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2022 | ||
* | ||
* 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.reference.phase0.kzg; | ||
|
||
import static tech.pegasys.teku.ethtests.finder.KzgTestFinder.KZG_DATA_FILE; | ||
|
||
import java.io.IOException; | ||
import tech.pegasys.teku.ethtests.finder.TestDefinition; | ||
import tech.pegasys.teku.kzg.KZG; | ||
import tech.pegasys.teku.kzg.ckzg4844.CKZG4844; | ||
import tech.pegasys.teku.networks.Eth2NetworkConfiguration; | ||
import tech.pegasys.teku.reference.TestDataUtils; | ||
import tech.pegasys.teku.reference.TestExecutor; | ||
import tech.pegasys.teku.spec.config.SpecConfigDeneb; | ||
|
||
public abstract class KzgTestExecutor implements TestExecutor { | ||
// We don't support config reloading and all tests are currently for mainnet | ||
private static final String CONFIG_NAME = "mainnet"; | ||
|
||
@Override | ||
public final void runTest(TestDefinition testDefinition) throws Throwable { | ||
final Eth2NetworkConfiguration networkConfig = | ||
Eth2NetworkConfiguration.builder(CONFIG_NAME).build(); | ||
final SpecConfigDeneb specConfigDeneb = | ||
SpecConfigDeneb.required(networkConfig.getSpec().getGenesisSpecConfig()); | ||
|
||
KZG kzg = null; | ||
try { | ||
kzg = CKZG4844.createInstance(specConfigDeneb.getFieldElementsPerBlob()); | ||
kzg.loadTrustedSetup(specConfigDeneb.getTrustedSetupPath().orElseThrow()); | ||
runTestImpl(testDefinition); | ||
} finally { | ||
if (kzg != null) { | ||
kzg.freeTrustedSetup(); | ||
} | ||
} | ||
} | ||
|
||
protected <T> T loadDataFile(final TestDefinition testDefinition, final Class<T> type) | ||
throws IOException { | ||
String dataFile = | ||
testDefinition.getTestName().endsWith(".yaml") | ||
? testDefinition.getTestName() | ||
: KZG_DATA_FILE; | ||
return TestDataUtils.loadYaml(testDefinition, dataFile, type); | ||
} | ||
|
||
protected abstract void runTestImpl(TestDefinition testDefinition) throws Throwable; | ||
} |
33 changes: 33 additions & 0 deletions
33
...ference-tests/src/referenceTest/java/tech/pegasys/teku/reference/phase0/kzg/KzgTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2022 | ||
* | ||
* 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.reference.phase0.kzg; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import tech.pegasys.teku.reference.TestExecutor; | ||
|
||
public class KzgTests { | ||
|
||
public static final ImmutableMap<String, TestExecutor> KZG_TEST_TYPES = | ||
ImmutableMap.<String, TestExecutor>builder() | ||
.put("kzg/blob_to_kzg_commitment", new KzgBlobToCommitmentTestExecutor()) | ||
.put("kzg/compute_blob_kzg_proof", new KzgComputeBlobProofTestExecutor()) | ||
// no KZG interface on CL side, EL responsibility | ||
.put("kzg/compute_kzg_proof", TestExecutor.IGNORE_TESTS) | ||
// actually uses verify_blob_kzg_proof_batch KZG interface | ||
.put("kzg/verify_blob_kzg_proof", new KzgVerifyBlobProofTestExecutor()) | ||
.put("kzg/verify_blob_kzg_proof_batch", new KzgVerifyBlobProofBatchTestExecutor()) | ||
// no KZG interface on CL side, EL responsibility | ||
.put("kzg/verify_kzg_proof", TestExecutor.IGNORE_TESTS) | ||
.build(); | ||
} |
83 changes: 83 additions & 0 deletions
83
...Test/java/tech/pegasys/teku/reference/phase0/kzg/KzgVerifyBlobProofBatchTestExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2022 | ||
* | ||
* 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.reference.phase0.kzg; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.util.List; | ||
import org.apache.tuweni.bytes.Bytes; | ||
import tech.pegasys.teku.ethtests.finder.TestDefinition; | ||
import tech.pegasys.teku.kzg.KZGCommitment; | ||
import tech.pegasys.teku.kzg.KZGProof; | ||
import tech.pegasys.teku.kzg.ckzg4844.CKZG4844; | ||
|
||
public class KzgVerifyBlobProofBatchTestExecutor extends KzgTestExecutor { | ||
|
||
@Override | ||
public void runTestImpl(final TestDefinition testDefinition) throws Throwable { | ||
final Data data = loadDataFile(testDefinition, Data.class); | ||
final Boolean expectedVerificationResult = data.getOutput(); | ||
Boolean actualVerificationResult; | ||
try { | ||
final List<Bytes> blobs = data.getInput().getBlobs(); | ||
final List<KZGCommitment> commitments = data.getInput().getCommitments(); | ||
final List<KZGProof> proofs = data.getInput().getProofs(); | ||
actualVerificationResult = | ||
CKZG4844.getInstance().verifyBlobKzgProofBatch(blobs, commitments, proofs); | ||
} catch (RuntimeException e) { | ||
actualVerificationResult = null; | ||
} | ||
assertThat(actualVerificationResult).isEqualTo(expectedVerificationResult); | ||
} | ||
|
||
private static class Data { | ||
@JsonProperty(value = "input", required = true) | ||
private Input input; | ||
|
||
@JsonProperty(value = "output", required = true) | ||
private Boolean output; | ||
|
||
public Input getInput() { | ||
return input; | ||
} | ||
|
||
public Boolean getOutput() { | ||
return output; | ||
} | ||
|
||
private static class Input { | ||
@JsonProperty(value = "blobs", required = true) | ||
private List<String> blobs; | ||
|
||
@JsonProperty(value = "commitments", required = true) | ||
private List<String> commitments; | ||
|
||
@JsonProperty(value = "proofs", required = true) | ||
private List<String> proofs; | ||
|
||
public List<Bytes> getBlobs() { | ||
return blobs.stream().map(Bytes::fromHexString).toList(); | ||
} | ||
|
||
public List<KZGCommitment> getCommitments() { | ||
return commitments.stream().map(KZGCommitment::fromHexString).toList(); | ||
} | ||
|
||
public List<KZGProof> getProofs() { | ||
return proofs.stream().map(KZGProof::fromHexString).toList(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this something we want to support in the future? If it is, it would be good to have a ticket for it linked here.
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.
mainnet
at the moment, if they are added we start to fail and will notice it