Skip to content

fix(basedao,daokit): bind the DAO's identity to its own live realm - #69

Merged
zxxma merged 1 commit into
feat/topaz-v2-renamefrom
fix/dao-caller-identity
Jul 20, 2026
Merged

zxxma merged 1 commit into
feat/topaz-v2-renamefrom
fix/dao-caller-identity

Conversation

@zxxma

@zxxma zxxma commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Completes the P0-A / P0-B interface work. This is the last interface-breaking change before the topaz-1 freeze, so it is now-or-never.

The defect

Both blockers are the same defect seen from two sides.

Execute forwards the threaded realm to the action handlers, which cross out under it. Whoever supplies that realm therefore decides the identity the DAO acts as — a third realm holding the DAO value could pass its own and have the DAO write to that realm's profile, or through MigrateFn reach anywhere it controls.

And reached through the DAO handle there is no DAO realm frame on the stack at all, so the old stack-walking identity named the signing account. A member's signature satisfied the membership check while the caller supplied the realm the DAO acted under.

The fix

Propose(req, rlm) / Vote(id, vote, rlm) / Execute(id, rlm) each assert the threaded realm is the DAO realm's own live one before doing anything else. Realm values are unforgeable and cannot be persisted across transactions, so a caller can only ever pass its own; requiring it to equal the DAO's own closes the donation path outright. Given that, rlm.Previous() is by construction the DAO's immediate caller.

The gate requires the realm to be current, not merely to match by pkgpath. Every realm the DAO crosses out into during an action receives the DAO's own realm as its cur.Previous() and can hand it straight back within the same transaction: same pkgpath, dead frame. Reproduced end to end — with a pkgpath-only gate a callee re-entered Propose under the DAO's own identity and was accepted. IsCurrent() is frame identity rather than name; verified it survives the /p/ hop into basedao and holds during a realm's own init, so neither the ordinary path nor construction is affected.

The realm is never a first parameter — the VM reads that as a crossing function, which /p/ packages may not declare. Receivers do not count, so assertRealmIsOwn and defaultCallerID take the DAO first.

Tests

testing.SetRealm fabricates a cur with no frame beneath it: cur.Previous() resolves to gno.land/p/samcrew/basedao itself. It cannot express a caller chain in either direction, which is why the original defect and the New() regression in #66 both passed CI.

Tests are therefore realm-to-realm, under gno/r/daoidentity/ — a DAO realm, a relay, a non-member, an attacker holding the DAO value, and a callee re-entering with the DAO's own dead-frame realm. These are fixtures only; the deployer publishes an explicit 7-directory list that excludes them, and assert_gnodaokit_source_form topaz-1 passes against this branch.

Five properties are mutation-checked, each failing exactly one test:

Mutation Caught by
drop !rlm.IsCurrent() TestADAORealmValueFromADeadFrameIsRefused
drop the pkgpath equality the three MayNotDonateItsIdentity tests
drop the empty-id guard TestAnEmptyCallerIdIsNeverAMember
membership checked before the realm gate TestTheGateRunsBeforeCallerIDEverSeesTheRealm
drop Execute's membership check TestExecuteRequiresMembershipNotJustTheRightRealm

Ordering is pinned because CallerIDFn is a frozen extension point: running membership first would hand a custom implementation an attacker-controlled realm.

basedao's unit tests now declare the caller they act as rather than leaning on the harness, and realm_identity_test.gno is dropped — SetRealm-based identity tests claim coverage that cannot exist.

Two corrections found in review

  • The stack walk is not wrong the way earlier notes recorded. On every path the gate admits, unsafe.PreviousRealm() and rlm.Previous() name the same realm — the gate has already established the DAO's frame is live. The walk goes wrong only in the shape the gate now rejects. Comments were corrected to say this; the threaded form is kept because it does not depend on the gate having run first.
  • Root-of-chain does not yield "" on-chain. buildOriginRealm sets {OriginCaller, ""}, so IsUser() holds and a root-of-chain call resolves to the signing account. The empty id is a gno test artifact (the harness leaves OriginCaller unset). The empty-id guard is asserted on controlled input instead, and it is load-bearing: AddMember does not reject "", Members is an exported avl.Tree a MigrateFn can seed directly, and any unattributable call resolves to "".

Verification

gno test ./gno/... green (8 packages) · gno lint clean · gno fmt -diff clean · zero gno: downloading · deployer assert_gnodaokit_source_form topaz-1 passes.

Base is feat/topaz-v2-rename, not main: main is pre-interrealm-v2 and not locally buildable.

Closes both identity blockers as one interface change, since they are the same
defect seen from two sides.

Propose(req, rlm) / Vote(id, vote, rlm) / Execute(id, rlm) each assert the
threaded realm is the DAO realm's own live one before doing anything else.
Execute forwards that realm to the action handlers, which cross out under it, so
whoever supplies it decides the identity the DAO acts as: a third realm holding
the DAO value could pass its own and have the DAO write to that realm's profile,
or via MigrateFn reach anywhere it controls. Realm values are unforgeable and
cannot be persisted across transactions, so a caller can only pass its own;
requiring it to equal the DAO's own closes that path outright.

Reached through the DAO handle there is no DAO realm frame on the stack at all,
so the old stack-walking identity named the signing account. A member's
signature then satisfied the membership check while the caller supplied the
realm the DAO acted under. Identity now derives from the threaded realm, which
does not depend on where in the chain it is read.

The gate requires the realm to be current, not merely to match by pkgpath. Every
realm the DAO crosses out into during an action receives the DAO's own realm as
its cur.Previous() and can hand that value straight back within the same
transaction: same pkgpath, dead frame. Reproduced end to end — before this, a
callee re-entered Propose under the DAO's own identity and a pkgpath-only gate
accepted it. IsCurrent() is frame identity rather than name; it survives the /p/
hop into basedao and holds during a realm's own init, so neither the ordinary
path nor construction is affected.

The realm is never a first parameter: the VM reads any function whose first
parameter is a realm as crossing, and /p/ packages may not declare crossing
functions. Receivers do not count, so assertRealmIsOwn and defaultCallerID take
the DAO first.

Tests are realm-to-realm, under gno/r/daoidentity. testing.SetRealm fabricates a
cur with no frame beneath it — cur.Previous() resolves to p/samcrew/basedao
itself — so it cannot express a caller chain in either direction, which is why
the original defect and the New() regression in #66 both passed CI. The suite
drives a real DAO realm from a relay, a non-member, an attacker holding the DAO
value, and a callee re-entering with the DAO's own dead-frame realm.

Five properties are mutation-checked, each failing exactly one test: either half
of the realm gate, the empty-id guard, the gate running before CallerID ever
sees a realm, and Execute requiring membership. The ordering matters because
CallerIDFn is a frozen extension point — running membership first would hand a
custom implementation an attacker-controlled realm.

basedao's unit tests now declare the caller they act as instead of leaning on
the harness, and realm_identity_test.gno is dropped: SetRealm-based identity
tests claim coverage that cannot exist.

The empty-id guard is load-bearing rather than cosmetic. AddMember does not
reject "", Members is an exported avl.Tree a MigrateFn can seed directly, and
any call the machine cannot attribute to a signer resolves to "" — so one such
entry would otherwise authenticate all of them. It is asserted on controlled
input, not inferred from the environment: under gno test the harness leaves
OriginCaller unset, while on-chain a root-of-chain call resolves to the signing
account.
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