Skip to content

Commit

Permalink
fix errors in Falcon precompiled due to code updates
Browse files Browse the repository at this point in the history
  • Loading branch information
eum602 committed Jul 6, 2023
1 parent 39d18fa commit 71c7dc3
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 223 deletions.
11 changes: 7 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ allprojects {

repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/lacchain/liboqs-java/")
url 'https://maven.pkg.github.com/lacchain/liboqs-java'
content { includeGroupByRegex('org\\.openquantumsafe(\\..*)?') }
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("USERNAME")
password = project.findProperty("gpr.key") ?: System.getenv("TOKEN")
}
}
maven {
url 'https://hyperledger.jfrog.io/hyperledger/besu-maven'
content { includeGroupByRegex('org\\.hyperledger\\..*') }
Expand Down Expand Up @@ -739,8 +740,6 @@ task testDocker {
}

task dockerUpload {
dependsOn distDocker
def dockerBuildVersion = project.hasProperty('release.releaseVersion') ? project.property('release.releaseVersion') : "${rootProject.version}"
def imageName = "ghcr.io/lacchain/besu"
def azureImageName = "hyperledger.azurecr.io/besu"
def image = "${imageName}:${dockerBuildVersion}"
Expand All @@ -750,6 +749,10 @@ task dockerUpload {
additionalTags.add('develop')
}

if (!isInterimBuild(dockerBuildVersion)) {
additionalTags.add(dockerBuildVersion.split(/\./)[0..1].join('.'))
}

doLast {
for (def variant in dockerVariants) {
def variantImage = "${image}-${variant}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ public OptionalLong getThanosBlockNumber() {
@Override
public OptionalLong getLacchainPostQuantumBlockNumber() {
return getOptionalLong("lacchainpqblock");
}

@Override
public OptionalLong getMagnetoBlockNumber() {
return getOptionalLong("magnetoblock");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ public OptionalLong getThanosBlockNumber() {
public OptionalLong getLacchainPostQuantumBlockNumber() {
return lacchainPostQuantumBlockNumber;
}

@Override
public OptionalLong getMagnetoBlockNumber() {
return magnetoBlockNumber;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class Address extends DelegatingBytes {
public static final Address BLS12_MAP_FP_TO_G1 = Address.precompiled(0x11);
/** The constant BLS12_MAP_FP2_TO_G2. */
public static final Address BLS12_MAP_FP2_TO_G2 = Address.precompiled(0x12);
/** Constant for Precompiled Falcon verification signature. */
public static final Address LACCHAIN_FALCON = Address.precompiled(0x13);
/** The constant KZG_POINT_EVAL. */
public static final Address KZG_POINT_EVAL = Address.precompiled(0x14);
/** The constant ZERO. */
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
*/
package org.hyperledger.besu.ethereum.mainnet;

import org.hyperledger.besu.ethereum.core.Account;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.mainnet.precompiles.FalconPrecompiledContract;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.evm.internal.EvmConfiguration;
import org.hyperledger.besu.evm.precompile.FalconPrecompiledContract;
import org.hyperledger.besu.evm.precompile.PrecompileContractRegistry;

import java.math.BigInteger;
import java.util.Optional;
Expand All @@ -27,21 +28,19 @@ public static ProtocolSpecBuilder postQuantumDefinition(
final Optional<BigInteger> chainId,
final OptionalInt contractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason,
final boolean quorumCompatibilityMode) {
final boolean enableRevertReason) {
return MainnetProtocolSpecs.istanbulDefinition(
chainId,
contractSizeLimit,
configStackSizeLimit,
enableRevertReason,
quorumCompatibilityMode)
EvmConfiguration.DEFAULT)
.precompileContractRegistryBuilder(
precompiledContractConfiguration -> {
PrecompileContractRegistry lacchainContractsRegistry =
MainnetPrecompiledContractRegistries.istanbul(precompiledContractConfiguration);
lacchainContractsRegistry.put(
Address.LACCHAIN_FALCON,
Account.DEFAULT_VERSION,
new FalconPrecompiledContract(
precompiledContractConfiguration.getGasCalculator()));
return lacchainContractsRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ public ProtocolSpecBuilder experimentalEipsDefinition(
evmConfiguration);
}

public ProtocolSpecBuilder lacchainDefinition() {
return LacchainProtocolSpecs.postQuantumDefinition(
chainId, contractSizeLimit, evmStackSize, isRevertReasonEnabled);
}

////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
// Classic Protocol Specs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ private Stream<Optional<BuilderMapEntry>> createMilestones(
config.getGrayGlacierBlockNumber(), specFactory.grayGlacierDefinition(config)),
blockNumberMilestone(
config.getMergeNetSplitBlockNumber(), specFactory.parisDefinition(config)),
blockNumberMilestone(
config.getLacchainPostQuantumBlockNumber(), specFactory.lacchainDefinition()),
// Timestamp Forks
timestampMilestone(config.getShanghaiTime(), specFactory.shanghaiDefinition(config)),
timestampMilestone(config.getCancunTime(), specFactory.cancunDefinition(config)),
Expand Down
1 change: 1 addition & 0 deletions evm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies {
implementation 'com.github.ben-manes.caffeine:caffeine'
implementation 'com.google.guava:guava'
implementation 'net.java.dev.jna:jna'
implementation 'org.openquantumsafe:liboqs-java'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-units'
implementation 'org.hyperledger.besu:arithmetic'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.mainnet.precompiles;
package org.hyperledger.besu.evm.precompile;

import static java.nio.charset.StandardCharsets.UTF_8;

import org.hyperledger.besu.crypto.Hash;
import org.hyperledger.besu.ethereum.core.Gas;
import org.hyperledger.besu.ethereum.mainnet.AbstractPrecompiledContract;
import org.hyperledger.besu.ethereum.vm.GasCalculator;
import org.hyperledger.besu.ethereum.vm.MessageFrame;
import org.hyperledger.besu.evm.frame.MessageFrame;
import org.hyperledger.besu.evm.gascalculator.GasCalculator;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.openquantumsafe.Signature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* note: Liboqs - random number generation defaults to /dev/urandom a better form is to use the
Expand All @@ -35,7 +33,7 @@
*/
public class FalconPrecompiledContract extends AbstractPrecompiledContract {

private static final Logger LOG = LogManager.getLogger();
private static final Logger LOG = LoggerFactory.getLogger(AbstractBLS12PrecompiledContract.class);

private static final Bytes METHOD_ABI =
Hash.keccak256(Bytes.of("verify(bytes,bytes,bytes)".getBytes(UTF_8))).slice(0, 4);
Expand All @@ -47,8 +45,9 @@ public FalconPrecompiledContract(final GasCalculator gasCalculator) {
}

@Override
public Gas gasRequirement(final Bytes input) {
return gasCalculator().sha256PrecompiledContractGasCost(input);
public long gasRequirement(final Bytes input) {
long value = gasCalculator().sha256PrecompiledContractGasCost(input);
return value;
}

@Override
Expand Down

0 comments on commit 71c7dc3

Please sign in to comment.