-
Notifications
You must be signed in to change notification settings - Fork 868
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
Unified Addresses support #21460
Unified Addresses support #21460
Conversation
367c99b
to
f7bcf22
Compare
A Storybook has been deployed to preview UI for the latest push |
A Storybook has been deployed to preview UI for the latest push |
A Storybook has been deployed to preview UI for the latest push |
@@ -36,6 +43,9 @@ module.exports = function RunCommand (options) { | |||
updatePatches(catapultDir, catapultPatchDir), | |||
// third_party/devtools-frontend/src | |||
updatePatches(devtoolsFrontendDir, devtoolsFrontendPatchDir), | |||
// brave/third_party/bitcoin-core | |||
updatePatches(bitcoinDir, bitcoinPatchDir), | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: empty line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
return /^t1[a-km-zA-HJ-NP-Z1-9]{33}$/.test(value) || /^u1[a-z0-9]+$/.test(value) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: needs formatting
std::string GetHPersonalizer(uint8_t i); | ||
std::string GetGPersonalizer(uint8_t i, uint16_t j); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two do not need to be public
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are used in tests
std::vector<uint8_t> GetLeft(const std::vector<uint8_t>& message) { | ||
size_t left_size = | ||
std::min(static_cast<size_t>(kLeftSize), message.size() / 2); | ||
return std::vector(message.begin(), message.begin() + left_size); | ||
} | ||
|
||
std::vector<uint8_t> GetRight(const std::vector<uint8_t>& message) { | ||
size_t left_size = | ||
std::min(static_cast<size_t>(kLeftSize), message.size() / 2); | ||
return std::vector(message.begin() + left_size, message.end()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static_cast<size_t>(kLeftSize)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
std::string GetHPersonalizer(uint8_t i) { | ||
return {85, 65, 95, 70, 52, 74, 117, | ||
109, 98, 108, 101, 95, 72, static_cast<char>(i), | ||
0, 0}; | ||
} | ||
|
||
std::string GetGPersonalizer(uint8_t i, uint16_t j) { | ||
return {85, | ||
65, | ||
95, | ||
70, | ||
52, | ||
74, | ||
117, | ||
109, | ||
98, | ||
108, | ||
101, | ||
95, | ||
71, | ||
static_cast<char>(i), | ||
static_cast<char>(j & 0xFF), | ||
static_cast<char>(j >> 8)}; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should return std:array<uint8_t, 16>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
TEST(F4JumbleUnitTest, ApplyF4Jumble) { | ||
{ | ||
std::vector<uint8_t> input = {}; | ||
|
||
std::vector<uint8_t> expected = {}; | ||
|
||
EXPECT_EQ(expected, ApplyF4Jumble(input)); | ||
} | ||
|
||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to test Apply + Revert resulting in original input. Also covering corner cases for input sizes.
Something like
std::vector<uint8_t> input(1000, 'a');
auto input_span = make_span(input);
for (int i = 0; i < input_span.size(); ++i) {
auto d = input_span.subspan(0, i);
EXPECT_EQ(d, RevertF4Jumble(ApplyF4Jumble(d)));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
if (personalizer.length() != sizeof(params.personal)) { | ||
NOTREACHED(); | ||
return std::nullopt; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personalizer should be a fixed size span, and this check should become a CHECK or a static assert
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
if (blake2b_init_param(&blake_state, ¶ms) != 0) { | ||
NOTREACHED(); | ||
return std::nullopt; | ||
} | ||
if (blake2b_update(&blake_state, payload.data(), payload.size()) != 0) { | ||
NOTREACHED(); | ||
return std::nullopt; | ||
} | ||
std::vector<uint8_t> result(len); | ||
if (blake2b_final(&blake_state, result.data(), len) != 0) { | ||
NOTREACHED(); | ||
return std::nullopt; | ||
} | ||
|
||
return result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blake2b_* calls fail only on invalid inputs. We should just CHECK the result and blake2b function should not return an optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
if (!hash || hash->size() != left.size()) { | ||
return std::nullopt; | ||
} | ||
std::vector<uint8_t> result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blake2b should never fail and always return hash size equal to left.size(). So this method never fails an no optional needed.
Same for g_round
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
// https://zips.z.cash/zip-0316#encoding-of-unified-addresses | ||
enum AddrType { | ||
P2PKH = 0x00, | ||
P2PSH = 0x01, | ||
Sapling = 0x02, | ||
Orchard = 0x03, | ||
End = 0x04 | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec does not mention End = 0x04. What is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to check whether code is known (less than End)
|
||
for (const auto& part : parts.value()) { | ||
if (part.first == AddrType::P2PKH) { | ||
return PubkeyToTransparentAddress(part.second, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
false is_testnet ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
auto reverted = RevertF4Jumble(data); | ||
if (!reverted || reverted->size() < 16) { | ||
return std::nullopt; | ||
} | ||
|
||
auto parts = ParseUnifiedAddress( | ||
base::make_span(*reverted).subspan(0, reverted->size() - 16)); | ||
if (!parts.has_value()) { | ||
return std::nullopt; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a comment and a constant for what is 16
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
A Storybook has been deployed to preview UI for the latest push |
} | ||
|
||
auto reverted = RevertF4Jumble(data); | ||
// HRP with 16 bytes padding which is appened to the end of message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
appended
} | ||
|
||
auto parts = ParseUnifiedAddress( | ||
base::make_span(*reverted).subspan(0, reverted->size() - 16)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kPaddedHrpSize
@@ -48,4 +48,13 @@ TEST(ZCashUtilsUnitTest, PubkeyToTransparentAddress) { | |||
false)); | |||
} | |||
|
|||
TEST(ZCashUtilsUnitTest, ExtractTransparentPart) { | |||
auto transparent_past = ExtractTransparentPart( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transparent_part
export function isValidZecAddress(value: string): boolean { | ||
return /^t1[a-km-zA-HJ-NP-Z1-9]{33}$/.test(value) | ||
return /^t1[a-km-zA-HJ-NP-Z1-9]{33}$/.test(value) || | ||
/^u1[a-z0-9]+$/.test(value) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should handle testnet also
A Storybook has been deployed to preview UI for the latest push |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strings
++
A Storybook has been deployed to preview UI for the latest push |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f4_jumble.cc
, chromium_src/patches
lgtm.
A Storybook has been deployed to preview UI for the latest push |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
util.js changes ok
[puLL-Merge] - brave/brave-core@21460 DescriptionThe pull request appears to be integrating Bitcoin Core support into Brave by adding patching capabilities and updating utility functions for ZCash addresses. It includes the proper patching for the new ChangesChangesPatch Updates
ZCash Address Handling
New Features (F4 Jumble)
Localization
Dependency Patching
Build Script
Security Hotspots
|
A Storybook has been deployed to preview UI for the latest push |
Resolves brave/brave-browser#32239
Resolves
Submitter Checklist:
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
wikinpm run lint
,npm run presubmit
wiki,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan: