Skip to content

Conversation

@dimxy
Copy link
Collaborator

@dimxy dimxy commented Aug 14, 2025

When KDF validates that all inputs signed with a certain pubkey, an internal extract_signature function is used.
This function has too restrictive opcode check for the signature in the scriptSig so some signatures did not pass this check.

This PR relaxes this signature check and relies on the third-party library function to parse and validate DER signatures.

Fixes: #2592

@dimxy dimxy self-assigned this Aug 14, 2025
@dimxy dimxy added priority: urgent Critical tasks requiring immediate action. bug: core labels Aug 14, 2025
@dimxy dimxy marked this pull request as ready for review August 14, 2025 13:17
Copy link
Collaborator

@mariocynicys mariocynicys left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

I'd rather lean for keeping things restrictive and only ease the rules when we have an example at hand that doesn't fit (like this one).

@cipig
Copy link

cipig commented Aug 14, 2025

before trying this fix, i tried the exact same swap again (same taker, same maker) and this time it worked fine
i don't really understand why

@mariocynicys
Copy link
Collaborator

before trying this fix, i tried the exact same swap again (same taker, same maker) and this time it worked fine
i don't really understand why

signatures are 64 bytes but variable in size when der encoded. the encoded sig size varies between 70 and 72 bytes (but seems like 69 is also valid too given this PR).
the swap u tested probably had a 70 bytes signature.

Copy link

@cipig cipig left a comment

Choose a reason for hiding this comment

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

did a bunch of swaps AXE/KMD, back and forth, all working fine
other swaps also still working fine

mariocynicys
mariocynicys previously approved these changes Aug 18, 2025
Copy link
Collaborator

@mariocynicys mariocynicys left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

},
opcode => Err(format!("Unexpected opcode {opcode:?}")),
Some(Ok(instruction)) => match instruction.data {
Some(bytes) if !bytes.is_empty() => Ok(bytes.to_vec()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: let's not do the if !is_empty() check to be consistent with the error messages like the pubkey extraction counterpart.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We need to have at least one byte in this data because we will send a slice of len-1 of it to SecpSignature::from_der fn.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ooh. nice catch. this -1 seems a lil bit dangerous. maybe we could use .saturating_sub in this situation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed to saturating_sub, thanks

@shamardy
Copy link
Collaborator

I don't think this
https://github.com/KomodoPlatform/komodo-defi-framework/blob/10009a604056bc662fc78f49f5921251789eed1f/mm2src/coins/utxo/utxo_common.rs#L2299
will always be a tx deserialization error

@dimxy
Copy link
Collaborator Author

dimxy commented Aug 26, 2025

.map_to_mm(ValidatePaymentError::TxDeserializationError)?;

fixed to return a structured error fbe9854 instead converting string to TxDeserializationError

@shamardy shamardy merged commit e775849 into dev Aug 28, 2025
18 of 32 checks passed
@shamardy shamardy deleted the fix-extract-signature branch August 28, 2025 01:26
dimxy pushed a commit that referenced this pull request Oct 15, 2025
…unction (#2591)

This change relaxes scriptSig parsing and P2PK verification to handle real‑world P2PK/P2PKH variants across UTXO chains. Signatures are accepted from any non‑empty push, and pubkeys are parsed from any push and validated as compressed or uncompressed secp256k1 keys. This improves compatibility with chain‑specific encodings (e.g., 69‑byte AXE signatures) without loosening validation, and includes tests for AXE‑like sizes and empty scriptSig cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug: core priority: urgent Critical tasks requiring immediate action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants