diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml
index c3bbb9521..81824b31f 100644
--- a/gradle/verification-metadata.xml
+++ b/gradle/verification-metadata.xml
@@ -77,6 +77,14 @@
+
+
+
+
+
+
+
+
diff --git a/src/main/java/co/rsk/federate/BtcToRskClient.java b/src/main/java/co/rsk/federate/BtcToRskClient.java
index 5676e1e90..598d4f105 100644
--- a/src/main/java/co/rsk/federate/BtcToRskClient.java
+++ b/src/main/java/co/rsk/federate/BtcToRskClient.java
@@ -329,22 +329,22 @@ private void validateCoinbaseInformation(CoinbaseInformation coinbaseInformation
throw new IllegalArgumentException(message);
}
+ Optional expectedWitnessCommitment = BitcoinUtils.findWitnessCommitment(coinbaseTransaction);
co.rsk.bitcoinj.core.Sha256Hash calculatedWitnessCommitment = co.rsk.bitcoinj.core.Sha256Hash.twiceOf(
witnessMerkleRoot.getReversedBytes(),
witnessReservedValue
);
- BitcoinUtils.findWitnessCommitment(coinbaseTransaction)
- .filter(commitment -> commitment.equals(calculatedWitnessCommitment))
- .orElseThrow(() -> {
- String message = String.format(
- "Block %s with segwit peg-in tx %s generated an invalid witness merkle root",
- coinbaseInformation.getBlockHash(),
- coinbaseTransaction.getHash()
- );
- logger.error("[validateCoinbaseInformation] {}", message);
- return new IllegalArgumentException(message);
- });
+ if (expectedWitnessCommitment.isEmpty() || !expectedWitnessCommitment.get().equals(calculatedWitnessCommitment)) {
+ String message = String.format(
+ "Block %s with segwit peg-in tx %s generated an invalid witness commitment",
+ coinbaseInformation.getBlockHash(),
+ coinbaseTransaction.getHash()
+ );
+ logger.error("[validateCoinbaseInformation] {}", message);
+ throw new IllegalArgumentException(message);
+ }
+
logger.debug(
"[validateCoinbaseInformation] Block {} with segwit peg-in tx {} has a valid witness merkle root",
coinbaseInformation.getBlockHash(),
diff --git a/src/main/java/co/rsk/federate/FedNodeRunner.java b/src/main/java/co/rsk/federate/FedNodeRunner.java
index b5f876e8f..705922c83 100644
--- a/src/main/java/co/rsk/federate/FedNodeRunner.java
+++ b/src/main/java/co/rsk/federate/FedNodeRunner.java
@@ -57,7 +57,6 @@
import co.rsk.peg.btcLockSender.BtcLockSenderProvider;
import co.rsk.peg.pegininstructions.PeginInstructionsProvider;
import org.bitcoinj.core.Context;
-import org.bouncycastle.util.encoders.Hex;
import org.ethereum.crypto.ECKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;