Skip to content

Commit

Permalink
Fix a bug in Bitcoin::MessageSign#verify_message where the BIP322 che…
Browse files Browse the repository at this point in the history
…ck was always true
  • Loading branch information
azuchi committed Aug 17, 2024
1 parent 433c238 commit 0223415
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/bitcoin/message_sign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def verify_message(address, signature, message, prefix: Bitcoin.chain_params.mes
tx.in[0].script_witness = Bitcoin::ScriptWitness.parse_from_payload(sig)
script_pubkey = Bitcoin::Script.parse_from_addr(address)
tx_out = Bitcoin::TxOut.new(script_pubkey: script_pubkey)
interpreter = Bitcoin::ScriptInterpreter.new(checker: Bitcoin::TxChecker.new(tx: tx, input_index: 0, prevouts: [tx_out]))
flags = Bitcoin::STANDARD_SCRIPT_VERIFY_FLAGS
interpreter = Bitcoin::ScriptInterpreter.new(flags: flags, checker: Bitcoin::TxChecker.new(tx: tx, input_index: 0, prevouts: [tx_out]))
interpreter.verify_script(Bitcoin::Script.new, script_pubkey, tx.in[0].script_witness)
else
raise ArgumentError, "This address unsupported."
Expand Down
1 change: 1 addition & 0 deletions spec/bitcoin/message_sign_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
# Verify signature
expect(described_class.verify_message(addr, sig1, '')).to be true
expect(described_class.verify_message(addr, sig2, 'Hello World')).to be true
expect(described_class.verify_message(addr, sig2, 'Hello World2')).to be false
end
end

Expand Down

0 comments on commit 0223415

Please sign in to comment.