Post
Topic
Board Development & Technical Discussion
very difficult question about real verify the signature
by
zhengjianxun
on 12/08/2018, 12:04:40 UTC
this question maybe some High difficulty , but it about important detail about bitcoin.real bitcoin expert can explain it.

i want to verify the signature in bitcoin.so i usesd the information in
https://blockchain.info/rawtx/5c76eb4dfb0941856a229833ef05b2f5c669dadc98ed2a34ea11974cacba9dc7?format=hex
this website is its hex serialize.

first:
0100000001107f46ae8f3ba0f1f9c5170f950a6fb0d6461a92718b5aa06ee776c4e114afdb00000 00048473044022014d647cd08f1ea5b31d1e6539b6cbceb9182f6e7b2e29fb969354ef7e3434923022 028bb4eda36af410149baa936322e7c0e46cc5540a3aa89c811bc3c360028bfd301ffffffff020a372f2d010000001976a9148ff0d9ee3c2c4b86d19d265cbd360e95c5191e3d88ac3 2ee9f00000000001976a9145c11f917883b927eef77dc57707aeb853f6d389488ac00000000

the red is the sig

second:
delete the sig

third:
add the previous output  script
https://blockchain.info/rawtx/dbaf14e1c476e76ea05a8b71921a46d6b06f0a950f17c5f9f1a03b8fae467f10?format=hex
it is 434104b0bd634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e6537a576782 eba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c1e0908ef7bac

four :
add  to posithon of sig :
0100000001107f46ae8f3ba0f1f9c5170f950a6fb0d6461a92718b5aa06ee776c4e114afdb00000 000434104b0bd634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e6537a576 782eba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c1e0908ef7bacffffffff020a372f2d0 10000001976a9148ff0d9ee3c2c4b86d19d265cbd360e95c5191e3d88ac32ee9f00000000001976 a9145c11f917883b927eef77dc57707aeb853f6d389488ac00000000

five :
add the hashtype:
01000000

so the code is :
0100000001107f46ae8f3ba0f1f9c5170f950a6fb0d6461a92718b5aa06ee776c4e114afdb00000 000434104b0bd634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e6537a576 782eba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c1e0908ef7bacffffffff020a372f2d0 10000001976a9148ff0d9ee3c2c4b86d19d265cbd360e95c5191e3d88ac32ee9f00000000001976 a9145c11f917883b927eef77dc57707aeb853f6d389488ac0000000001000000

six:
double hash256 is :
f27c6c3aa42563c958292922be1e53fe107f4db0dfadba11122f0b12bf77f3ab

but when i want to verify it ,false,false,false  so  what happend , i think i am right!!


the verify go code is :

package main

import (
   "crypto/ecdsa"
   "crypto/elliptic"
   "fmt"
   "math/big"
   "encoding/hex"
)


func main(){


   pubkey,_:=hex.DecodeString("b0bd634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e6537a576782eba668 a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c1e0908ef7b");



   curve := elliptic.P256()
   //公钥的长度
   keyLen := len(pubkey)

   x := big.Int{}
   y := big.Int{}
   x.SetBytes(pubkey[:(keyLen / 2)])
   y.SetBytes(pubkey[(keyLen / 2):])

   rawPubKey := ecdsa.PublicKey{curve, &x, &y}


   //hash
   hash,_:=hex.DecodeString("f27c6c3aa42563c958292922be1e53fe107f4db0dfadba11122f0b12bf77f3ab   ")


   
   r := big.Int{}
   s := big.Int{}
   rr,_:=hex.DecodeString("14d647cd08f1ea5b31d1e6539b6cbceb9182f6e7b2e29fb969354ef7e3434923")
   ss,_:=hex.DecodeString("28bb4eda36af410149baa936322e7c0e46cc5540a3aa89c811bc3c360028bfd3")

   r.SetBytes(rr)
   s.SetBytes(ss)

   

   if ecdsa.Verify(&rawPubKey, hash[:], &r, &s) == false {
      fmt.Printf("%s\n", "true")
   }else{
      fmt.Printf("%s\n", "false")
   }

}