Skip to content

fix(governance): reject set_execution_delay before initialize - #613

Open
KorexOnchain wants to merge 1 commit into
Invoice-Liquidity-Network:mainfrom
KorexOnchain:fix/set-execution-delay-privilege-escalation
Open

fix(governance): reject set_execution_delay before initialize#613
KorexOnchain wants to merge 1 commit into
Invoice-Liquidity-Network:mainfrom
KorexOnchain:fix/set-execution-delay-privilege-escalation

Conversation

@KorexOnchain

Copy link
Copy Markdown
Contributor

Closes #603

The bug

set_execution_delay in contracts/iln_governance/src/lib.rs 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.

The fix

  • Added GovernanceError::NotInitialized (variant 21).
  • Removed the else branch entirely. set_execution_delay now uses .ok_or(GovernanceError::NotInitialized)? to fetch the stored admin, returning NotInitialized if it's unset, and Unauthorized if the caller doesn't match. initialize() remains the only code path that writes StorageKey::Admin.

Tests added

  • test_set_execution_delay_before_initialize_rejected — calling on an uninitialized contract panics with NotInitialized instead 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 with Unauthorized.
  • 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 via git stash that it fails identically on unmodified main before any of these changes.
  • cargo fmt -p iln_governance -- --check: no diff.
  • cargo clippy -p iln_governance --all-targets -- -D warnings: clean.

…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
@drips-wave

drips-wave Bot commented Jul 27, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

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.

Fix set_execution_delay privilege escalation on uninitialized contract

1 participant