Skip to content

Commit

Permalink
Make special case for irregular tx with segwit BSQ inputs
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
stejbac committed Jan 12, 2021
1 parent 224d903 commit fdc739d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions core/src/main/java/bisq/core/dao/node/full/RpcService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<String> 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;
Expand Down Expand Up @@ -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={}",
Expand Down

0 comments on commit fdc739d

Please sign in to comment.