Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripthash not correct #89

Open
Ljzn opened this issue Jan 23, 2024 · 4 comments
Open

scripthash not correct #89

Ljzn opened this issue Jan 23, 2024 · 4 comments

Comments

@Ljzn
Copy link

Ljzn commented Jan 23, 2024

Get atomicals at location returns wrong scripthash.

request:

curl -v "https://ep.atomicalneutron.com/proxy/blockchain.atomicals.at_location?params=\[%22d21f8ea708b21608b09cfec7ca263e35d69b63e1380db0f68954a2b5b3ba8c8fi0%22\]"

response:

{"success":true,"response":{"location_info":{"location":"d21f8ea708b21608b09cfec7ca263e35d69b63e1380db0f68954a2b5b3ba8c8fi0","txid":"d21f8ea708b21608b09cfec7ca263e35d69b63e1380db0f68954a2b5b3ba8c8f","index":0,"scripthash":"4b2ff9b90f0fca6341f6cac374d414a7ee59379a528990cf3a8d1c74bfa4ef45","script":"0014fb7454e043913f46cee06143ff3f320b6e2f8041","value":546},"atomicals":[{"atomical_id":"9125f03bcf9325f6071762b9aee00b461a0b43ed157c336e2e89e07f47ea6f66i0","atomical_number":149087,"atomical_ref":"j4jz0eyfjcjzc1rqcawtxr0b8rd0pgzd2ny36vheh7g7yhzadxk0i0","type":"FT"}]}}

The scripthash here is "4b2ff9b90f0fca6341f6cac374d414a7ee59379a528990cf3a8d1c74bfa4ef45" .

Not equal to the correct scripthash of address "bc1qld69fczrjyl5dnhqv9pl70ejpdhzlqzpu0mfjh", which should be "8e6cec514958b4af4002f0c0a6f9f7b0a84944fcb7e6034083c112aaf7dea721".

We can get the atomical with the correct scripthash:

curl -v "https://ep.atomicalneutron.com/proxy/blockchain.atomicals.listscripthash?params=\[%228e6cec514958b4af4002f0c0a6f9f7b0a84944fcb7e6034083c112aaf7dea721%22\]"
# response is too large to paste here

curl -v "https://ep.atomicalneutron.com/proxy/blockchain.atomicals.listscripthash?params=\[%224b2ff9b90f0fca6341f6cac374d414a7ee59379a528990cf3a8d1c74bfa4ef45%22\]"
# request with wrong scripthash just returns empty utxos

So I think the scripthash in the response of blockchain.atomicals.at_location is not correct. The script field is correct.

@dubuqingfeng
Copy link
Contributor

hex_to_bytes = bytes.fromhex
HASHX_LEN = 11

from pycoin.symbols.btc import network
import hashlib

_sha256 = hashlib.sha256


def hex_str_to_hash(x):
    '''Convert a displayed hex string to a binary hash.'''
    return bytes(reversed(hex_to_bytes(x)))


def scripthash_to_hashX(scripthash):
    bin_hash = hex_str_to_hash(scripthash)
    if len(bin_hash) == 32:
        return bin_hash[:HASHX_LEN]


def address_to_script(addr):
    script = network.parse.address(addr).script()
    return script.hex()


def address_to_scripthash(addr):
    script = network.parse.address(addr).script()
    return hashlib.sha256(script).digest()[::-1].hex()


def sha256(x):
    '''Simple wrapper of hashlib sha256.'''
    return _sha256(x).digest()


def double_sha256(x):
    '''SHA-256 of SHA-256, as used extensively in bitcoin.'''
    return sha256(sha256(x))


def address_to_scripthash_atomicals(addr):
    scripthash = double_sha256(network.parse.address(addr).script())
    return scripthash


def hash_to_hex_str(x):
    return bytes(reversed(x)).hex()


print(address_to_script('bc1qld69fczrjyl5dnhqv9pl70ejpdhzlqzpu0mfjh'))
print(address_to_scripthash('bc1qld69fczrjyl5dnhqv9pl70ejpdhzlqzpu0mfjh'))
print(hash_to_hex_str(address_to_scripthash_atomicals('bc1qld69fczrjyl5dnhqv9pl70ejpdhzlqzpu0mfjh')))

@Ljzn
Copy link
Author

Ljzn commented Jan 24, 2024

For convenience to others, the result of that python script is:

0014fb7454e043913f46cee06143ff3f320b6e2f8041
8e6cec514958b4af4002f0c0a6f9f7b0a84944fcb7e6034083c112aaf7dea721
4b2ff9b90f0fca6341f6cac374d414a7ee59379a528990cf3a8d1c74bfa4ef45

Is runhash_to_hex_str for scripthash on purpose here? I don't quite understand.

@shadowv0vshadow
Copy link
Collaborator

shadowv0vshadow commented Jan 24, 2024

For convenience to others, the result of that python script is:

0014fb7454e043913f46cee06143ff3f320b6e2f8041
8e6cec514958b4af4002f0c0a6f9f7b0a84944fcb7e6034083c112aaf7dea721
4b2ff9b90f0fca6341f6cac374d414a7ee59379a528990cf3a8d1c74bfa4ef45

Is runhash_to_hex_str for scripthash on purpose here? I don't quite understand.

Hexadecimal strings are more human-readable and easier to understand.

@Ljzn
Copy link
Author

Ljzn commented Jan 25, 2024

For convenience to others, the result of that python script is:为了方便其他人,该 python 脚本的结果是:

0014fb7454e043913f46cee06143ff3f320b6e2f8041
8e6cec514958b4af4002f0c0a6f9f7b0a84944fcb7e6034083c112aaf7dea721
4b2ff9b90f0fca6341f6cac374d414a7ee59379a528990cf3a8d1c74bfa4ef45

Is runhash_to_hex_str for scripthash on purpose here? I don't quite understand.这里是故意的吗 hash_to_hex_str scripthash ?我不太明白。

Hexadecimal strings are more human-readable and easier to understand.

Yes, but the scripthash be converted to hex twice here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants