Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore non-standard outputs when searching for the witness commitment hash #373

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/main/java/co/rsk/federate/BtcToRskClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ private void validateCoinbaseInformation(CoinbaseInformation coinbaseInformation
throw new IllegalArgumentException(message);
}

Optional<co.rsk.bitcoinj.core.Sha256Hash> expectedWitnessCommitment = BitcoinUtils.findWitnessCommitment(coinbaseTransaction);
Optional<co.rsk.bitcoinj.core.Sha256Hash> expectedWitnessCommitment = BitcoinUtils.findWitnessCommitment(coinbaseTransaction, federatorSupport.getConfigForBestBlock());
co.rsk.bitcoinj.core.Sha256Hash calculatedWitnessCommitment = co.rsk.bitcoinj.core.Sha256Hash.twiceOf(
witnessMerkleRoot.getReversedBytes(),
witnessReservedValue
Expand Down
7 changes: 4 additions & 3 deletions src/test/java/co/rsk/federate/BtcToRskClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import co.rsk.federate.signing.utils.TestUtils;
import co.rsk.net.NodeBlockProcessor;
import co.rsk.peg.PegUtilsLegacy;
import co.rsk.peg.bitcoin.BitcoinUtils;
import co.rsk.peg.btcLockSender.*;
import co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType;
import co.rsk.peg.constants.BridgeConstants;
Expand Down Expand Up @@ -51,6 +50,8 @@
* Created by ajlopez on 6/1/2016.
*/
class BtcToRskClientTest {
private static final Sha256Hash WITNESS_RESERVED_VALUE = Sha256Hash.ZERO_HASH;
private static final int WITNESS_COMMITMENT_LENGTH = 36; // 4 bytes for header, 32 for hash
private int nhash = 0;
private ActivationConfig activationConfig;
private BridgeConstants bridgeRegTestConstants;
Expand Down Expand Up @@ -2774,15 +2775,15 @@ private Transaction getCoinbaseTransactionWithWrongWitnessCommitment() {
coinbaseTx.verify();

TransactionWitness txWitness = new TransactionWitness(1);
txWitness.setPush(0, BitcoinUtils.WITNESS_RESERVED_VALUE.getBytes());
txWitness.setPush(0, WITNESS_RESERVED_VALUE.getBytes());
coinbaseTx.getInput(0).setWitness(txWitness);

Sha256Hash witnessCommitment = Sha256Hash.wrap("0011223344556677889900112233445566778899001122334455667788990011");
String witnessCommitmentHeader = "aa21a9ed";
byte[] wrongWitnessCommitmentWithHeader = ByteUtil.merge(
new byte[]{ScriptOpCodes.OP_RETURN},
new byte[]{ScriptOpCodes.OP_PUSHDATA1},
new byte[]{BitcoinUtils.WITNESS_COMMITMENT_LENGTH},
new byte[]{WITNESS_COMMITMENT_LENGTH},
Hex.decode(witnessCommitmentHeader),
witnessCommitment.getBytes()
);
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/co/rsk/federate/bitcoin/BitcoinTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.bouncycastle.util.encoders.Hex;
import org.ethereum.crypto.HashUtil;

public final class BitcoinTestUtils {

public static final byte[] WITNESS_COMMITMENT_HEADER = Hex.decode("aa21a9ed");
public static final Sha256Hash WITNESS_RESERVED_VALUE = Sha256Hash.ZERO_HASH;
public static final int WITNESS_COMMITMENT_LENGTH = WITNESS_COMMITMENT_HEADER.length + Sha256Hash.LENGTH;

private BitcoinTestUtils() { }

public static List<Coin> coinListOf(long... values) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,10 @@ void processBlock_ok() {
TransactionReceipt receipt = mock(TransactionReceipt.class);
List<LogInfo> logs = new ArrayList<>();

SignatureCache signatureCache = new BlockTxSignatureCache(new ReceivedTxSignatureCache());

BridgeEventLoggerImpl bridgeEventLogger = new BridgeEventLoggerImpl(
new BridgeRegTestConstants(),
activations,
logs,
signatureCache
logs
);

Keccak256 value = createHash(3);
Expand Down Expand Up @@ -282,13 +279,10 @@ void accepts_transaction_with_two_release_requested() {
TransactionReceipt receipt = mock(TransactionReceipt.class);
List<LogInfo> logs = new ArrayList<>();

SignatureCache signatureCache = new BlockTxSignatureCache(new ReceivedTxSignatureCache());

BridgeEventLoggerImpl bridgeEventLogger = new BridgeEventLoggerImpl(
new BridgeRegTestConstants(),
activations,
logs,
signatureCache
logs
);

Keccak256 releaseRequestTxHash = createHash(3);
Expand Down
Loading