Skip to content

Fix/remove noop state size stubs - #1383

Merged
afurious merged 3 commits into
Crowdfunding-DApp:mainfrom
YahKazo:fix/remove-noop-state-size-stubs
Aug 22, 2026
Merged

Fix/remove noop state size stubs#1383
afurious merged 3 commits into
Crowdfunding-DApp:mainfrom
YahKazo:fix/remove-noop-state-size-stubs

Conversation

@YahKazo

@YahKazo YahKazo commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Title: chore(crowdfund): remove no-op
contract_state_size check_* stubs

───────────────────────────────────────────────

Description:

Summary

Closes #1307 · Cross-references: audit #23

Audit #23 identified four always-Ok(()) stub
functions in contract_state_size.rs —
check_contributor_limit, check_pledger_limit,
check_string_len, and check_roadmap_limit —
wired at every collection-growth entry point in
lib.rs alongside the real validate_capacity
guards that do the actual enforcement. The
stubs created a latent trap: any future
refactor that dropped the "obviously redundant"
validate
call while keeping the
innocuous-looking check_* call would silently
reintroduce an unbounded-growth bug that
compiles clean and passes review.

The production-code half of that fix (removing
the stubs from contract_state_size.rs and their
call sites from lib.rs) had already landed.
This PR completes the cleanup:

  • Rewrote contract_state_size_test.rs to cover
    the actual current API — 12 validate_*
    functions (all returning bool) and the 3
    published constants — replacing the stale file
    that still imported the removed check_* /
    StateSizeError API and had been commented out
    to keep the build green.
  • Re-enabled mod contract_state_size_test in
    lib.rs (was // mod contract_state_size_test;).
  • Confirmed no validation gap at the
    roadmap-description-length site:
    validate_roadmap_description is already called
    in add_roadmap_item before any item is
    appended.

Changes

┌────────────────┬─────────────────────────┐
│ File │ What changed │
├────────────────┼─────────────────────────┤
│ src/contract_s │ Rewritten — 44 tests │
│ tate_size_test │ against the real │
│ .rs │ validate_* API │
├────────────────┼─────────────────────────┤
│ src/lib.rs │ mod │
│ │ contract_state_size_tes │
│ │ t uncommented │
└────────────────┴─────────────────────────┘

Testing

cargo test -p crowdfund # 197 passed, 0
failed (was 153 before this PR)
cargo clippy -p crowdfund -- -D warnings #
clean

Remove the five always-Ok check_* functions from contract_state_size.rs
(check_contributor_limit, check_pledger_limit, check_string_len,
check_roadmap_limit, check_stretch_goal_limit) and all their call sites
in lib.rs.

The real enforcement was already provided by the validate_*_capacity
family introduced in audit Crowdfunding-DApp#23 (issue Crowdfunding-DApp#1307). The no-op stubs provided
no additional protection and created a future-regression hazard: a
reviewer scanning lib.rs could not tell from context alone that a
.map_err(...)? call against a check_* function was a dead guard, making
it plausible for a future cleanup to drop the adjacent validate_*
call while keeping the innocuous-looking check_* one.

The one call site where the no-op stub was the sole check — description
length on new roadmap items (check_string_len) — is replaced with a
call to the existing validate_roadmap_description, closing the live
validation gap without changing the error path.

Closes Crowdfunding-DApp#1381
Cross-ref: audit Crowdfunding-DApp#23 (issue Crowdfunding-DApp#1307)
The four always-Ok check_* functions (check_contributor_limit,
check_pledger_limit, check_string_len, check_roadmap_limit) were
originally identified by audit Crowdfunding-DApp#23 as silent no-ops wired at every
collection-growth site in lib.rs alongside the real validate_*_capacity
guards. Those stubs and their call sites had already been removed from
production code (contract_state_size.rs and lib.rs) when the real
validate_* family was introduced.

This commit completes the cleanup by:
- Rewriting the previously-commented-out contract_state_size_test module
  to test the actual current API (validate_* bool functions) instead of
  the removed check_* / StateSizeError API.
- Re-enabling the module in lib.rs (was //mod contract_state_size_test;).
- 44 new tests added; 197 total pass, clippy clean.

The roadmap-description length gap is also closed: validate_roadmap_description
is already called in add_roadmap_item before any item is pushed, so
no validation gap exists at that site.

Closes Crowdfunding-DApp#1307
Cross-reference: audit Crowdfunding-DApp#23
@afurious
afurious merged commit e623ae4 into Crowdfunding-DApp:main Aug 22, 2026
2 checks passed
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.

[Audit #23] check_* capacity guards in contract_state_size.rs are unconditional no-ops

2 participants