-
Notifications
You must be signed in to change notification settings - Fork 895
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
[ZCash] Implement Zcash sync process and Orchard inputs spending #27018
base: master
Are you sure you want to change the base?
Conversation
A Storybook has been deployed to preview UI for the latest push |
73a1e11
to
21e1e2d
Compare
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.
++ Wallet Front-end
auto frontier_bytes = PrefixedHexStringToBytes( | ||
base::StrCat({"0x", frontier_tree_state_.value()->orchardTree})); |
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.
It looks like it should be HexStringToBytes(frontier_tree_state_.value()->orchardTree)
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.
PrefixedHexStringToBytes is a bit more complicated: for ex. it appends 0 if input size is odd. I'd prefer to use it instead.
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.
PrefixedHexStringToBytes is for EVM's encoding of integers. It is not supposed to be used unless it is explictly required by format of hex string.
As afar as I can see orchardTree is just hex encoded bytes, so decoding to bytes should be done with HexStringToBytes and fail in case of odd size
GURL request_url = MakeGetLightdInfoURL(GetNetworkURL(chain_id)); | ||
|
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.
Is it unintentinonal removal?
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.
Returned
initial_ranges_count_ = | ||
std::ceil(static_cast<double>((to - from + 1)) / kBatchSize); | ||
scan_ranges_ = std::deque<ScanRange>(); |
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.
Can it be rewritten somehow so it's easier to track if always to >= form
?
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
case ZCashShieldSyncService::ErrorCode::kFailedToVerifyChainState: | ||
return 7; | ||
case ZCashShieldSyncService::ErrorCode::kFailedToUpdateSubtreeRoots: | ||
return 8; | ||
case ZCashShieldSyncService::ErrorCode::kDatabaseError: | ||
return 9; | ||
case ZCashShieldSyncService::ErrorCode::kScannerError: | ||
return 10; | ||
} |
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.
would that be enough to just return static_cast<size_t>(error);
?
And why it returns size_t
?
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.
It was enum class, reworked using simple enum
return; | ||
} else { | ||
verify_chain_state_task_.reset(); |
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.
It seems verify_chain_state_task_.reset();
should be done with chain_state_verified_ = true
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.
It is
|
||
namespace brave_wallet { | ||
|
||
class ZCashVerifyChainStateTask { |
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.
A brief comment would be helpful for all such task classes
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
OrchardAddrRawPart receiver_; | ||
std::optional<OrchardMemo> memo_; | ||
uint64_t amount_; | ||
|
||
bool started_ = 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.
Why we need these started_
flags for tasks?
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 ensure that Start is called only once
orchard_output.value = zcash_transaction.TotalInputsAmount() - | ||
zcash_transaction.fee() - pick_result->change; | ||
orchard_output.addr = receiver_; |
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 some explanation or guards so this does not overflow
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
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.
To avoid copy paste that should be based on base::CheckedNumeric
[puLL-Merge] - brave/brave-core@27018 DescriptionThis PR introduces significant changes to the Brave Wallet's ZCash implementation, particularly focusing on the Orchard protocol and shielded transactions. The changes include new task classes for handling various ZCash operations, improvements to the transaction creation and signing process, and updates to the user interface for ZCash-related features. Possible Issues
Security Hotspots
ChangesChanges
sequenceDiagram
participant User
participant UI
participant ZCashWalletService
participant ZCashScanBlocksTask
participant ZCashBlocksBatchScanTask
participant ZCashCompleteTransactionTask
participant Blockchain
User->>UI: Initiate ZCash operation
UI->>ZCashWalletService: Request operation
ZCashWalletService->>ZCashScanBlocksTask: Start block scanning
loop For each batch
ZCashScanBlocksTask->>ZCashBlocksBatchScanTask: Scan batch
ZCashBlocksBatchScanTask->>Blockchain: Fetch blocks
Blockchain-->>ZCashBlocksBatchScanTask: Return block data
ZCashBlocksBatchScanTask-->>ZCashScanBlocksTask: Return batch result
end
ZCashScanBlocksTask-->>ZCashWalletService: Scanning complete
ZCashWalletService->>ZCashCompleteTransactionTask: Complete transaction
ZCashCompleteTransactionTask->>Blockchain: Submit transaction
Blockchain-->>ZCashCompleteTransactionTask: Transaction result
ZCashCompleteTransactionTask-->>ZCashWalletService: Operation result
ZCashWalletService-->>UI: Operation complete
UI-->>User: Display result
|
@@ -57,13 +70,15 @@ void ZCashCreateShieldTransactionTask::WorkOnTask() { | |||
|
|||
if (!transaction_ && !CreateTransaction()) { |
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.
why transaction_ is checked here?
std::move(start_address), std::move(callback))); | ||
task->ScheduleWorkOnTask(); | ||
auto task = base::MakeRefCounted<ZCashDiscoverNextUnusedZCashAddressTask>( | ||
base::PassKey<class ZCashWalletService>(), weak_ptr_factory_.GetWeakPtr(), |
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.
don't need class here most likely
Resolves brave/brave-browser#42898
Sec review: https://github.com/brave/reviews/issues/1834
Implements basic sync process for the Orchard protocol.
Entry point for the sync process is the per-account ZCashShieldSyncService class.
Sync process includes:
ZCashCreateOrchardToOrchardTransactionTask then could be used to construct shielded transaction.
ZCashCompleteTransactionTask completes transactions by calculating witness for every shielded input and signing the transaction.
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 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: