Skip to content
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

Cancun forkids for non-mainnets #6322

Merged
merged 2 commits into from
Jan 3, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,7 @@ private void configureNativeLibs() {
if (kzgTrustedSetupFile != null) {
KZGPointEvalPrecompiledContract.init(kzgTrustedSetupFile);
} else {
KZGPointEvalPrecompiledContract.init(network.name());
KZGPointEvalPrecompiledContract.init();
}
} else if (kzgTrustedSetupFile != null) {
throw new ParameterException(
Expand Down
320 changes: 155 additions & 165 deletions besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions besu/src/test/java/org/hyperledger/besu/RawForkIdTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright Hyperledger Besu contributors.
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*
*/
package org.hyperledger.besu;

import static org.assertj.core.api.Assertions.assertThat;

import org.hyperledger.besu.ethereum.forkid.ForkId;

import java.util.List;

import org.apache.tuweni.bytes.Bytes;
import org.junit.jupiter.api.Test;

public class RawForkIdTest {
@Test
public void testFromRaw() {
final ForkId forkId = new ForkId(Bytes.ofUnsignedInt(0xfe3366e7L), 1735371L);
final List<List<Bytes>> forkIdAsBytesList = List.of(forkId.getForkIdAsBytesList());
assertThat(ForkId.fromRawForkId(forkIdAsBytesList).get()).isEqualTo(forkId);
}
}
1 change: 1 addition & 0 deletions config/src/main/resources/goerli.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"londonBlock":5062605,
"terminalTotalDifficulty": 10790000,
"shanghaiTime": 1678832736,
"cancunTime": 1705473120,
"clique":{
"blockperiodseconds":15,
"epochlength":30000
Expand Down
1 change: 1 addition & 0 deletions config/src/main/resources/holesky.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"preMergeForkBlock": 0,
"terminalTotalDifficulty": 0,
"shanghaiTime": 1696000704,
"cancunTime": 1707305664,
"ethash": {},
"discovery": {
"bootnodes": [
Expand Down
1 change: 1 addition & 0 deletions config/src/main/resources/sepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"mergeNetSplitBlock": 1735371,
"terminalTotalDifficulty": 17000000000000000,
"shanghaiTime": 1677557088,
"cancunTime": 1706655072,
"ethash":{},
"discovery": {
"dns": "enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@all.sepolia.ethdisco.net",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class KZGPointEvalPrecompiledContract implements PrecompiledContract {

private static Bytes successResult;

private static void init() {
private static void loadLib() {
CKZG4844JNI.loadNativeLibrary();
Bytes fieldElementsPerBlob =
Bytes32.wrap(Words.intBytes(CKZG4844JNI.FIELD_ELEMENTS_PER_BLOB).xor(Bytes32.ZERO));
Expand All @@ -57,7 +57,7 @@ private static void init() {
*/
public static void init(final Path trustedSetupFile) {
if (loaded.compareAndSet(false, true)) {
init();
loadLib();
final String trustedSetupResourceName = trustedSetupFile.toAbsolutePath().toString();
LOG.info("Loading trusted setup from user-specified resource {}", trustedSetupResourceName);
CKZG4844JNI.loadTrustedSetup(trustedSetupResourceName);
Expand All @@ -67,17 +67,14 @@ public static void init(final Path trustedSetupFile) {
}

/**
* Init the C-KZG native lib using a resource identified by the passed network name as trusted
* setup
* Init the C-KZG native lib using mainnet trusted setup
*
* @param networkName used to select the resource in /kzg-trusted-setups/ to use.
* @throws IllegalStateException is the trusted setup was already loaded
*/
public static void init(final String networkName) {
public static void init() {
if (loaded.compareAndSet(false, true)) {
init();
final String trustedSetupResourceName =
"/kzg-trusted-setups/" + networkName.toLowerCase() + ".txt";
loadLib();
final String trustedSetupResourceName = "/kzg-trusted-setups/mainnet.txt";
LOG.info(
"Loading network trusted setup from classpath resource {}", trustedSetupResourceName);
CKZG4844JNI.loadTrustedSetupFromResource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class KZGPointEvalPrecompileContractTest {

@BeforeAll
public static void init() {
KZGPointEvalPrecompiledContract.init("mainnet");
KZGPointEvalPrecompiledContract.init();
contract = new KZGPointEvalPrecompiledContract();
}

Expand All @@ -55,7 +55,7 @@ public static void tearDown() {

@ParameterizedTest(name = "{index}")
@MethodSource("getPointEvaluationPrecompileTestVectors")
public void testComputePrecompile(final PrecompileTestParameters parameters) {
void testComputePrecompile(final PrecompileTestParameters parameters) {
when(toRun.getVersionedHashes()).thenReturn(Optional.of(List.of(parameters.versionedHash)));
PrecompiledContract.PrecompileContractResult result =
contract.computePrecompile(parameters.input, toRun);
Expand Down
Loading