Skip to content

fix(daokit/daocond/basedao): v5 audit + Red/Blue + expert + CTO findings - #62

Closed
zxxma wants to merge 5 commits into
mainfrom
fix/security-audit-v5-realm-fixes
Closed

zxxma wants to merge 5 commits into
mainfrom
fix/security-audit-v5-realm-fixes

Conversation

@zxxma

@zxxma zxxma commented May 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Consolidated security, governance, and code-hygiene work on gnodaokit primitives (basedao, daocond, daokit), spanning four review tracks:

  • Mainnet audit prep — critical correctness + safety
  • Gno expert panel — openCount desync + perf cleanup
  • Red Team + Blue Team — H-6 minority takeover, M-10 execute leak, R17 supermajority
  • CTO follow-up — remove math.Max from orCond.Signal to drop the math import surface

10 files, +283 / -48.

Note on framing (post @n0izn0iz review, thread)

The float64 → bps change in d5ab78e was originally framed as "consensus safety across VM implementations." That framing was overstated — gno's float64 is deterministic, and there's no structural Eval/Signal split (everything in the VM is consensus when invoked from a tx; the display-only nature of Signal() is conventional, not structural). The change is retained as code hygiene (removes the math import; integer-only Eval is cleaner) rather than a consensus-safety fix. The d5ab78e commit message is left as-is in history; this PR description and the comment thread are the corrected record.

Critical fixes

  • Infinite recursion in crossingDAO.Render() — was calling c.Render instead of c.dao.Render (06f76e5).
  • Threshold denominator snapshot (H-6, prevents minority takeover) (45f9c65): new Snapshottable interface in daocond; MembersThresholdCond.Snapshot() and RoleThresholdCond.Snapshot() freeze counter fns at proposal creation; AndCond / OrCond propagate; ProposalsStore.newProposal calls Snapshot when supported. Prevents membership-shifting between vote and execution to retroactively change pass/fail.
  • Execute openCount leak via handler panic (M-10) (45f9c65): refactored Core.Execute to set Status = Executed BEFORE the handler call (re-entrancy gate). If the handler panics, the whole tx reverts including the status change (Gno atomicity). Prevents permanent slot leak on faulty action handlers.

Governance hardening

  • Proposal expiry (7776384): ProposalTTLBlocks (~30 days) + ProposalStatusExpired. UpdateStatus, Vote, Execute all honour expiry. Expired proposals reject votes.
  • MaxOpenProposals = 50 spam limit (7776384): openCount tracking with decrement on execute/expire.
  • Min-member guard (7776384): RemoveMember panics if only 1 member remains. Prevents permanent DAO bricking.
  • Constitutional supermajority (R17) (45f9c65): new Config.SupermajorityCondition (default MembersThreshold(0.75)). ChangeDAOImplementation and RemoveMember now require supermajority (was 60%). Other actions keep InitialCondition (60%).

Safety nets + code hygiene

  • Division-by-zero guards in cond_members_threshold and cond_role_treshold when count = 0 (06f76e5).
  • Format-string arity fix in cond_role_treshold.RenderWithVotes — was passing 2 args for 3 verbs, runtime panic (06f76e5).
  • openCount desync fix (d5ab78e): GetProposals/GetProposalsJSON decrement on expiry transitions; new UpdateProposalStatus store helper; new public CleanExpired() for batch cleanup; Vote path uses UpdateProposalStatus (auto-decrements).
  • CountMembersWithRole: O(n) → O(1) via roleData.Members.Size() (was allocating full slice just to call len()) (d5ab78e).
  • Integer-only Eval in cond_members_threshold + cond_role_treshold (d5ab78e): thresholdBps (uint64), yes*10000 >= thresholdBps*total (was float64 division + comparison). Constructor still accepts float64 0.0–1.0 for API compat, converts to bps at construction time. Code hygiene per @n0izn0iz — see framing note above.
  • CTO follow-up: remove math.Max from orCond.Signal — explicit comparison instead. Drops the math import (c599cb7).

