1

This is the top ranking result on google for OP_EQUALVERIFY: non-equal data error.

In the answer, the person gets the uncompressed public key and its address from the scriptSig.

Is there a website link I can be pointed to where I can give scriptSig as input, and receive the uncompressed public key and address please?

0

2 Answers 2

2

This answer provides a good description of a task similar to what you are trying to accomplish.

This wiki page shows how scripts are serialized and deserialized. It's actually not very hard to extract the raw opcodes from the script by hand, especially if you know it's a standard type of script.

But, you may use https://chainquery.com/bitcoin-api/decodescript and paste in the raw hex of the scriptSig for a more automated solution. The parsed opcodes will be in the result.asm field, including any raw data (such as signatures and pubkeys) separated by spaces. If you look for the element(s) of the script that start with 02/03/04, that will be the public key.

2

You seem to be under the impression that addresses are generated from a scriptSig, which is wrong. Addresses are always generated off of the scriptPubKey in the output of a transaction. The scriptSig spends that scriptPubKey. Inside of the the scriptPubKey, there is a constant called a pubkeyhash which is what is used to generate a bitcoin adddress. This pubkeyhash will be different depending on if your pubkey is compressed or uncompressed. Here is an example of a console session using bitcoin-s to demonstrate how compressed vs uncompressed public keys generate different addresses

chris@chris-870Z5E-880Z5E-680Z5E:~/dev/bitcoins-core$ sbt console 
[info] Loading project definition from /home/chris/dev/bitcoins-core/project
[info] Set current project to bitcoin-s-core (in build file:/home/chris/dev/bitcoins-core/)
[info] Starting scala interpreter...
[info] 
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_101).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import org.bitcoins.core.crypto._
import org.bitcoins.core.crypto._

scala> import org.bitcoins.core.protocol._ 
import org.bitcoins.core.protocol._

scala> val privKey = ECPrivateKey() 
privKey: org.bitcoins.core.crypto.ECPrivateKey = ECPrivateKey(06e166f6d40cf6366bfa8f0b60f8f8526fde4095322af89ee9db64569f7db680,true)

scala> val pubKey = privKey.publicKey
pubKey: org.bitcoins.core.crypto.ECPublicKey = ECPublicKey(023e5970f3fdf82372ca6778837caff638caf81bdee7a8ba70f16130a299b6c5d6)

scala> val unCompressedPrivKey = ECPrivateKey.fromHex(privKey.hex,false)
unCompressedPrivKey: org.bitcoins.core.crypto.ECPrivateKey = ECPrivateKey(06e166f6d40cf6366bfa8f0b60f8f8526fde4095322af89ee9db64569f7db680,false)

scala> val unCompressedPublicKey = unCompressedPrivKey.publicKey
unCompressedPublicKey: org.bitcoins.core.crypto.ECPublicKey = ECPublicKey(043e5970f3fdf82372ca6778837caff638caf81bdee7a8ba70f16130a299b6c5d6e05500f2e535d80296db3c106ee9030a31c34c1723d5dbd64f39335f9d18e0aa)

scala> import org.bitcoins.core.config._
import org.bitcoins.core.config._
//note these two hashes are different ! ! ! 
scala> val pubKeyHash = CryptoUtil.sha256Hash160(pubKey.bytes)
pubKeyHash: org.bitcoins.core.crypto.Sha256Hash160Digest = Sha256Hash160DigestImpl(a83f9e96392c2b9809cdc5e0ef3893b3877e575d)

scala> val unCompressedPubKeyHash = CryptoUtil.sha256Hash160(unCompressedPublicKey.bytes)
unCompressedPubKeyHash: org.bitcoins.core.crypto.Sha256Hash160Digest = Sha256Hash160DigestImpl(f1492e86f3daff5ed261e60980b9b494f6c13ff6)

scala> val address = P2PKHAddress(pubKeyHash, MainNet) 
address: org.bitcoins.core.protocol.P2PKHAddress = P2PKHAddressImpl(1GLcjb1qbbspXEGBoGdm7aaU51KK4iKAa3)

scala> val unCompressedAddress = P2PKHAddress(unCompressedPubKeyHash, MainNet) 
unCompressedAddress: org.bitcoins.core.protocol.P2PKHAddress = P2PKHAddressImpl(1NzoWzJkPWbNENd3XkJNYf1S9BxhLThb8M)

So if you were to provide the uncompressed version of the public key in the scriptSig instead of the compressed version (or vice versa if you hashed the uncompressed version with OP_HASH160) you will get an error saying the data was not equivalent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.