Skip to content

Commit 507c8dc

Browse files
Solve the fact that in some cases the built transaction is discarded by Bitcoin nodes.
In `sec1_to_der`, I used to say that we need mock signing and assume the largest signature size that is reachable by providing `vec![1; 64]` in `mock_signer` in order to be in the if case for both conditions of `sec1_to_der`. However as far as I know Bitcoin uses sometimes variable length integer so `r` and `s` absolute values encoded by `vec![1; 64]` are less than `r` and `s` values encoded by `vec![255; 64]` and so the latter may take more signature size than the former. So in addition to assume that `r` and `s` are negative, we also have to assume that their value are the most negative one. So the solution is to return `vec![255; 64]` in mock_signer and not `vec![1; 64]`. It solves the problem as for a signed transaction size of 223 bytes it now considers a fee of 224 satoshis.
1 parent 5ad505c commit 507c8dc

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

rust/src/transaction_management.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ async fn mock_signer(
546546
_derivation_path: Vec<Vec<u8>>,
547547
_message_hash: Vec<u8>,
548548
) -> Result<Vec<u8>, ManagementCanisterReject> {
549-
Ok(vec![1; 64])
549+
Ok(vec![255; 64])
550550
}
551551

552552
// Converts a SEC1 ECDSA signature to the DER format.

0 commit comments

Comments
 (0)