@@ -329,22 +329,22 @@ private void validateCoinbaseInformation(CoinbaseInformation coinbaseInformation
329329 throw new IllegalArgumentException (message );
330330 }
331331
332+ Optional <co .rsk .bitcoinj .core .Sha256Hash > expectedWitnessCommitment = BitcoinUtils .findWitnessCommitment (coinbaseTransaction );
332333 co .rsk .bitcoinj .core .Sha256Hash calculatedWitnessCommitment = co .rsk .bitcoinj .core .Sha256Hash .twiceOf (
333334 witnessMerkleRoot .getReversedBytes (),
334335 witnessReservedValue
335336 );
336337
337- BitcoinUtils .findWitnessCommitment (coinbaseTransaction )
338- .filter (commitment -> commitment .equals (calculatedWitnessCommitment ))
339- .orElseThrow (() -> {
340- String message = String .format (
341- "Block %s with segwit peg-in tx %s generated an invalid witness merkle root" ,
342- coinbaseInformation .getBlockHash (),
343- coinbaseTransaction .getHash ()
344- );
345- logger .error ("[validateCoinbaseInformation] {}" , message );
346- return new IllegalArgumentException (message );
347- });
338+ if (expectedWitnessCommitment .isEmpty () || !expectedWitnessCommitment .get ().equals (calculatedWitnessCommitment )) {
339+ String message = String .format (
340+ "Block %s with segwit peg-in tx %s generated an invalid witness commitment" ,
341+ coinbaseInformation .getBlockHash (),
342+ coinbaseTransaction .getHash ()
343+ );
344+ logger .error ("[validateCoinbaseInformation] {}" , message );
345+ throw new IllegalArgumentException (message );
346+ }
347+
348348 logger .debug (
349349 "[validateCoinbaseInformation] Block {} with segwit peg-in tx {} has a valid witness merkle root" ,
350350 coinbaseInformation .getBlockHash (),
0 commit comments