Skip to content

fix: Signature serializes more bytes than are deserialized#686

Merged
bobbinth merged 5 commits intonextfrom
sergerad-fix-signature-serde
Dec 3, 2025
Merged

fix: Signature serializes more bytes than are deserialized#686
bobbinth merged 5 commits intonextfrom
sergerad-fix-signature-serde

Conversation

@sergerad
Copy link
Contributor

@sergerad sergerad commented Dec 3, 2025

Closes #685.

We discovered in 0xMiden/protocol#2128 that serialization of Signature is problematic.

It appears that an additional byte is serialized but not deserialized.

impl Serializable for Signature {
fn write_into<W: ByteWriter>(&self, target: &mut W) {
let mut bytes = [0u8; SIGNATURE_BYTES];
let mut bytes = [0u8; SIGNATURE_BYTES - 1];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unsure how we actually want to fix this. Put this here for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is probably related to #668 (and now thinking about it, my concern about the odd number of bytes is not valid).

@Al-Kindi-0 - is there a reason we need 66 bytes vs. 65 bytes for serialization?

Also, this should probably go into main as it seems like a bug fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

For now, we could just read the extra byte during deserialization and discard it as a fix, right? That means we wouldn't actually touch the serialization format, in case that is somehow important.

Copy link
Contributor

@bobbinth bobbinth Dec 3, 2025

Choose a reason for hiding this comment

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

Yeah, I think we probably want to do two things:

  1. The short-term fix that reads the extra byte and discards it - this would go into main.
  2. The longer term fix that reduces signature size to 65 bytes (assuming that's the correct thing to do) - that would go into next.

@sergerad sergerad added the no changelog This PR does not require an entry in the `CHANGELOG.md` file label Dec 3, 2025
Copy link
Contributor

@bobbinth bobbinth 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! Thank you! Also, let's update the changelog.

I'd hold off on merging before review from @Al-Kindi-0.

@sergerad sergerad removed the no changelog This PR does not require an entry in the `CHANGELOG.md` file label Dec 3, 2025
CHANGELOG.md Outdated
@@ -1,6 +1,7 @@
## 0.20.0 (TBD)
## 0.20.0 (2025-12-04)
Copy link
Contributor

Choose a reason for hiding this comment

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

We are not planning to release the v0.20.0 version yet - so, I'd keep it as TBD.

The bug fix (that keeps signature length as is) should go into main - and that would probably be a different PR.

Copy link
Collaborator

@Al-Kindi-0 Al-Kindi-0 left a comment

Choose a reason for hiding this comment

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

LGTM
I think the reason for the extra bit was the previous solution where we wanted to accommodate both the Keccak and SHA variants of the signature. We then probably forgot to remove this extra bit when we abandoned that goal.

@bobbinth bobbinth merged commit 1007b3b into next Dec 3, 2025
26 checks passed
@bobbinth bobbinth deleted the sergerad-fix-signature-serde branch December 3, 2025 19:23
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.

Signature does not consume all bytes during deserialization

4 participants