Skip to content

feat: align protocol version reporting with init#778

Merged
Baskarayelu merged 4 commits intoQuickLendX:mainfrom
Marvy247:feature/version-field-consistency
Apr 1, 2026
Merged

feat: align protocol version reporting with init#778
Baskarayelu merged 4 commits intoQuickLendX:mainfrom
Marvy247:feature/version-field-consistency

Conversation

@Marvy247
Copy link
Copy Markdown
Contributor

Summary

Fixes the inconsistency where get_version hardcoded 1u32 instead of reading the version stored during initialization.

Also fixes a pre-existing WASM build failure in verification.rs where std::vec::Vec and std::str::from_utf8 were used in a no_std context.

Changes

  • init.rs — Added PROTOCOL_VERSION constant (= 1) and PROTOCOL_VERSION_KEY storage key. Version is written to instance storage during initialize_internal. Added ProtocolInitializer::get_version() that reads from storage, falling back to the constant before init.
  • lib.rsget_version now delegates to ProtocolInitializer::get_version instead of hardcoding 1u32.
  • test_init.rs — 5 new version-consistency tests covering: before-init fallback, after-init match, direct storage read, before/after consistency, and idempotent re-init stability.
  • docs/contracts/initialization.md — Documented get_version API and upgrade policy (patch/minor/major).
  • verification.rs — Replaced std::vec::Vec/std::str::from_utf8 with a fixed-size stack array and core::str::from_utf8 to fix the wasm32v1-none release build.

Security Notes

  • get_version is read-only — no new attack surface.
  • Version is written atomically as part of the existing initialization flow.
  • Idempotent re-init does not overwrite the stored version.

Testing

  • cargo check --lib — clean (zero new errors)
  • cargo build --target wasm32v1-none --release — now passes

Closes #725

- Add PROTOCOL_VERSION constant (= 1) and PROTOCOL_VERSION_KEY storage
  key to init.rs
- Store PROTOCOL_VERSION in instance storage during initialize_internal
  so get_version always reflects the version active at init time
- Add ProtocolInitializer::get_version() query method that reads from
  storage, falling back to the constant before init
- Update lib.rs get_version to delegate to ProtocolInitializer::get_version
  instead of hardcoding 1u32
- Add 5 version-consistency tests in test_init.rs (before/after init,
  storage read, consistency, idempotent re-init)
- Document get_version API and upgrade policy in
  docs/contracts/initialization.md

Closes QuickLendX#725
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 30, 2026

@Marvy247 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

@Baskarayelu Baskarayelu merged commit fa29d1b into QuickLendX:main Apr 1, 2026
1 check failed
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.

Protocol version consistency between get_version and initialization

2 participants