Skip to content

Commit

Permalink
Check is not a P2WSH
Browse files Browse the repository at this point in the history
This commit has not been tested but this check is mandatory as the grouphug requires P2WPKH:
  • Loading branch information
polespinasa committed May 6, 2024
1 parent b9986cd commit 171ea71
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions grouphug.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,16 @@ def validate_transaction(tx_raw):
# Check each input for the correct SigHash type
for input in tx['ins']:
if 'witness' in input and input['witness']:

if len(input['witness']) != 2:
# If len of witness is diff from 2 we know is a P2WSH and not a P2WPKH
return False, "Script is not a P2WPKH"

# Assuming the SigHash type is the last byte of the last item in the witness
last_byte = input['witness'][-1][-1]
if last_byte != (0x83): # Hex 0x83 stands for SigHashType.SINGLE | SigHashType.ANYONECANPAY
return False, "One or more inputs do not use the required SigHash type SINGLE | ANYONECANPAY."

else:
return False, "Witness data missing or invalid in one or more inputs."
return True, "Transaction is valid."
Expand Down

0 comments on commit 171ea71

Please sign in to comment.