Page MenuHomePhabricator

Cashaddr decoding the raw data and checksum
ClosedPublic

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

Details

Summary

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

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

Event Timeline

deadalnix created this revision.Sep 30 2017, 10:56
Herald added a reviewer: Restricted Project. · View Herald TranscriptSep 30 2017, 10:56
deadalnix updated this revision to Diff 1475.Oct 2 2017, 20:35

Various nits

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);
+    BOOST_CHECK_EQUAL_COLLECTIONS(
+            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 updated this revision to Diff 1540.Oct 11 2017, 23:49
deadalnix edited edge metadata.

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

deadalnix updated this revision to Diff 1541.Oct 12 2017, 10:38

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)
deadalnix updated this revision to Diff 1542.Oct 12 2017, 11:11

Add tests for no separator and dual separator

dagurval accepted this revision.Oct 12 2017, 21:47
dagurval added inline comments.
src/cashaddr.cpp
13 ↗(On Diff #1542)

Bech32 -> Cash address ?

18 ↗(On Diff #1542)

ditto

149 ↗(On Diff #1542)

😮

174 ↗(On Diff #1542)

Bech32 requres -> Cash address requires ?

src/test/cashaddr_tests.cpp
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
deadalnix updated this revision to Diff 1547.Oct 13 2017, 17:52

Comments from @dagurval

This revision was automatically updated to reflect the committed changes.