Files

  • gno/p/basedao/basedao.gno
  • gno/p/basedao/members.gno
  • gno/p/daocond/cond_and.gno
  • gno/p/daocond/cond_members_threshold.gno
  • gno/p/daocond/cond_or.gno
  • gno/p/daocond/cond_role_treshold.gno
  • gno/p/daocond/daocond.gno
  • gno/p/daokit/crossing.gno
  • gno/p/daokit/daokit.gno
  • gno/p/daokit/proposals.gno

Test plan

  • CI green on `gno test ./gno/p/...` (currently red on unrelated toolchain rot — see CI note below)
  • Snapshot behaviour — add member after proposal creation, verify vote uses snapshotted counter (not current)
  • Expiry — create proposal, advance past `ProposalTTLBlocks`, attempt vote → reject
  • Supermajority — `ChangeDAOImplementation` requires 75%
  • Supermajority — `RemoveMember` requires 75%
  • Min-member guard — `RemoveMember` panics on last member
  • MaxOpenProposals — 51st open proposal rejected
  • Execute panic — handler panic does NOT leak `openCount` slot
  • Reviewer ≠ author confirmed

CI note (unrelated toolchain rot)

CI is currently red on gno-lint + gno-test for an issue that affects ALL gnodaokit branches right now, not this one specifically. The Makefile pins GNOVERSION=4e80c37e8d18 (gno @ 2025-09-29), which can no longer unmarshal current upstream package-server responses (amino: unrecognized concrete type full name vm.InvalidPackageError). Last green run on main was 2025-11-12; no main commits since, so the rot wasn't noticed.

A separate chore/ci-bump-gno-toolchain PR is in flight on gnodaokit to bump the pin to 96264d21d (v1.1.0 / gnoland1.1 release commit, 2026-04-01). Once that merges, this PR will be rebased to inherit green CI.

Notes

  • Marked Draft: holding for secondary reviewer assignment per Memba v7.1 Phase 1 Q-A protocol. Commits authored by @zxxma → reviewer must be ≠ author.
  • After merge, tag a release per repo convention.

zxxma added 5 commits April 9, 2026 23:06
- crossing.gno: Fix infinite recursion in crossingDAO.Render()
  (was calling c.Render instead of c.dao.Render)
- cond_members_threshold.gno: Division-by-zero guard when membersCount=0
- cond_role_treshold.gno: Division-by-zero guard when role count=0
- cond_role_treshold.gno: Fix RenderWithVotes format string arity mismatch
  (was passing 2 args for 3 format verbs, causing runtime panic)
…it, member guard

daokit/proposals:
- Proposal expiration: ProposalTTLBlocks (~30 days), ProposalStatusExpired
- UpdateStatus now checks expiry before evaluating conditions
- MaxOpenProposals = 50 spam limit (prevents unbounded proposal creation)
- openCount tracking with decrementOpen on execution/expiry

daokit/daokit:
- Vote now checks expiry before allowing vote (expired proposals reject votes)
- Execute decrements open count after successful execution

basedao/members:
- Minimum member guard: RemoveMember panics if only 1 member remains
  (prevents permanent DAO bricking by removing all members)
…governance hardening

CRITICAL — Float64 → integer basis points in daocond (consensus safety):
- cond_members_threshold: thresholdBps (uint64), Eval uses integer math
  yes*10000 >= thresholdBps*total (was float64 division + comparison)
- cond_role_treshold: same pattern with uint64 casts for safety
- Float64 was technically deterministic under Go spec but a latent
  mainnet consensus risk across VM implementations
- Signal() still returns float64 (display-only, not consensus-critical)
- Threshold constructor still accepts float64 0.0-1.0 for API compat,
  converts to bps at construction time

daokit/proposals — openCount desync fix:
- GetProposals/GetProposalsJSON now decrement openCount on expiry transitions
- New UpdateProposalStatus store helper keeps openCount in sync
- New CleanExpired() public function for batch cleanup
- Vote path uses UpdateProposalStatus (auto-decrements)
- Prevents DoS via MaxOpenProposals slot leakage

basedao/members — O(n) → O(1) optimization:
- CountMembersWithRole now uses roleData.Members.Size() directly
- Previously allocated full slice just to call len()
CRITICAL fixes:

