Repository navigation
Conversation
🛠 PR Checks SummaryAll Automated Checks passed. ✅ Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🟢 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
Master's only change to effective-gno.md since the fork is 24 lines: the GetCoin note in the Coins section, and the Foo Token example turning UserTeller into an unexported userTeller with a Transfer wrapper. Both are carried onto this branch's rewrite. MyBalance keeps this branch's cur.Previous() and takes master's Token.BalanceOf, since UserTeller is gone.
One conflict, in docs/resources/effective-gno.md. This branch replaces the sections master still carries below "Define types and interfaces in pure packages", so the resolution keeps the branch side of that region. Master moved the grc20 package from p/demo/tokens/grc20 to p/nt/grc20/v0 and fixed both references. One of them sits inside the conflict region here and one outside, so the outside fix merged and the inside one had to be carried over by hand: the branch had moved that import into the Coins section.
…ction samples
Nine samples opened on
if !cur.IsCurrent() {
panic("spoofed realm")
}
before reading cur.Previous().Address(). Every entry from another realm mints
a fresh cur, so the guard refuses nobody and the panic message names something
that cannot happen. The live check is on a realm value the caller hands over
as an ordinary parameter, which none of these samples takes.
The paragraph on chain/runtime/unsafe said nothing verifies a stack walk the
way a cur handle is verified. It now contrasts the two on what is true: a
stack walker answers from wherever it stands, and the runtime binds cur to the
frame that received it.
There was a problem hiding this comment.
Thanks for picking up the roadmap! I left notes inline: the callback section needs a rewrite (it's a security point), and a few numbers and paths are off.
More generally, following #5651, I'd cut each new tip down to a few lines plus a link. Many of the sections repeat pages we already have (gno-data-structures.md, community-packages.md, gas-fees.md, the security guide). The app patterns (state machine, subscription, governance) would fit better as r/docs examples. Putting the section reorder in its own commit would also make the diff much easier to review.
…k the caller in the public-API sample
… the banker detail
…ink payments and restricted_denoms, simplify package naming
|
@alexiscolin, since your review at b610600:
|
There was a problem hiding this comment.
(Review done with AI help.)
Thanks David, this reads much better, and my inline notes are all addressed. What's left: the payment check on the new coins page and the teller comment (inline), and two "see also" lines outside the diff that still say effective-gno.md covers payment guards, docs/resources/gno-security-guide.md:613 and docs/resources/gno-ai-contract-review.md:261. Could they point to coins-and-tokens.md now? The app patterns didn't make it to r/docs, so could you switch to "Part of #5031" or open a follow-up issue, so they don't get lost when this closes?
| `maketx call` with `-send`. | ||
| In the called function, first check that the user called you directly with | ||
| `cur.Previous().IsUserCall()`, then read the amount sent with | ||
| [`unsafe.OriginSend()`](./gno-stdlibs.md#originsend). The |
There was a problem hiding this comment.
The move dropped master's sample and the amount comparison: this now just says to "read" OriginSend(), and §5.5 links straight back here. Someone following it literally checks IsUserCall() and never compares what was paid. Could you keep a short sample here, IsUserCall() plus if unsafe.OriginSend().AmountOf("ugnot") != price { panic(...) }?
There was a problem hiding this comment.
Fixed: c47b9df, the section shows a Buy sample with both checks again, and says that without the amount check a call attaching no coins succeeds.
| var ( | ||
| Token *grc20.Token | ||
| privateLedger *grc20.PrivateLedger | ||
| // Unexported: whoever holds a teller can spend from the ledger. |
There was a problem hiding this comment.
A CallerTeller only works in the token's own realm (guardHome returns ErrForeignCallerTeller anywhere else), so "whoever holds a teller can spend" isn't true for this one. Master's wording was right:
| // Unexported: whoever holds a teller can spend from the ledger. | |
| // Keep the teller unexported: it is a spend capability. It is built from | |
| // the ledger, which never leaves this realm, and it only works here. |
| ## Choosing between Coins and GRC20 tokens | ||
|
|
||
| Pick Coins when a token only needs to be held and sent. The chain moves them | ||
| with no contract code, and a user attaches them to any call with `-send`. |
There was a problem hiding this comment.
Nit: since #6062, a -send to a function that never looks at the payment fails with UnobservedSendError, so -send doesn't work on just any call.
| with no contract code, and a user attaches them to any call with `-send`. | |
| with no contract code, and a user pays a realm by attaching them with `-send` | |
| to a function that reads `unsafe.OriginSend()`. |
| - In a crossing function, derive caller identity from `cur.Previous()` and write no `cur.IsCurrent()` guard: the runtime puts `cur` into the current realm-context on entry, so the check is always true. `IsCurrent()` belongs on a realm value a caller hands over as an ordinary argument, `rlm` by convention, which may be left over from an earlier call. | ||
| - Never read `chain/runtime/unsafe.PreviousRealm()` in a crossing function: it walks the frame stack, so it answers from wherever it is called, while `cur.Previous()` names the realm that was current when `cur` was minted. Delete any `chain/runtime/unsafe` import sitting beside a `cur realm` parameter. | ||
| - When editing a realm that accepts payment via `banker.OriginSend()`, the caller guard must be `cur.Previous().IsUserCall()`, not `IsUser()`. `IsUser()` accepts `maketx run` ephemeral realms, which can consume the origin-send envelope before calling your function and bypass the payment check. See [docs/resources/effective-gno.md § Verifying inbound Coin payments](docs/resources/effective-gno.md#verifying-inbound-coin-payments). | ||
| - When editing a realm that accepts payment via `banker.OriginSend()`, the caller guard must be `cur.Previous().IsUserCall()`, not `IsUser()`. `IsUser()` accepts `maketx run` ephemeral realms, which can consume the origin-send envelope before calling your function and bypass the payment check. See [docs/resources/coins-and-tokens.md § Verifying inbound Coin payments](docs/resources/coins-and-tokens.md#verifying-inbound-coin-payments). |
There was a problem hiding this comment.
Since this line changes anyway: banker.OriginSend() doesn't exist, OriginSend lives in chain/runtime/unsafe (line 111 has the same name).
| - When editing a realm that accepts payment via `banker.OriginSend()`, the caller guard must be `cur.Previous().IsUserCall()`, not `IsUser()`. `IsUser()` accepts `maketx run` ephemeral realms, which can consume the origin-send envelope before calling your function and bypass the payment check. See [docs/resources/coins-and-tokens.md § Verifying inbound Coin payments](docs/resources/coins-and-tokens.md#verifying-inbound-coin-payments). | |
| - When editing a realm that accepts payment via `unsafe.OriginSend()`, the caller guard must be `cur.Previous().IsUserCall()`, not `IsUser()`. `IsUser()` accepts `maketx run` ephemeral realms, which can consume the origin-send envelope before calling your function and bypass the payment check. See [docs/resources/coins-and-tokens.md § Verifying inbound Coin payments](docs/resources/coins-and-tokens.md#verifying-inbound-coin-payments). |
There was a problem hiding this comment.
Applied in c47b9df, line 111 too. Line 109 now deletes only a chain/runtime/unsafe import that PreviousRealm() alone uses, since the payment check reads unsafe.OriginSend() from it. 14784a5..c47b9df
…d-tokens Co-authored-by: Alexis Colin <7622257+alexiscolin@users.noreply.github.com>
|
This time it should be good, I will do a second PR for the rest of the initial issue, tysm for your review! |
Part of #5031
Effective Gno ended on a TODO listing topics nobody wrote, and five links on four pages pointed at a storage section,
#choose-storage-types-by-access-pattern, that acd01fa deleted.This writes those topics as short tips, each a few lines and a link to the page that covers it, and cuts the older sections to the same shape: 5631 words on master, 1959 here. The storage section returns under its old anchor.
The
testinghelpers that call a realm as another user or contract move to a new section ofgno-testing.md.Coins, GRC20 tokens and how a realm takes a Coin payment move to a new page,
coins-and-tokens.md, since they define the assets rather than a practice. The links to the payment section, inAGENTS.md, the security guide,gno-ai-contract-review.mdand three realm comments, follow it. The payment check readsunsafe.OriginSend(), so the rule inAGENTS.mdand the security guide that deleted everychain/runtime/unsafeimport beside acur realmparameter now deletes only one thatPreviousRealm()alone uses.