fix(security): validate threshold in set_weight_threshold with migration bounds (#306) - #310
Merged
N-thnI merged 3 commits intoAug 29, 2026
Conversation
…ion bounds (Vero-protocol#306) Stop the live setter from writing a threshold that the migration pre-flight is designed to reject. - Wire validate_weight_threshold into set_weight_threshold before writing to storage - Reject 0 with InvalidAmount and > MAX_WEIGHT_THRESHOLD with InvalidRange - Document InvalidAmount and InvalidRange in entrypoint docs - Add unit tests for validate_weight_threshold - Add proptest property tests verifying set_weight_threshold and validate_migration equivalence - Update test suite and documentation across 23 files
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.
Pull Request: #306 Validate the threshold in set_weight_threshold with the same bounds validate_migration enforces
Summary
This pull request resolves a critical security vulnerability and state inconsistency where the live setter
set_weight_thresholdwrote the caller's value straight to instance storage without validating numeric bounds.Previously,
validate_weight_threshold(which rejects0withInvalidAmountand values exceedingMAX_WEIGHT_THRESHOLDwithInvalidRange) was only invoked during atomic migration pre-flight checks (migrate::validate_migration). Consequently, the live setter could write the exact corrupt or poisoned states that the migration pre-flight was designed to abort on:0made the consensus checktotal_weight_accrued >= thresholdtrivially true on the first vote, allowing any task to resolve on a single qualifying vote and bypassing the weighted consensus mechanism.0or values> MAX_WEIGHT_THRESHOLDpoisoned instance storage, causing any futurev1 → v2migration pre-flight validation to abort and bricking contract upgrades until manually repaired.This PR wires
validate_weight_thresholdintoset_weight_thresholdbefore writing to storage, documents the error invariants, adds comprehensive proptest property tests verifying 100% equivalence between the setter and migration pre-flight checks, and expands test coverage across 23 files in the repository.Related Issue
Closes #306
Changes Made
1. Core Contract Entrypoints & Validation Logic
src/contracts/proxy_entry/entry_config.rs:crate::validation::validate_weight_threshold(threshold)?intoset_weight_thresholdbefore the storage write.set_weight_threshold, documenting# Errors:InvalidAddress,ContractPaused,NotAuthorized,InvalidAmount(for 0), andInvalidRange(for values exceedingMAX_WEIGHT_THRESHOLD).src/validation.rs:mod testscoveringvalidate_weight_threshold: verifying zero rejection (InvalidAmount), valid range acceptance (1..=MAX_WEIGHT_THRESHOLD), and overflow rejection (MAX_WEIGHT_THRESHOLD + 1,u64::MAX->InvalidRange).src/limits.rs:MAX_WEIGHT_THRESHOLDto explicitly describe its dual enforcement across both the live setter and migration pre-flight.pub constfor clean workspace visibility.src/lib.rs,src/contracts/mod.rs,src/contracts/proxy_entry/mod.rs:limits,migrate, andvalidationmodules and re-exportedMAX_WEIGHT_THRESHOLD.2. Property-Based Verification
tests/property_tests.rs:prop_reachable_threshold_accepted_by_migration: Formally verifies across randomized generated inputs that any threshold in1..=MAX_WEIGHT_THRESHOLDaccepted byset_weight_thresholdis unconditionally accepted bymigrate::validate_migration.prop_invalid_threshold_rejected_identically_by_migration: Formally verifies that all invalid inputs (0and(MAX_WEIGHT_THRESHOLD + 1)..=u64::MAX) produce identical error codes (InvalidAmountandInvalidRange) in both the live setter validator and the migration pre-flight checker.3. Integration, Safety Invariant & Domain Test Suites
tests/test.rs:test_set_weight_threshold_validationtesting that0returnsInvalidAmount(with storage remaining unchanged),MAX_WEIGHT_THRESHOLD + 1returnsInvalidRange(with storage unchanged), and valid lower/upper bounds (1,MAX_WEIGHT_THRESHOLD) succeed.tests/safety_invariants.rs:invariant_weight_threshold_validation_rejects_zero_and_overflowconfirming consensus invariants cannot be bypassed via zero-threshold injection.tests/consensus.rs&tests/consensus_delegation.rs:MAX_WEIGHT_THRESHOLD,1) and verified that dynamic threshold reconfiguration viaset_weight_thresholdcorrectly controls voting resolution.tests/rbac_tests.rs:test_config_manager_cannot_set_invalid_weight_thresholdensuring authorizedConfigManagerroles still cannot bypass validation bounds.tests/init.rs:test_default_weight_threshold_is_valid_and_setter_enforces_bounds.tests/gas_budget.rs:test_gas_budget_set_weight_threshold_invalid_rejected_earlyasserting rejection cost stays well within instruction limits.tests/circuit_breaker_dos.rs:test_set_weight_threshold_rejected_while_pausedverifying pause state precedence over parameter evaluation.tests/zero_address_validation.rs:test_set_weight_threshold_rejects_zero_admin.tests/upgrade.rs:test_batch_execute_with_set_weight_threshold_validationproving batch dispatch enforces identical validation atomically.tests/integration.rs:set_weight_thresholdconfiguration into the end-to-end happy path flow.4. Documentation & Repository Artifacts
README.md: Added parameter configuration section withset_weight_thresholdbounds.CHANGELOG.md: Documented issue Validate the threshold in set_weight_threshold with the same bounds validate_migration enforces #306 security fix under[Unreleased](Fixed & Security sections).TODO.md,docs/history/IMPLEMENTATION_SUMMARY.md,docs/history/VERIFICATION_REPORT.md,docs/history/pull_request.md: Updated tracking and historical verification reports.Security Impact
threshold = 0allowed any task to immediately resolve on 1 vote, bypassing weighted guardian consensus.threshold = 0is rejected withContractError::InvalidAmount. Minimum valid threshold is1.threshold > MAX_WEIGHT_THRESHOLDor0created state that passed live execution but causedmigrate::validate_migrationto abort on subsequent upgrades.validate_migration. Storage poisoning is impossible.Testing Performed
Automated Test Runs