Page MenuHomePhabricator

Cashaddr decoding the raw data and checksum

Authored by deadalnix on Sep 30 2017, 10:56.



This is split from D544 plus implement a candidate BCH code of degree 8 for it. The BCH code can detect up to 6 errors over the typical length of an address and up to 8 errors in a row.

This is intended to serve as a base to get the new address format started.

Test Plan

Added unittests.

Diff Detail

rABC Bitcoin ABC
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

dagurval requested changes to this revision.Oct 8 2017, 22:53
dagurval added a subscriber: dagurval.

I wrote you a failing unittest:

$ git diff
diff --git a/src/test/cashaddr_tests.cpp b/src/test/cashaddr_tests.cpp
index d1e3dc29e..74de83e34 100644
--- a/src/test/cashaddr_tests.cpp
+++ b/src/test/cashaddr_tests.cpp
@@ -32,6 +32,22 @@ bool CaseInsensitiveEqual(const std::string &s1, const std::string &s2) {
     return true;
+BOOST_AUTO_TEST_CASE(cashaddr_sanity_check) {
+    typedef std::pair<std::string, std::vector<uint8_t> > raw;
+    raw toEncode;
+    toEncode.first = "helloworld";
+    toEncode.second = { 0xf0, 0x0d };
+    std::string encoded = cashaddr::Encode(toEncode.first, toEncode.second);
+    raw decoded = cashaddr::Decode(encoded);
+    BOOST_CHECK_EQUAL(toEncode.first, decoded.first);
+            begin(toEncode.second), end(toEncode.second),
+            begin(decoded.second), end(decoded.second));
 BOOST_AUTO_TEST_CASE(bip173_testvectors_valid) {
     static const std::string CASES[] = {

This results in

test/cashaddr_tests.cpp(45): error: in "cashaddr_tests/cashaddr_sanity_check": check toEncode.first == decoded.first has failed [helloworld != ]
test/cashaddr_tests.cpp(48): error: in "cashaddr_tests/cashaddr_sanity_check": check { begin(toEncode.second), end(toEncode.second) } == { begin(decoded.second), end(decoded.second) } has failed.
Collections size mismatch: 2 != 0

  • 2 failures are detected in the test module "Bitcoin Test Suite"
This revision now requires changes to proceed.Oct 8 2017, 22:53
deadalnix edited edge metadata.

Update the parameters for the BCH code.
Add test cases and fix a bug.

Wrong window size in the comment for 5 errors.

deadalnix retitled this revision from [Draft] cashaddr draft. to Cashaddr decoding the raw data and checksum.Oct 12 2017, 11:00
deadalnix edited the summary of this revision. (Show Details)
deadalnix edited the test plan for this revision. (Show Details)

Add tests for no separator and dual separator

dagurval added inline comments.
13 ↗(On Diff #1542)

Bech32 -> Cash address ?

18 ↗(On Diff #1542)


149 ↗(On Diff #1542)


174 ↗(On Diff #1542)

Bech32 requres -> Cash address requires ?

34 ↗(On Diff #1542)

I'd like to see the sanity check I commented previously here.

This revision is now accepted and ready to land.Oct 12 2017, 21:47
This revision was automatically updated to reflect the committed changes.