fix(governance): reject set_execution_delay before initialize - #613
Open
KorexOnchain wants to merge 1 commit into
Open
Conversation
…e-Liquidity-Network#603) set_execution_delay had a fallback branch that silently set StorageKey::Admin to the caller if it was not yet initialized: } else { env.storage().instance().set(&StorageKey::Admin, &admin); } If initialize() was never called (or there was a race during deployment), any caller could invoke set_execution_delay and become the governance admin -- gaining veto power and proposal execution rights. Privilege escalation. Fix: - Added GovernanceError::NotInitialized (21). - Removed the else branch entirely. set_execution_delay now uses .ok_or(GovernanceError::NotInitialized)? to fetch the stored admin, returning NotInitialized if it is unset, and Unauthorized if the caller does not match. initialize() remains the only code path that writes StorageKey::Admin. Tests added (contracts/iln_governance/src/test.rs): - test_set_execution_delay_before_initialize_rejected: calling on an uninitialized contract panics (NotInitialized) instead of silently granting admin to the caller. - test_set_execution_delay_wrong_admin_rejected: calling with an address that is not the configured admin panics (Unauthorized). - test_set_execution_delay_correct_admin_succeeds: the legitimate admin path still works correctly (regression guard against an overly broad fix). Verified: - cargo test -p iln_governance: 100 passed, 1 failed. The 1 failure (test_vote_receipt_available_within_ttl) is pre-existing and unrelated -- confirmed identical failure on unmodified main via git stash before making any changes here. - cargo fmt -p iln_governance -- --check: no diff. - cargo clippy -p iln_governance --all-targets -- -D warnings: clean. Closes Invoice-Liquidity-Network#603
|
@KorexOnchain 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! 🚀 |
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #603
The bug
set_execution_delayincontracts/iln_governance/src/lib.rshad a fallback branch that silently setStorageKey::Adminto the caller if it was not yet initialized:If
initialize()was never called (or there was a race during deployment), any caller could invokeset_execution_delayand become the governance admin — gaining veto power and proposal execution rights.The fix
GovernanceError::NotInitialized(variant 21).elsebranch entirely.set_execution_delaynow uses.ok_or(GovernanceError::NotInitialized)?to fetch the stored admin, returningNotInitializedif it's unset, andUnauthorizedif the caller doesn't match.initialize()remains the only code path that writesStorageKey::Admin.Tests added
test_set_execution_delay_before_initialize_rejected— calling on an uninitialized contract panics withNotInitializedinstead of silently granting admin to the caller.test_set_execution_delay_wrong_admin_rejected— calling with an address that isn't the configured admin panics withUnauthorized.test_set_execution_delay_correct_admin_succeeds— the legitimate admin path still works correctly (regression guard against an overly broad fix).Verification
cargo test -p iln_governance: 100 passed, 1 failed. The 1 failure (test_vote_receipt_available_within_ttl) is pre-existing and unrelated — confirmed viagit stashthat it fails identically on unmodifiedmainbefore any of these changes.cargo fmt -p iln_governance -- --check: no diff.cargo clippy -p iln_governance --all-targets -- -D warnings: clean.