H-6 — Threshold denominator snapshot (prevents minority takeover):
- New Snapshottable interface in daocond
- MembersThresholdCond.Snapshot() freezes membersCountFn at proposal creation
- RoleThresholdCond.Snapshot() freezes usersRoleCountFn at proposal creation
- AndCond and OrCond propagate Snapshot() to children
- ProposalsStore.newProposal calls Snapshot() if condition supports it
- Prevents attacks where members are added/removed between vote and execution
  to retroactively change whether a proposal passes

M-10 — Execute openCount leak via handler panic:
- Refactored Core.Execute to use UpdateProposalStatus (single decrement path)
- Set Status = Executed BEFORE handler call (re-entrancy gate)
- If handler panics, entire tx reverts including the status change (Gno atomic)
- Prevents permanent slot leak on faulty action handlers

R17 — Constitutional supermajority:
- New Config.SupermajorityCondition (default: MembersThreshold(0.75))
- ChangeDAOImplementation now requires supermajority (was 60%)
- RemoveMember now requires supermajority (was 60%)
- Other actions (AddMember, AssignRole, etc.) keep InitialCondition (60%)
Replace math.Max with explicit comparison to reduce float64 surface area
in daocond. Signal is display-only (Eval is the consensus path) but
removing the math import keeps the package free of float operations
beyond the display-only Signal returns.

Addresses CTO-1 P1 finding.
@n0izn0iz

Copy link
Copy Markdown
Contributor

gno's float64 is deterministic, there is no such thing as "consensus path" and "not consensus path" since everything is run in the vm consensus

@zxxma

zxxma commented May 11, 2026

Copy link
Copy Markdown
Collaborator Author

Fair correction, thanks — agreed:

  1. gno float64 is deterministic (single reference VM, no client diversity). The "consensus risk across VM implementations" framing in d5ab78e was hypothetical and overstated — that risk only materializes if alternative gno VM implementations ever ship, which isn't on the table.
  2. You're right that Signal() also runs in the VM. The display-only framing is operationally true only because the current callers are Render() / RenderWithVotes() — both invoked as ABCI queries (per-node, not consensus replay). It's a convention, not a structural guarantee, and the commit message shouldn't have implied otherwise.

I'll keep the bps change in cond_members_threshold + cond_role_treshold because it removes the math import surface and integer-only Eval is cleaner — but reframing it as code hygiene, not consensus safety. PR description updated to reflect that. Leaving d5ab78e commit message as-is in history; the conversation + description make the correction discoverable.

The other commits stand on their own merits independently of this discussion:

  • c599cb7 (math.Max removal — same code-hygiene angle as above)
  • 06f76e5 (real bugs: infinite recursion in crossingDAO.Render, div-by-zero in both threshold conds, format-string arity panic in RoleThreshold.RenderWithVotes)
  • 7776384 (proposal expiry, MaxOpenProposals = 50 spam limit, min-member guard)
  • 45f9c65 (H-6 threshold Snapshot to prevent post-creation membership shifts, M-10 openCount leak on handler panic, R17 supermajority for ChangeDAOImplementation + RemoveMember)

Heads-up that CI is currently red here for an unrelated reason: the Makefile pins gno@4e80c37e (2025-09-29) which can no longer unmarshal current upstream package-server responses (vm.InvalidPackageError). I'll open a separate small chore/ci-bump-gno-toolchain PR to bump the pin to 96264d21d (v1.1.0 / gnoland1.1 release commit) and rebase this PR on top once that lands.

@zxxma

zxxma commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded — its findings landed, by a different route.

The two that mattered were harvested and shipped in #67: the ufmt arity panic in cond_role_treshold.gno (a guaranteed panic on every render for any DAO with a RoleThreshold), and the missing minimum-member guard on RemoveMember. Both were reproduced with failing tests first, and the min-member guard turned out to need fixing at the condition layer rather than in RemoveMember — voteRatio divides by the electorate size, so at zero members the result is NaN, reachable while MembersCount() >= 2 and so past any <= 1 guard.

Its headline finding — infinite recursion in crossingDAO.Render — is moot: the interrealm-v2 port deleted crossing.gno.

Closing rather than merging because its own CI ran and failed, and the remaining 283 lines are unreviewed against a codebase that has since moved through the whole freeze stack.

@zxxma zxxma closed this Jul 20, 2026
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.

2 participants