Post
Topic
Board Bitcoin Technical Support
Merits 15 from 7 users
Re: Sign Transaction Bitcoin with Openssl
by
BrewMaster
on 17/02/2020, 11:37:19 UTC
⭐ Merited by suchmoon (7) ,OgNasty (2) ,o_e_l_e_o (2) ,Heisenberg_Hunter (1) ,ETFbitcoin (1) ,DdmrDdmr (1) ,barno (1)
Code:
mandatory-script-verify-flag-failed (Script failed an OP_EQUALVERIFY operation) (code 16)

you should pay attention to the error messages you see. they usually tell you what was wrong.
in this case the problem is the public key you included in the scriptsig.

the script verification is like this:
- push 1 item (sig)
- push 1 item (pubkey)
- duplicate top stack item
- pop and hash top stack item with RIPEMD160 of SHA256 and push the result
- pop top 2 stak items and see if they are equal

this last step is where it stops because the hashes are not equal.
with a closer look you are using the "uncompressed" public key (it starts with 4 and is 65 bytes) which is wrong. you should replace it with compressed key which is 03d6e5ff918b8388dc49cdfc115ddc1ea9fd4d884dd8b87ef6602a6bd07b5c1748
then the evaluation will pass.

there is also another point to keep in mind which OpenSSL is not doing which is you MUST have a low S value otherwise the signature verification will fail.
to do that parse the signature, if (S > N/2) then S = N - S