Bitcoin: Is pkh() nested in tr() allowed?

Bitcoin Core Test Cases: PKH() nested in TR() enabled

The Bitcoin Core test suite has been updated to allow pkh() nested within tr() in certain cases. This feature was flagged as invalid in the original test vector, but is now included.

What are PKH() and TR()?

pkh() is a command that converts a key (address) from one format to another (for example, from Bitcoin script format to human-readable text). tr() is a command that reverses the order of characters in a string. In the context of Bitcoin, both commands are used for formatting and debugging.

Initial test vector

Bitcoin: pkh() nested in tr() is allowed?

In the original test vector, the following code was marked as invalid:

// Test vector: PKH() nested in TR()

int main() {

printf("%s\n", pkh(tr("addr1M4nLp9zJfRt2F7VwQqG5dXxSTK3yWYrP"))); // not valid

return 0;

}

The tr() command was used to convert the address from script format to text, but then the pkh() command was used to convert the resulting string back to Bitcoin script format. This nested use of both commands has been flagged as invalid.

Bitcoin Core Test Suite Update

However, in the updated test suite, this behavior is no longer considered a bug. The code in question can now be rewritten without using tr():

// Test vector: PKH() nested in TR() (updated)

int main() {

printf("%s\n", pkh("addr1M4nLp9zJfRt2F7VwQqG5dXxSTK3yWYrP")); // allowed

return 0;

}

In this updated version, the pkh() command is used directly to convert the address into script format, without using the tr() command.

Conclusion

The Bitcoin Core test suite has been updated to allow pkh() to nest in tr(). This feature can be used to simplify debugging and formatting operations, but it can cause performance problems if used excessively. It is important to carefully review the code before updating any existing tests or applications that use this behavior.

Market Capitalization

Leave a Comment

Your email address will not be published. Required fields are marked *