Skip to content
Open
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 @@ -439,6 +439,9 @@ public class CommonParameter {
@Getter
@Setter
public String cryptoEngine = Constant.ECKey_ENGINE;
@Getter
@Setter
public boolean useNativeSecp256k1 = false;

@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class MiscConfig {
private long trxExpirationTimeInMilliseconds = Constant.TRANSACTION_DEFAULT_EXPIRATION_TIME;
private long blockNumForEnergyLimit = 4727890L;
private String cryptoEngine = Constant.ECKey_ENGINE;
private boolean useNativeSecp256k1 = false;
private List<String> seedNodeIpList = new ArrayList<>();

public static MiscConfig fromConfig(Config config) {
Expand Down Expand Up @@ -51,6 +52,8 @@ public static MiscConfig fromConfig(Config config) {
// crypto
mc.cryptoEngine = config.hasPath("crypto.engine")
? config.getString("crypto.engine") : Constant.ECKey_ENGINE;
mc.useNativeSecp256k1 = config.hasPath("crypto.useNativeSecp256k1")
&& config.getBoolean("crypto.useNativeSecp256k1");

// seed node
mc.seedNodeIpList = config.hasPath("seed.node.ip.list")
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ node.backup {
# Algorithm for generating public key from private key. Do not modify to avoid forks.
crypto {
engine = "eckey" # Signature engine.
# Use JNA-backed libsecp256k1 for signature verification when engine = "eckey".
useNativeSecp256k1 = false
}

# Energy limit block number (config key has typo "enery" preserved for backward compatibility)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void testDefaults() {
mc.getTrxExpirationTimeInMilliseconds());
// reference.conf has crypto.engine = "eckey" (lowercase)
assertEquals("eckey", mc.getCryptoEngine());
assertFalse(mc.isUseNativeSecp256k1());
// reference.conf has seed.node.ip.list with actual IPs
assertFalse(mc.getSeedNodeIpList().isEmpty());
}
Expand All @@ -40,13 +41,14 @@ public void testFromConfig() {
"storage { needToUpdateAsset = false,"
+ " balance { history { lookup = true } } }\n"
+ "trx { reference { block = head } }\n"
+ "crypto { engine = sm2 }\n"
+ "crypto { engine = sm2, useNativeSecp256k1 = true }\n"
+ "seed.node { ip.list = [\"1.2.3.4:18888\"] }");
MiscConfig mc = MiscConfig.fromConfig(config);
assertFalse(mc.isNeedToUpdateAsset());
assertTrue(mc.isHistoryBalanceLookup());
assertEquals("head", mc.getTrxReferenceBlock());
assertEquals("sm2", mc.getCryptoEngine());
assertTrue(mc.isUseNativeSecp256k1());
assertEquals(1, mc.getSeedNodeIpList().size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.security.SignatureException;
import java.util.stream.Collectors;
import org.bouncycastle.util.encoders.Hex;
import org.tron.common.crypto.ECKey;
import org.tron.common.crypto.SignUtils;
import org.tron.common.overlay.message.Message;
import org.tron.common.utils.ByteUtil;
import org.tron.common.utils.Sha256Hash;
Expand Down Expand Up @@ -96,8 +96,8 @@ public DataType getDataType() {

public void analyzeSignature() throws SignatureException {
byte[] hash = Sha256Hash.hash(true, getPbftMessage().getRawData().toByteArray());
publicKey = ECKey.signatureToAddress(hash, TransactionCapsule
.getBase64FromByteString(getPbftMessage().getSignature()));
publicKey = SignUtils.signatureToAddress(hash, TransactionCapsule
.getBase64FromByteString(getPbftMessage().getSignature()), true);
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions crypto/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ repositories {

dependencies {
api project(":common")
implementation 'net.java.dev.jna:jna:5.12.1'
implementation 'com.github.federico2014.besu-native:secp256k1:1.3.11'
Comment thread
Federico2014 marked this conversation as resolved.
Comment thread
Federico2014 marked this conversation as resolved.
}

jacocoTestReport {
Expand Down
Loading
Loading