Skip to content

update protocol#906

Open
JssDWt wants to merge 12 commits into
mainfrom
jssdwt-upate-protocol
Open

update protocol#906
JssDWt wants to merge 12 commits into
mainfrom
jssdwt-upate-protocol

Conversation

@JssDWt
Copy link
Copy Markdown
Collaborator

@JssDWt JssDWt commented May 23, 2026

This change updates how the Breez SDK talks to the Spark network for three core
operations: depositing Bitcoin into Spark, receiving a transfer from another user,
and cooperatively withdrawing back to Bitcoin. Each previously took two network
round-trips with the Spark operators; we collapse them into one, matching what the
reference Spark JS SDK already uses.

Copy link
Copy Markdown
Collaborator

@dangeross dangeross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

Comment thread crates/spark/src/operator/rpc/spark_rpc_client.rs Outdated
Comment thread crates/spark/src/services/deposit.rs
Comment thread crates/spark/src/services/transfer.rs Outdated
Comment on lines +884 to +888
if chunks.len() != 3 {
return Err(ServiceError::Generic(
"Not enough signing commitments returned".to_string(),
));
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only checking the commitments are chunked into 3, which could lead to a panic accessing the chunks later. Should we check signing_commitments.len() == 3 * leaves.len() instead?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch on that panic. I added guards around that.

)
.await?;

// TODO: Verify the returned tx signatures
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should definitely do this now we've dropped verifying the signature shares verifying key. Wdyt (could be a follow up PR)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I added it for the deposit. I will do others in a follow-up PR, after adding Turnkey integration with the higher-level signer.

@JssDWt JssDWt force-pushed the jssdwt-upate-protocol branch from 317e463 to 68a74b6 Compare May 29, 2026 08:31
JssDWt added 2 commits May 29, 2026 10:31
Replaces ad-hoc `signing_commitments.chunks(leaves.len())` patterns
in prepare_transfer_package, prepare_claim_package and
submit_coop_exit_transfer with a shared `split_signing_commitments_by_variant`
helper that rejects zero node_id_count up front (Vec::chunks(0) panics)
and validates total length equals `3 * node_id_count`. Adds empty-input
guards and a checked u32 conversion for leaves.len() at the claim site.
JssDWt added a commit that referenced this pull request May 29, 2026
The previous fused start_deposit_tree_creation flow returned signature
shares that we aggregated locally; the new package flow aggregates
server-side, so we relied on the operators implicitly. Restore the
end-to-end check by validating, on the response:

  * the returned verifying public key matches the one we used, and
  * the aggregated Schnorr key-path signatures on node_tx, refund_tx
    and direct_from_cpfp_refund_tx verify against the sighashes we
    computed earlier in the flow.

Addresses PR review #906#discussion_r3317972290.
@JssDWt JssDWt force-pushed the jssdwt-upate-protocol branch from 9642240 to 0ba6869 Compare May 29, 2026 13:38
The previous fused start_deposit_tree_creation flow returned signature
shares that we aggregated locally; the new package flow aggregates
server-side, so we relied on the operators implicitly. Restore the
end-to-end check by validating, on the response:

  * the returned verifying public key matches the one we used, and
  * the aggregated Schnorr key-path signatures on node_tx, refund_tx
    and direct_from_cpfp_refund_tx verify against the sighashes we
    computed earlier in the flow.

The verification helper lives next to sighash_from_tx in
bitcoin/service.rs so it can be reused by other flows.

Addresses PR review #906#discussion_r3317972290.
@JssDWt JssDWt marked this pull request as ready for review May 29, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants