Closed kaykurokawa closed 5 years ago
Agreed with the following:
b5
is OP_CLAIM_NAME
04
is 4 bytes or 63617473
63617473
is "cats"
4c
is OP_PUSHDATA1
dc
is 220 bytes or the claim
I don't process the ASM, but the raw data from lbrycrd for the chainquery app because there is different behavior for ASMs that make it unreliable as a source in this manner. Below is a screenshot of all claims by the name "cats". All the ASMs have this problem.
Taking a look at the code an interesting situation appears.
if (vch.size() <= static_cast<vector<unsigned char>::size_type>(4)) {
str += strprintf("%d", CScriptNum(vch, false).getint());
}
So if the group of bytes is 4 or less then lbrycrd treats it as a littleendian uint16 for the ASM which translates to...drum roll...1937006947
. Other wise it takes the hexstr which is what everyone expects to be the output.
To top it off this is also expected in the bitcoin codebase as well below: https://github.com/bitcoin/bitcoin/blob/master/src/core_write.cpp#L95
I also created an issue for the bitcoin repository to see what the functional use case of this is, in case anyone is ever interested in what the developers have to say: https://github.com/bitcoin/bitcoin/issues/13085
We can delete this if statement: https://github.com/lbryio/lbrycrd/blame/270307a29070a4c10095528e232ad0f8e251ec5a/src/core_write.cpp#L90
Since for our use case it is better to treat data of any size as a hex string
Are any new unit tests necessary for this, except those already in existence: https://github.com/lbryio/lbrycrd/blob/master/src/test/script_tests.cpp#L1067 ?
We can delete this if statement: https://github.com/lbryio/lbrycrd/blame/270307a29070a4c10095528e232ad0f8e251ec5a/src/core_write.cpp#L90
@kaykurokawa I'm not saying I strongly disagree here, since it's just a string representation, but I also think it can be easily (and consistently) handled upstream since it's the same data.
#include <stdio.h>
#include <arpa/inet.h>
int main(int argc, char** argv)
{
printf("%d, %x, %x\n", 1937006947, 1937006947, ntohl(1937006947));
return 0;
}
This prints out 1937006947, 73746163, 63617473
, which is what you'd expect.
@kaykurokawa What is the status of this issue? I
@mirgee provided https://github.com/lbryio/lbrycrd/pull/172 for a fix if someone wants to use it. But to err on the safe side, it shall not be merged in case some applications might expect the decode function to behave as it does in Bitcoin.
A proper solution should detect to see if data to print is part of a claim transaction, and always treat that data as hex if that is the case.
No one is depending on this feature so this is not urgent.
fixed via cherry-pick
Via Lex:
working on unit tests for the claim name script and using real live blockchain data and am confused about
lbrycrd
output:looking at the hex:
b5
is correct forOP_CLAIM_NAME
, then it's04
which is correct for length of upcoming string, consuming the next 4 bytes (8 in hex) gives uscats
: