Skip to content

Validate the threshold in set_weight_threshold with the same bounds validate_migration enforces #306

Description

@N-thnI

Description

Stop the live setter from writing a threshold the migration pre-flight is designed to reject.

Problem Statement

set_weight_threshold writes the caller's value straight to storage with no range check (src/contracts/proxy_entry/entry_config.rs:17-30):

crate::contracts::rbac::require_role(&env, &admin, crate::types::Role::ConfigManager)?;
env.storage().instance().set(&DataKey::WeightThreshold, &threshold);

validate_weight_threshold (src/validation.rs:84-92, rejecting 0 and > MAX_WEIGHT_THRESHOLD) exists and is invoked — but only by migrate::validate_migration at src/migrate.rs:169. So the live setter can write exactly the state the migration pre-flight rejects.

Verified: try_set_weight_threshold(&admin, &0) returns Ok(()) and get_weight_threshold() returns 0. A zero threshold makes consensus::apply_vote's total_weight_accrued >= threshold (src/consensus.rs:103) trivially true, so every task resolves on its first qualifying vote, silently defeating weighted consensus. It also poisons any future v1 → v2 migration: validate_migration would abort with InvalidAmount, leaving the contract unmigratable until the threshold is manually reset.

Proposed Changes

  • Call crate::validation::validate_weight_threshold(threshold)? in set_weight_threshold before the storage write
  • Remove the now-inaccurate #[allow(dead_code)] on MAX_WEIGHT_THRESHOLD (src/limits.rs:50)
  • Document InvalidAmount / InvalidRange in the entrypoint's error list, matching the style used on set_vault_address

Technical Implementation Scaffolding

  • Target Repository: vero-core-contracts
  • Target Path: src/contracts/proxy_entry/entry_config.rs, src/validation.rs
  • Branch Naming: fix/issue--validate-weight-threshold-setter
  • Authority Context: Security-sensitive — consensus threshold; zero disables weighted voting

Acceptance Criteria

  • try_set_weight_threshold(admin, 0) returns Err(ContractError::InvalidAmount) and get_weight_threshold() is unchanged
  • try_set_weight_threshold(admin, MAX_WEIGHT_THRESHOLD + 1) returns Err(ContractError::InvalidRange)
  • Any threshold reachable via set_weight_threshold is accepted by migrate::validate_migration (property test over the accepted range)

Definition of Done

  • Reviewed by lead maintainer
  • Pull request merged via verified status check

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third Campaign

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions