Skip to content

Conversation

@0xLeif
Copy link
Contributor

@0xLeif 0xLeif commented Nov 29, 2025

The mnemonic encoding/decoding was using big-endian bit packing instead of the little-endian bit packing required by the Algorand SDK spec.

Changes:

  • Rewrite encode() to use little-endian bit packing via toElevenBit()
  • Rewrite decode() to use little-endian bit unpacking via fromElevenBit()
  • Add cross-SDK compatibility tests with verified test vectors

The fix ensures mnemonics generated by swift-algorand are now accepted by py-algorand-sdk and other official Algorand SDKs.

@0xLeif 0xLeif requested a review from Copilot November 29, 2025 20:19
The mnemonic encoding/decoding was using big-endian bit packing instead
of the little-endian bit packing required by the Algorand SDK spec.

Changes:
- Rewrite encode() to use little-endian bit packing via toElevenBit()
- Rewrite decode() to use little-endian bit unpacking via fromElevenBit()
- Add cross-SDK compatibility tests with verified test vectors

The fix ensures mnemonics generated by swift-algorand are now accepted
by py-algorand-sdk and other official Algorand SDKs.
@0xLeif 0xLeif force-pushed the fix/mnemonic-checksum branch from b5e0f36 to 47c573a Compare November 29, 2025 20:19
Copilot finished reviewing on behalf of 0xLeif November 29, 2025 20:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical compatibility issue in mnemonic encoding/decoding by switching from big-endian to little-endian bit packing, ensuring the swift-algorand SDK generates mnemonics compatible with py-algorand-sdk and other official Algorand SDKs.

  • Rewrites encode() and decode() methods to use little-endian bit packing via new helper functions toElevenBit() and fromElevenBit()
  • Adds comprehensive cross-SDK compatibility tests with verified test vectors from py-algorand-sdk
  • Adds robustness testing with multiple generated mnemonics

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
Sources/Algorand/Mnemonic.swift Replaces big-endian string-based bit manipulation with little-endian buffer-based bit packing/unpacking for proper cross-SDK compatibility
Tests/AlgorandTests/MnemonicTests.swift Adds test vectors verified against py-algorand-sdk and multiple-generation round-trip tests to ensure compatibility and correctness

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +38 to +40
// Test with tampered padding (last word should encode to zeros in padding bits)
var words = validMnemonic.components(separatedBy: " ")
words[24] = "ability" // "ability" = index 1, encodes to non-zero
words[24] = "ability" // "ability" = index 1, encodes to non-zero in padding bits
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

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

The comment is misleading. With the new little-endian implementation, the last word (word 24) is the checksum, not padding. The test is actually checking that modifying the checksum word to "ability" (index 1) will fail validation because it won't match the computed checksum. Consider updating the comment to: // Test with tampered checksum (last word should match computed checksum)

Copilot uses AI. Check for mistakes.
@0xLeif 0xLeif merged commit c3ca935 into main Nov 29, 2025
2 checks passed
@0xLeif 0xLeif deleted the fix/mnemonic-checksum branch November 29, 2025 20:25
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