Description
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.
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));
}
Metadata
Metadata
Assignees
Type
Projects
Status