Skip to content

Fix/issue 32 wasm hash type#308

Merged
hman38705 merged 2 commits intosolutions-plug:mainfrom
Fidelis900:fix/issue-32-wasm-hash-type
Mar 27, 2026
Merged

Fix/issue 32 wasm hash type#308
hman38705 merged 2 commits intosolutions-plug:mainfrom
Fidelis900:fix/issue-32-wasm-hash-type

Conversation

@Fidelis900
Copy link
Copy Markdown
Contributor

Title: fix: use BytesN<32> for WASM hash in PendingUpgrade struct

Body:

Summary

Fixes #32 — Resolve WASM Hash Type Mismatch in Governance

PendingUpgrade.wasm_hash was already typed as BytesN<32> in types.rs, but the governance module's internal helpers (
require_no_upgrade_collision, get/set/clear_upgrade_rejected_at) and ConfigKey::UpgradeRejectedAt still used String.
This caused a type mismatch that would fail at the host upgrade call site since
e.deployer().update_current_contract_wasm() requires BytesN<32>.

Changes

  • types.rs: Changed ConfigKey::UpgradeRejectedAt(String) → ConfigKey::UpgradeRejectedAt(BytesN<32>)
  • governance.rs:
    • Updated require_no_upgrade_collision, get_upgrade_rejected_at, set_upgrade_rejected_at, clear_upgrade_rejected_at
      to accept &BytesN<32> instead of &String
    • Removed the wasm_hash.is_empty() guard — BytesN<32> is always exactly 32 bytes, so this check never fires and
      doesn't compile
  • test.rs: Updated 6 test cases that passed String::from_str hashes to use BytesN::from_array with distinct byte
    patterns

Why this matters

The Soroban host's update_current_contract_wasm function requires a BytesN<32> argument. Storing the hash as String in
the cooldown/rejection tracking keys meant the type flowing through the upgrade lifecycle was inconsistent, and would
panic or fail to compile when the stored value was retrieved and passed to the host function.
closes #140

- Add e.deployer().require_auth() as the first check in initialize()
- Prevents front-running attacks where an attacker monitors deployment
  and races to call initialize() with their own admin address
- Only the deployer's signed transaction can pass the auth check
- Add test_initialize_rejects_non_deployer to verify enforcement

Closes solutions-plug#28
- Change ConfigKey::UpgradeRejectedAt payload from String to BytesN<32>
- Update require_no_upgrade_collision, get/set/clear_upgrade_rejected_at
  helpers to accept &BytesN<32> instead of &String
- Remove wasm_hash.is_empty() guard (BytesN<32> is always 32 bytes)
- Update 6 test usages from String::from_str hashes to BytesN::from_array

PendingUpgrade.wasm_hash was already BytesN<32> in types.rs; this fixes
the remaining String references in governance.rs that caused a type
mismatch at the host upgrade call site.

Closes solutions-plug#32
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Mar 27, 2026

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

@hman38705 hman38705 merged commit f391c98 into solutions-plug:main Mar 27, 2026
2 of 13 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.

Resolve WASM Hash Type Mismatch in Governance

2 participants