Visitar URL original
Invalid witness address when the localwitness is null · Issue #6281 · tronprotocol/java-tron · GitHub
Skip to content

Invalid witness address when the localwitness is null #6281

Description

@Federico2014

Software Versions

OS : Mac OS
JVM : Oracle Corporation 1.8.0_161 amd64
Version : 4.7.7

Expected behavior

When launching the full-node with the null localwitness config, the node should run normally without an witness address .

localwitness = [
]

Actual behavior

It generates an invalid witness address: 41dcc703c0e500b653ca82273b7bfad8045d85a470 even when the private key is null.

Image

After analysis, I find that even if the localwitness is null, it will still execute initWitnessAccountAddress function.

 else if (config.hasPath(Constant.LOCAL_WITNESS)) {
      localWitnesses = new LocalWitnesses();
      List<String> localwitness = config.getStringList(Constant.LOCAL_WITNESS);
      localWitnesses.setPrivateKeys(localwitness);
      witnessAddressCheck(config);
      localWitnesses.initWitnessAccountAddress(PARAMETER.isECKeyCryptoEngine());
      logger.debug("Got privateKey from config.conf");
    }

From the initWitnessAccountAddress function, it will invoke the fromPrivate function.

  public void initWitnessAccountAddress(boolean isECKeyCryptoEngine) {
    if (witnessAccountAddress == null) {
      byte[] privateKey = ByteArray.fromHexString(getPrivateKey());
      final SignInterface ecKey = SignUtils.fromPrivate(privateKey,
          isECKeyCryptoEngine);
      this.witnessAccountAddress = ecKey.getAddress();
    }
  }

In this case, the privKeyBytes is [] instead of null, so it continues to execute fromPrivate(new BigInteger(1, privKeyBytes)). So, the empty private key is finally passed to the Bouncycastle library, which leads to an implicit error and outputs an invalid address.

  public static ECKey fromPrivate(byte[] privKeyBytes) {
    if (Objects.isNull(privKeyBytes)) {
      return null;
    }
    return fromPrivate(new BigInteger(1, privKeyBytes));
  }

Activity

  1. FriendlyCM commented on Apr 10, 2025

    @FriendlyCM

    Discovering this question is really great, and looking forward to solving it! No address should be generated when no localwitness is provided.

  2. Federico2014 commented on Apr 10, 2025

    @Federico2014
    CollaboratorAuthor

    @abc-x-t Yes, we will solve it after discussion.

  3. halibobo1205 commented on Apr 10, 2025

    @halibobo1205
    Collaborator

    I also found this issue when upgrading the BCP-related dependencies of org.bouncycastle. See curve25519 private key parsing fails since 1.74.
    Passing an empty private key will throw an IllegalArgumentException:

    java.lang.IllegalArgumentException: Scalar is not in the interval [1, n - 1]
  4. Federico2014 commented on Apr 10, 2025

    @Federico2014
    CollaboratorAuthor

    @halibobo1205 Yes, the current BC version 1.69 is incomplete, so the exception is not thrown out explicitly. We should consider upgrading the BC.

  5. Federico2014 commented on Apr 10, 2025

    @Federico2014
    CollaboratorAuthor

    Currently, the bouncycastle version of java-tron is v1.69, while the libp2p bouncycastle version is v1.79. I have checked the bouncycastle release notes. If we upgrade the bouncycastle version to v1.79, there are some potential benefits:

    • optimizations for the Blake3, KeccakDisget, SHA-256 algorithms;
    • optimize the key range check of SM2;
    • support the post-quantum cryptography, such as BIKE, CMCE, Frodo, HQC, Picnic,LMS/HSS, SPHINCS+, Dilithium, Falcon, and NTRU, which will prepare for future upgrades.
    • keep up with libp2p boucycastle version.

    @halibobo1205 Do you think is it necessary to upgrade the bouncycastle version?

  6. halibobo1205 commented on Apr 10, 2025

    @halibobo1205
    Collaborator

    Upgrade the Bouncycastle version to 1.8.0? @Federico2014

  7. Federico2014 commented on Apr 10, 2025

    @Federico2014
    CollaboratorAuthor

    I just consider keeping the same version with libp2p. Upgrading to version 1.80 is ok.

  8. moved this to Todo in java-tronon May 19, 2025
  9. FriendlyCM commented on May 29, 2025

    @FriendlyCM

    keeping the same version with libp2p

    Yes, I think keep same version with libp2p is better, because we are not sure whether higher version is compatible with libp2p

  10. moved this from To Do to In Progress in java-tronon May 29, 2025
  11. added and removed on Jun 12, 2025
  12. linked a pull request that will close this issuefix(crypto): resolve the invalid witness #6368on Jun 30, 2025
  13. moved this from In Progress to In Review in java-tronon Jun 30, 2025
  14. Benson0224 commented on Jul 24, 2025

    @Benson0224
    Collaborator

    Status Update: This issue has been scheduled for implementation in the next release, tentatively V4.8.1. The resolution plan is as follows

    • ✅ Added to development pipeline
    • ⏳ Will close automatically when core PRs land
    • 🔔 Maintain real-time status updates here

    However, all discussions related to this issue remain welcome. Please continue the conversation here if you have relevant topics to contribute. Thanks!

    At last, please follow V4.8.1 status at Issue #6342 and watch this issue (via Subscribe button) to track progress if needed. We value your involvement in TRON's development!

  15. moved this from In Review to Done in java-tronon Aug 20, 2025
  16. closed this as completedby moving to Done in java-tronon Aug 20, 2025
  17. Federico2014 commented on Aug 28, 2025

    @Federico2014
    CollaboratorAuthor

    To address the issue, the changes made are as follows:

    • When the localwitness configuration is empty, an invalid witness address will no longer be generated.
    • The bouncycastle dependency version has been upgraded from 1.69 to 1.79.
    • When a non-witness node starts, witness private key and address initialization will no longer be executed.
    • If the command-line parameter --witness-address or the localWitnessAccountAddress in the configuration file is invalid, the code will throw an exception and exit (versions prior to 4.8.1 derived the witness address from the private key).
    • When configuring localWitnessAccountAddress, only one private key is allowed for localwitness. Otherwise, the program will throw an exception and exit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions