Skip to content

Commit

Permalink
Merge pull request #2 from polespinasa/main
Browse files Browse the repository at this point in the history
Check is not a P2WSH
  • Loading branch information
federicociro authored May 7, 2024
2 parents b9986cd + 171ea71 commit 63b1f00
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 63b1f00

Please sign in to comment.