Skip to content

fix(market): guard execute_fee_rate_change with require_initialized - #649

Open
Akeem813 wants to merge 1 commit into
Vatix-Protocol:devfrom
Akeem813:fix/issue-496-timelock-require-initialized
Open

fix(market): guard execute_fee_rate_change with require_initialized#649
Akeem813 wants to merge 1 commit into
Vatix-Protocol:devfrom
Akeem813:fix/issue-496-timelock-require-initialized

Conversation

@Akeem813

Copy link
Copy Markdown
Contributor

Problem

execute_fee_rate_change was the only state-mutating contract entry point that did not call validation::require_initialized before operating on persistent storage.

Every other mutating function (set_fee_rate, set_fee_cap, set_treasury, cancel_market, update_position, etc.) begins with require_initialized so callers on an uninitialized contract receive ContractError::NotInitialized rather than silently reading or writing orphaned storage entries.

Without the guard a caller could write FeeRateBps storage via execute_fee_rate_change before the contract admin is set — producing a partially-configured contract state inconsistent with the initialization invariant documented throughout the codebase.

What Changed

execute_fee_rate_change now opens with:

validation::require_initialized(&env)?;

This is the same guard used by every other mutating function. The existing timelock check (timestamp < effective_at → TimelockNotElapsed) is unchanged.

Files Changed

  • contracts/market/src/lib.rs — add require_initialized as the first check in execute_fee_rate_change

Acceptance Criteria

  • Early execute (before effective_at) fails with TimelockNotElapsed — existing check, unchanged
  • Execute on uninitialized contract fails with NotInitialized — new guard
  • Ready execute (after effective_at on initialized contract) updates FeeRateBps — existing behavior, unchanged

execute_fee_rate_change was the only state-mutating contract entry point
that did not call validation::require_initialized before operating on
persistent storage.

Every other mutating function (set_fee_rate, set_fee_cap, set_treasury,
cancel_market, update_position, etc.) begins with require_initialized so
that callers on an uninitialized contract receive ContractError::NotInitialized
rather than silently reading or writing orphaned storage entries.

Without the guard a caller could, in theory, write FeeRateBps storage via
execute_fee_rate_change before the contract admin is set — producing a
partially-configured contract state that is hard to reason about and
inconsistent with the initialization invariant documented throughout the
codebase.

The timelock check itself (timestamp < effective_at → TimelockNotElapsed)
is already correct and unchanged; this commit adds the missing initialization
gate as the very first check in the function.

Fixes: Vatix-Protocol#496
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.

1 participant