Skip to content

feat(sbt): add credential metadata compression (closes #26) - #219

Merged
maugauwi-hash merged 2 commits into
ethos-protocol:mainfrom
Emmanard:feature/issue-26-metadata-compression
Jul 30, 2026
Merged

feat(sbt): add credential metadata compression (closes #26)#219
maugauwi-hash merged 2 commits into
ethos-protocol:mainfrom
Emmanard:feature/issue-26-metadata-compression

Conversation

@Emmanard

Copy link
Copy Markdown
Contributor

Summary

Adds storage-efficient credential metadata compression using a MessagePack extension envelope. The implementation replaces the ineffective legacy encoder while preserving compatibility with raw and previously compressed metadata.

Changes

  • contracts/sbt/src/compression.rs

    • Implements MessagePack Ext8 and Ext16 framing.
    • Adds direct and delta PackBits-style encoding modes.
    • Selects the smaller candidate and avoids storing larger encodings.
    • Supports raw metadata and the legacy 0xC1 format during decompression.
    • Validates malformed payloads and decompressed-size limits.
  • contracts/sbt/src/lib.rs

    • Adds compress_metadata(env, metadata: Bytes) -> Bytes.
    • Adds backwards-compatible decompress_metadata.
    • Repairs in-place compression for String-backed SBT metadata.
    • Preserves the existing mint and String metadata APIs.
    • Automatically decompresses compressed metadata during reads.
  • contracts/sbt/src/compression_tests.rs

    • Adds focused coverage for Ext8, Ext16, round trips, raw and legacy compatibility, malformed data, empty input, in-place storage, and incompressible metadata.
    • Adds a storage-savings benchmark assertion.
  • docs/sbt-advanced-features.md

    • Documents the byte-level MessagePack format, compatibility behavior, APIs, and measured storage savings.

Approach

  • Used a standards-compatible MessagePack extension envelope with a versioned custom payload.
  • Compared direct and delta encodings and retained only genuinely smaller results.
  • Preserved legacy and uncompressed metadata reads.
  • Followed the existing opt-in SBT compression model.
  • Introduced zero new libraries.

Testing

  • Added ten focused Soroban unit tests.
  • Added a benchmark assertion showing 64 repeated bytes compressed to 7 bytes, saving 57 bytes (89.06%).
  • git diff --check passed.
  • Cargo formatting and tests were not executed because the repository safety rules prohibit Rust tooling and builds.

Closes #26

@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@Emmanard Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@maugauwi-hash
maugauwi-hash merged commit b64845e into ethos-protocol:main Jul 30, 2026
1 of 4 checks passed
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.

Add Credential Metadata Compression

2 participants