Skip to content

fix(daocond,basedao): a guaranteed render panic, a permanent DAO brick, and NaN escaping the threshold conditions - #67

Merged
zxxma merged 4 commits into
feat/topaz-v2-renamefrom
fix/pre-freeze-safety-hardening
Jul 20, 2026
Merged

zxxma merged 4 commits into
feat/topaz-v2-renamefrom
fix/pre-freeze-safety-hardening

Conversation

@zxxma

@zxxma zxxma commented Jul 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Three defects that become permanent the moment we publish to topaz-1. All three are in exported public API, all three were reproduced by a failing test before being fixed, and none is covered by the existing suite.

Based on feat/topaz-v2-rename (#65) rather than main, because that is the source the ceremony publishes and because main is pre-interrealm-v2 — its unsuffixed p/nt/* imports cannot resolve on topaz-1 at all. Each fix is independent of the others.

1. RoleThreshold proposals panic instead of rendering

cond_role_treshold.gno:59 consumed three format verbs (%g, %s, %s) while passing two arguments. gno's ufmt panics on an argument shortfall rather than emitting Go's cosmetic %!s(MISSING), so every proposal-detail render for a DAO whose condition contains a RoleThreshold panicked — permanently.

Reproduced: panic: ufmt: not enough arguments at ufmt.gno:199, raised from cond_role_treshold.gno:59.

Why the suite never caught it: daocond_test.gno:175 calls RenderWithVotes only inside its failure branch, so a passing run never executes the line. The new test exercises it directly. (%% is a literal percent and consumes no argument — the verb count is genuinely 3.)

2. Removing the last member bricks the DAO permanently

RemoveMember checked only IsMember, so a single-member DAO could remove itself — 1/1 = 100% clears any threshold. The resulting zero-member DAO is unrecoverable: assertCallerIsMember rejects every entry point, so not even AddMember can be proposed again.

Reproduced: Panic value: nil — the removal succeeded silently. The control case (removal with others remaining) passes before and after, so the test discriminates rather than blanket-refusing.

3. An empty electorate yields NaN, not an unmet condition

Both threshold conditions divide yes-votes by the size of their electorate. gno's float64 divide has no zero guard — unlike every integer case, which raises division by zero — so an empty electorate produces 0/0 = NaN. NaN then escapes through Eval, Signal and RenderWithVotes; Signal is a progress value and math.Min(NaN/threshold, 1) is NaN, not 1.

The minimum-member guard in (2) does not cover this: a role can reach zero holders while the DAO still has members, via RemoveRoleFromMember (a default-registered governance action), RemoveRole, or removing the last holder of a role while others remain. Zero resolves to 0.0, never 1.0 — reading an empty electorate as vacuous truth would let a proposal pass with nobody entitled to vote on it. This mirrors the guard gnolovDaoCondThreshold.voteRatio already carries for its zero-power case.

Test plan

⚠️ CI on this repo is red for environmental reasons unrelated to this branch — gno lint/gno test resolve dependencies from rpc.gno.land, which CNAMEs to a mutable testnet serving pre-interrealm-v2 sources, so a hermetically pinned compiler is fed by a live unversioned source. Bumping the toolchain pin does not fix it. Vendoring the dependency closure does, and is proven end-to-end offline — but the vendor set must be pinned to the fork (p/samcrew/avl), not to examples/ at the pin, or the green signal would be compiled against the two-value avl that topaz-1 does not have. That is a separate PR and it depends on #65.

4. A roleless voter permanently bricks a gnolove DAO proposal

cond_gnolovedao.gno:112 getUserRole panicked when a voter held none of the condition's tier roles. Core.Vote gates on membership only, never on holding a tier role, so such a voter can reach the ballot — as can any member when the condition is built over a subset of the DAO's roles, which is exactly what the "T3 abstaining" case models. The panic was raised from inside the ballot walk, so one such vote made every later Eval, Signal and Render on that proposal panic. Unrecoverable once published, and reached by an ordinary member casting an ordinary vote.

A voter outside the condition's roles now carries no voting power.

This changes a deliberately asserted behaviour, so it deserves scrutiny. The matrix case carried panic: true alongside expectedYes: 7.0/10.0 — and 7/10 is precisely the tally with the T3 votes excluded, i.e. the number the case produces under this change. The panic flag documented what the code did; the expectation recorded what it was meant to do. With the flag removed, that case now genuinely evaluates Eval(ballot) == true instead of passing through the recover path, so the assertion is exercised for the first time.

Test plan

zxxma added 3 commits July 20, 2026 13:44
RenderWithVotes consumed three format verbs (%g, %s, %s) while passing two
arguments. gno's ufmt panics on an argument shortfall rather than emitting
Go's cosmetic "%!s(MISSING)", so every proposal-detail render for a DAO whose
condition contains a RoleThreshold panicked — permanently, since publishing is
immutable.

The existing suite never caught it: daocond_test.gno only calls RenderWithVotes
inside its failure branch, so a passing run never executes the line. The new
test exercises it directly.
RemoveMember checked only IsMember, so a single-member DAO could remove
itself: 1/1 = 100% clears any threshold, and nothing stopped the removal.
The resulting zero-member DAO is unrecoverable — assertCallerIsMember
rejects every entry point, so not even AddMember can be proposed, and every
threshold evaluates 0/0 = NaN, which is never >= the threshold. Publishing
is immutable, so the brick would be permanent.

Test lives in members_removal_test.gno rather than members_test.gno to avoid
colliding with the file added in the realm-identity-hardening branch.
Both threshold conditions divide yes-votes by the size of their electorate.
gno's float64 divide has no zero guard — unlike every integer case, which
raises "division by zero" — so an empty electorate produces 0/0 = NaN. NaN
then escapes through Eval, Signal and RenderWithVotes; Signal is a progress
value and math.Min(NaN/threshold, 1) is NaN, not 1.

The minimum-member guard added alongside this does not cover it: a role can
reachably reach zero holders while the DAO still has members, via
RemoveRoleFromMember (a default-registered governance action), RemoveRole, or
removing the last holder of a role while others remain.

Zero resolves to 0.0, never 1.0 — reading an empty electorate as vacuous truth
would let a proposal pass with nobody entitled to vote on it. This mirrors the
guard gnolovDaoCondThreshold.voteRatio already carries for its zero-power case.
@zxxma
zxxma force-pushed the fix/pre-freeze-safety-hardening branch from 531d12b to fc44fad Compare July 20, 2026 11:44
@zxxma
zxxma changed the base branch from feat/topaz-v2-rename to chore/vendor-dep-closure July 20, 2026 11:44
@zxxma zxxma changed the title pre-freeze safety: a guaranteed render panic, a permanent DAO brick, and NaN escaping the threshold conditions fix(daocond,basedao): a guaranteed render panic, a permanent DAO brick, and NaN escaping the threshold conditions Jul 20, 2026
getUserRole panicked when a voter held none of the condition's tier roles.
Core.Vote gates on membership only, never on holding a tier role, so such a
voter can reach the ballot — as can any member when the condition is built over
a subset of the DAO's roles, which is exactly what the "T3 abstaining" case
models. The panic was raised from inside the ballot walk, so one such vote made
every later Eval, Signal and Render on that proposal panic. On an immutable
publish that is unrecoverable, and it is reached by an ordinary member casting an
ordinary vote.

A voter outside the condition's roles now carries no voting power: "" is absent
from votingPowersByTier, so the lookup yields 0.0 and they contribute nothing.

This changes a deliberately asserted behaviour, so it is worth being explicit
about why it is a fix rather than a regression. The existing matrix case carried
`panic: true` alongside `expectedYes: 7.0/10.0` — and 7/10 is precisely the tally
with the T3 votes excluded, i.e. the number the case would produce under this
change. The panic flag documented what the code did; the expectation recorded
what it was meant to do. With the flag removed the case now genuinely evaluates
Eval(ballot) == true instead of passing through the recover path, so the
assertion is exercised for the first time.
@zxxma
zxxma changed the base branch from chore/vendor-dep-closure to feat/topaz-v2-rename July 20, 2026 12:19
@zxxma
zxxma merged commit 7a18b35 into feat/topaz-v2-rename Jul 20, 2026
6 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.

1 participant