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

address to public-key-rmd #52

Open
hamnaz opened this issue Jan 28, 2021 · 7 comments
Open

address to public-key-rmd #52

hamnaz opened this issue Jan 28, 2021 · 7 comments

Comments

@hamnaz
Copy link

hamnaz commented Jan 28, 2021

i have address
bc1qsssfz2x83e8mlhwl52n7y5p8c3rj5r4yk0744y
i want convert to hash160 (20byte)
could you guide what command you saying to work
i tried all way its return always error
thankx for update me

@Meru852
Copy link

Meru852 commented Feb 1, 2021 via email

@voltaxvoltax
Copy link

Since the --batch option dont work, I've made following shell script to make the conversion, I hope this help you guys:
#!/usr/bin/bash
while read value
do
random=$(./bitcoin-tool --input-type address --input-format base58check --input $value --output-type public-key-rmd --output-format hex)
echo $random
done < FILEWITHBASE58ADDRESSES.txt

@streamofstars
Copy link

@voltaxvoltax why do you say batch option does not work? Please give me an example.

@voltaxvoltax
Copy link

voltaxvoltax commented Apr 30, 2021

@streamofstars

@voltaxvoltax why do you say batch option does not work? Please give me an example.

running the command :
./bitcoin-tool --batch --input-type address --output-type public-key-rmd --input-format base58check --network bitcoin --output-format hex --input-file FILE.txt
Gives the following error, even using the fix, it still dont work :

Failed to decode Base58Check input (checksum failure).
You can use the --fix-base58check option to change the input string until the checksum is valid, but this may return a false positive match.

@streamofstars
Copy link

@voltaxvoltax ok, you are right, seems like a bug. I just tested on some addresses I took from the newest block and the tool behaves unpredictably. It throws errors on some addresses when a file is provided as an input but is able to convert them separately. Also, if the problematic address is at the first or second line of an input file then it works but if it is at the third line it does not. Weird. @matja FYI

@matja
Copy link
Owner

matja commented Apr 30, 2021

Thanks for the report, I believe I have found the cause of this.
When using --batch, does the failing address start with 1 and follows an address starting with 3?

matja added a commit that referenced this issue Apr 30, 2021
@matja
Copy link
Owner

matja commented Apr 30, 2021

Pushed 439aaaa to fix batch mode decoding of some addresses.
Still need to check bech32 addresses.

Minimal test case:

cat > fail.txt << EOF
3R2cuenjG5nFubqX9Wzuukdin2YfBbQ6Kw
1111111111111111111114oLvT2
EOF

./bitcoin-tool \
--batch \
--network bitcoin \
--input-type address \
--input-format base58check \
--input-file fail.txt \
--output-type public-key-rmd \
--output-format hex

expected:

ffffffffffffffffffffffffffffffffffffffff
0000000000000000000000000000000000000000

actual:

ffffffffffffffffffffffffffffffffffffffff
Failed to decode Base58Check input (checksum failure).
You can use the --fix-base58check option to change the input string until the checksum is valid, but this may return a false positive match.

This happens because the leading zeros in the output buffer is not initialized at:

bn_bytes_wrote = BN_bn2bin(result, output+leading_zeros);

So the 0x05 address prefix (P2SH), which is not part of the rmd160 hash, is not overwritten by the 0x00 address prefix (P2PKH) of the leading zeros in the second address.

Added test to catch this:

Test failure (old code):

failed test 17 - 0-padded base58 decoding prefix initialization

Test pass (new code):

pass 17 - 0-padded base58 decoding prefix initialization
...
all tests passed

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

No branches or pull requests

5 participants