trust

Trust monitors — le modèle d'autorisation on-chain composite de Convex. À utiliser lors de l'écriture de contrôles d'accès, de la restriction des fonctions d'acteurs, de la définition de qui peut frapper ou…

npx skills add https://github.com/convex-dev/convex --skill trust

Trust Monitors

Trust monitors are Convex's authorisation primitive: composable, sandboxed, on-chain modules that grant or deny access. Anywhere an actor asks "may this caller do this?", the answer should come from a trust monitor rather than hand-rolled logic.

Normative spec: https://docs.convex.world/docs/cad/trustmon. Reference implementation: convex-core/src/main/cvx/convex/core/trust.cvx and convex/trust/monitors.cvx.

The Model

Every check is a triple:

  • Subject — who is acting, almost always an account, usually *caller*
  • Action — what they are doing, a short keyword such as :update
  • Object — what they are acting on, typically an address or ID

This is the reference monitor model. Keeping the triple explicit is what makes monitors reusable across unrelated contracts.

Referencing a Monitor

A monitor reference is an account address, optionally scoped:

#45              ;; an account
[#78 1467476]    ;; a scoped account — same actor, different rule
nil              ;; never authorises anything

nil is a valid monitor that always denies — useful as a safe default.

A bare address trusts only itself: (trusted? #13 #13) is true, anything else false. That makes "the owner" expressible without deploying anything.

Checking Trust

(@convex.trust/trusted? monitor subject)
(@convex.trust/trusted? monitor subject action)
(@convex.trust/trusted? monitor subject action object)

Omitted action and object are passed as nil.

Inside an actor, the usual shape is:

(when-not (trust/trusted? minter *caller* :mint)
  (fail :TRUST "No rights to mint"))

Use :TRUST for authorisation failures — that is what callers expect.

Fail Closed

The check-trusted? SPI uses normal CVM truthiness: nil and false deny; every other value grants. A monitor may return a lookup result directly, without converting it to a boolean. In particular, 0, empty collections, empty strings and keywords such as :DENIED all grant access. A monitor must map any error-as-data or other denial sentinel to nil or false itself.

From protocol version 1, the public trusted? function normalises SPI results to literal true or false. It calls the monitor in query to roll back state changes and catches monitor errors as false. Resource exhaustion can still abort the check; it must never grant access. Write against that behaviour — it is the target semantics, and MigrationFixesTest pins it.

;; what trusted? does from v1
(boolean (try (query (call monitor (check-trusted? subject action object))) false))

Before v1 activates, the genesis trusted? in core/trust.cvx keeps the query guard but does not catch the error or coerce the result — so a monitor can throw through it or return a non-boolean value to its caller. If you are deploying an actor that accepts caller-supplied monitors onto a network still at version 0, apply the wrapper yourself. For monitors you control, the plain call is fine either way. See the protocol-versions skill.

Writing a Monitor

Implement check-trusted? as a callable taking exactly three arguments:

(defn ^:callable check-trusted?
  [subject action object]
  (and (= subject object) (= action :examine-self)))

Requirements that are not optional:

  • No reliance on side effects. A monitor MUST work correctly inside query, where state changes are rolled back.
  • Use CVM truthiness for every argument combination. Return nil or false to deny; callers needing literal booleans should use trusted?.
  • Be O(1) in computation and stack depth, with a small constant. Use pre-computed sets and maps for lookups.
  • Never scan arbitrary data structures. An unbounded scan inside a monitor is a denial-of-service vector, since the monitor runs on every check.

Standard Monitors

convex.trust.monitors provides composable monitors that need no deployment — each returns a scoped address evaluated inline.

ConstructorGrants when
(mon/permit-subjects #3 #14)subject is in the set
(mon/permit-actions :open :close)action is in the set
(mon/all m1 m2 …)every listed monitor grants
(mon/any m1 m2 …)any listed monitor grants
(mon/everyone)always
(mon/before end) / (mon/after start) / (mon/between start end)within the timestamp window
(mon/rule (fn [s a o] …))the function returns truthy
(mon/owns asset)subject owns the asset
(mon/delegate allow deny base)deny first, then allow, else base

Compose rather than write bespoke logic:

(@convex.trust.monitors/all
  (@convex.trust.monitors/permit-subjects #13 #17)
  (@convex.trust.monitors/permit-actions :open :close))

delegate checks deny before allow, which is the ordering you want for revocation.

Guidance

Hard-code actions. An action keyword SHOULD NOT come from, or be influenced by, untrusted input — otherwise a caller can select which authorisation branch to be checked against. Keep actions literal at the call site.

Keep actions simple. They may be any CVM value, but complex action structures make security bugs easy. A keyword is almost always right.

Let users supply the monitor. The point of the pluggable design is that whoever controls a resource chooses its access rules. Take a monitor reference as configuration rather than baking a whitelist into an actor — this is exactly how add-mint takes :minter; see the token skill.

Related libraries: convex.trust.whitelist, convex.trust.ownership-monitor, convex.trust.delegate and convex.trust.governance.

Plus de skills de convex-dev

convex-lisp
convex-dev
Référence du langage Convex Lisp — conventions CVM, appel de code de bibliothèque, définitions d'acteurs, juice et codes d'erreur. À utiliser lors de l'écriture ou du débogage de code source CVM pour…
ecosystem
convex-dev
Orientation dans l’écosystème Convex — ce qui se trouve dans quel dépôt, où sont les spécifications et la documentation, et quelles bibliothèques clientes existent. À utiliser lorsque vous avez besoin de contexte…
local-network
convex-dev
Exécutez un réseau de test Convex local pour le développement. Utilisez-le pour tester des modifications par rapport à un réseau en direct, reproduire un problème d'un pair, ou lorsqu'aucun réseau distant n'est...
protocol-versions
convex-dev
Versions de protocole, migrations et mise à niveau v1 — quelles sémantiques utiliser, et comment modifier le comportement de CVM sans forker le réseau. À utiliser lorsque…
etch
convex-dev
Inspecter et maintenir un magasin Etch — la base de données à adressage par contenu de Convex. À utiliser lors de l'examen du stockage des pairs, du diagnostic de corruption, du garbage collection, ou…
juice
convex-dev
Comptabilité Juice — le coût de calcul et de bande passante sur le CVM. À utiliser lors du raisonnement sur le coût d’exécution des transactions, du diagnostic d’une erreur :JUICE, ou…
memory
convex-dev
Comptabilité et allocations de mémoire — le coût du stockage on-chain, et comment le minimiser et le récupérer. À utiliser pour raisonner sur la croissance de l'état, diagnostiquer un…
peer
convex-dev
Exploiter un pair Convex — créer, démarrer, lister, sauvegarder ou instancier une genèse de réseau. À utiliser lors de l'exécution d'un pair contre un réseau ou de la mise en place d'un nouveau réseau.