Skip to content

Commit

Permalink
Use official trusted setup (#7609)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov authored Oct 20, 2023
1 parent d418f8d commit 0d4f9eb
Show file tree
Hide file tree
Showing 36 changed files with 25,082 additions and 9,092 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ allprojects {
}
}

def refTestVersion = 'v1.4.0-beta.2-hotfix' // Arbitrary change to refresh cache number: 1
def refTestVersion = 'v1.4.0-beta.3' // Arbitrary change to refresh cache number: 1
def blsRefTestVersion = 'v0.1.2'
def refTestBaseUrl = 'https://github.com/ethereum/consensus-spec-tests/releases/download'
def blsRefTestBaseUrl = 'https://github.com/ethereum/bls12-381-tests/releases/download'
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
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 {

Expand All @@ -30,8 +29,8 @@ public void runTestImpl(final TestDefinition testDefinition) throws Throwable {
KZGCommitment actualKzgCommitment;
try {
final Bytes blob = data.getInput().getBlob();
actualKzgCommitment = CKZG4844.getInstance().blobToKzgCommitment(blob);
} catch (RuntimeException e) {
actualKzgCommitment = kzg.blobToKzgCommitment(blob);
} catch (final RuntimeException ex) {
actualKzgCommitment = null;
}
assertThat(actualKzgCommitment).isEqualTo(expectedKzgCommitment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
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 {

Expand All @@ -32,8 +31,8 @@ public void runTestImpl(final TestDefinition testDefinition) throws Throwable {
try {
final Bytes blob = data.getInput().getBlob();
final KZGCommitment commitment = data.getInput().getCommitment();
actualKzgProof = CKZG4844.getInstance().computeBlobKzgProof(blob, commitment);
} catch (RuntimeException e) {
actualKzgProof = kzg.computeBlobKzgProof(blob, commitment);
} catch (final RuntimeException ex) {
actualKzgProof = null;
}
assertThat(actualKzgProof).isEqualTo(expectedKzgProof);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import static tech.pegasys.teku.ethtests.finder.KzgTestFinder.KZG_DATA_FILE;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import tech.pegasys.teku.ethtests.finder.TestDefinition;
import tech.pegasys.teku.kzg.KZG;
import tech.pegasys.teku.kzg.ckzg4844.CKZG4844;
Expand All @@ -25,26 +27,33 @@
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";

private static final Pattern TEST_NAME_PATTERN = Pattern.compile("kzg-(.+)/.+");

protected final KZG kzg = CKZG4844.createInstance();

@Override
public final void runTest(TestDefinition testDefinition) throws Throwable {
public final void runTest(final TestDefinition testDefinition) throws Throwable {
final String network = extractNetwork(testDefinition.getTestName());
final Eth2NetworkConfiguration networkConfig =
Eth2NetworkConfiguration.builder(CONFIG_NAME).build();
Eth2NetworkConfiguration.builder(network).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();
}
kzg.freeTrustedSetup();
}
}

private String extractNetwork(final String testName) {
final Matcher matcher = TEST_NAME_PATTERN.matcher(testName);
if (matcher.find()) {
return matcher.group(1);
}
throw new IllegalArgumentException("Can't extract network from " + testName);
}

protected <T> T loadDataFile(final TestDefinition testDefinition, final Class<T> type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
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 {

Expand All @@ -34,9 +33,8 @@ public void runTestImpl(final TestDefinition testDefinition) throws Throwable {
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 = kzg.verifyBlobKzgProofBatch(blobs, commitments, proofs);
} catch (final RuntimeException ex) {
actualVerificationResult = null;
}
assertThat(actualVerificationResult).isEqualTo(expectedVerificationResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
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;

/**
* Actually uses {@link tech.pegasys.teku.kzg.KZG#verifyBlobKzgProofBatch(List, List, List)} KZG
Expand All @@ -40,10 +39,8 @@ public void runTestImpl(final TestDefinition testDefinition) throws Throwable {
final KZGCommitment commitment = data.getInput().getCommitment();
final KZGProof proof = data.getInput().getProof();
actualVerificationResult =
CKZG4844
.getInstance()
.verifyBlobKzgProofBatch(List.of(blob), List.of(commitment), List.of(proof));
} catch (RuntimeException e) {
kzg.verifyBlobKzgProofBatch(List.of(blob), List.of(commitment), List.of(proof));
} catch (final RuntimeException ex) {
actualVerificationResult = null;
}
assertThat(actualVerificationResult).isEqualTo(expectedVerificationResult);
Expand Down
Loading

0 comments on commit 0d4f9eb

Please sign in to comment.