From 5611905fe1058bb9c3a54fe3c0c8db662b811301 Mon Sep 17 00:00:00 2001 From: Steven Barclay Date: Fri, 8 Jan 2021 21:37:55 +0000 Subject: [PATCH] Make special case for irregular tx with segwit BSQ inputs Selectively disable pubkey extraction from segwit inputs of a particular tx at block height 660384 (2020-12-07), which spends spuriously created segwit BSQ (later burned), to prevent a change in the DAO state hashes from that point. (Since a tx with a given ID can only appear on one chain, a fixed global exclusion list of IDs should not cause any issues on testnet/regtest versus mainnet. This is simpler than conditioning by block height.) --- .../java/bisq/core/dao/node/full/RpcService.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/bisq/core/dao/node/full/RpcService.java b/core/src/main/java/bisq/core/dao/node/full/RpcService.java index b6cbbba83a1..fb0b533e193 100644 --- a/core/src/main/java/bisq/core/dao/node/full/RpcService.java +++ b/core/src/main/java/bisq/core/dao/node/full/RpcService.java @@ -48,6 +48,7 @@ import java.math.BigDecimal; import java.util.List; +import java.util.Set; import java.util.function.Consumer; import java.util.stream.Collectors; @@ -62,6 +63,13 @@ */ @Slf4j public class RpcService { + // The BSQ tx with the following ID has 1 segwit (P2WPKH) BSQ input and 1 segwit (P2WPKH) + // BTC input, but with null pubKey already recorded in the DaoState for both inputs. Thus + // we must make a special case for it, as it was mined prior to the BSQ segwit upgrade. + private static final Set BSQ_TXS_DISALLOWING_SEGWIT_PUB_KEYS = Set.of( + "d1f45e55be6101b1b75e6bf9fc5e5341c6ab420647be7555863bbbddd84e92f3" // in mainnet block 660384, 2020-12-07 + ); + private final String rpcUser; private final String rpcPassword; private final String rpcHost; @@ -246,8 +254,10 @@ private static RawTx getTxFromRawTransaction(RawTransaction rawDtoTx, // To maintain backwards compatibility when serializing and hashing the DAO state, // segwit pubKeys are only extracted for the first input, as this will always be a // BSQ input. Later inputs might be segwit BTC, which would have had a null pubKey - // recorded in the DAO state prior to the segwit upgrade of the RPC client. - String pubKeyAsHex = extractPubKeyAsHex(rawInput, rawInput == rawDtoTx.getVIn().get(0)); + // recorded in the DAO state prior to the segwit upgrade of the RPC client. Spurious + // segwit BSQ inputs in txs mined prior to the upgrade also require exclusion. + String pubKeyAsHex = extractPubKeyAsHex(rawInput, rawInput == rawDtoTx.getVIn().get(0) && + !BSQ_TXS_DISALLOWING_SEGWIT_PUB_KEYS.contains(txId)); if (pubKeyAsHex == null) { log.debug("pubKeyAsHex is not set as we received a not supported sigScript. " + "txId={}, asm={}, txInWitness={}",