clarity-sip-compliance
Skill2 starsChanged 32 days agoMITView on GitHub
Token standards in Clarity: SIP-010, SIP-009 and SIP-013 traits and conformance, metadata, SIP-018 signed data. Use when writing a token or NFT contract or checking trait conformance.
In this repository24 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- llms.txtllms.txt
- clarity-apisSkill
- clarity-assetsSkill
- clarity-auditorSkill
- clarity-bitcoin-proofsSkill
- clarity-deploymentSkill
- clarity-ecosystemSkill
- clarity-environmentsSkill
- clarity-epochsSkill
- clarity-fuzzingSkill
- clarity-governanceSkill
- clarity-optimizerSkill
- clarity-oraclesSkill
- clarity-protocolsSkill
- clarity-scholarSkill
- clarity-securitySkill
- clarity-stakingSkill
- clarity-startSkill
- clarity-system-integrationSkill
- clarity-testingSkill
- clarity-upgradesSkill
- clarity-walletsSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 6 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 18
impl-traitchecks types only: Verify balances, native assets, transfer effects, memos and errors separately. - Very specific: line 29
Use native assets (define-fungible-token, optional second argument caps supply.
- Distinctive: line 39
Document whichever model you pick.
- Very specific: line 175
Use consensus serialization and SHA-256, not JSON text.
- Distinctive: line 176
Use the SIP's vectors to establish cross-language compatibility, including field ordering imposed by consensus serialization.
- Distinctive: line 180
Do not confuse secp256k1 recoverable signatures with secp256r1 verification or assume their encodings are interchangeable.
- Distinctive: line 199
Start with the protocol's claims and exposed interfaces.
- Distinctive: line 202
Read beyond the trait: semantic clauses, events, native assets, error conventions and client obligations can be outside it.
- Distinctive: line 208
When sources conflict, quote only the short disputed clause, pin both sources, and mark the affected conclusion unverified until the …
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Clarity SIP Compliance
Assess clause-to-code-to-test conformance or implement standards while preserving requested behavior.
Writing or changing contract code: also load clarity-scholar and clarity-security, and finish with the build checklist.
Key distinctions
impl-traitchecks types only: Verify balances, native assets, transfer effects, memos and errors separately. Bounded return types need compatibility, not identical text (SIP-010).- SIP-009 does not prescribe caller authentication: It specifies transfer ownership results. Missing authentication is a security issue; cite an actual clause before claiming a normative violation.
- SIP-010's
tx-sendercheck is an example: The SIP mandates neither one sender check nor global error codes. Itsu1–u4meanings are recommendations local to the token interface, not an application-wide numbering. - Not every memo print complies: Print a present memo unwrapped after a successful native transfer.
some 0xis present andnoneis absent; a custom tuple changes the event interface. - Accepted is not activated: Separate application compatibility, proposal status and activation. SIP-044 disables the
cost-votingboot contract (SIP-006's voting mechanism) from epoch 4.0; SIP-006's cost model remains. Historical proposals need not describe current APIs.
See recall corrections for common mistakes.
Writing a token: shared rules
- Compile with Clarity 4 or later. Every extension beyond the standard (mint, burn, pause, admin) is a new surface to review.
- Use native assets (
define-fungible-token, optional second argument caps supply;define-non-fungible-token) so postconditions and indexers see every movement. Map-only balances are invisible to native asset constraints, and SIP-shaped methods alone do not make a synthetic balance equivalent to a native FT. ft-transfer?,nft-transfer?,ft-burn?andnft-burn?do not look attx-sender: the VM lets the defining contract move any holder's balance. Only native STX transfers and burns requiresender == tx-sender. Every public path that reaches a native token operation therefore needs its own owner check.- Owners may be contract principals; avoid EOA-only assumptions.
impl-traitthe deployed mainnet trait principal and keep it in source on every network. On testnet/devnet the trait needs a deployment on that network: in Clarinet add the mainnet principal under[[project.requirements]](simnet deploys it at the mainnet principal;clarinet deployments applypublishes it under your deployer on devnet/testnet and rewrites the ID in later contracts). Never hand-edit the principal per environment, and do not silently choose a testnet trait on mainnet. SIP-listed testnet principals and their current status: standard traits.
Authorization choice
- SIP-010's example checks only
tx-sender; SIP-013 recommends also acceptingcontract-caller. Neither requires rejecting contract-mediated transfers. The default here is either identity,(or (is-eq tx-sender sender) (is-eq contract-caller sender)), because a contract can then hold and spend tokens or NFTs it owns withoutas-contract?(sBTC does this). - Trade-off: the
tx-senderbranch still lets any contract the owner calls (a marketplace, a commission or other callback) move the owner's assets; thecontract-callerbranch adds nothing against that. Atx-sender-only check is no safer in that respect; it only stops contracts from spending their own balances withoutas-contract?. Owner-side protection is bounded postconditions and not calling untrusted contracts. See A01 and the per-asset authorization matrix. - To forbid forwarded owner authority, check
(asserts! (is-eq contract-caller sender) ...)(direct calls and contract-held balances only); that breaks routers that call on the user's behalf unless the user is the direct caller. - Document whichever model you pick; integrators depend on it. The either-identity default is a design choice, not SIP-mandated.
Token administration
- If the token has an administrator and the project has no governance model yet, keep it in a data var initialized to
tx-sender(the deployer) pluspending-admin (optional principal). Keep an existing model (DAO extension checks, role maps, a multisig contract); a token with no privileged functions needs no administrator. - Privileged functions (mint, set-token-uri, admin changes) check
contract-caller, nottx-sender: an admin calling an untrusted contract must not lend it this power. Under an ExecutorDAO-style owner, setters checktx-senderagainst the DAO instead (proposal contracts). - Standard-account administrators use nomination then acceptance. The nominee must be a standard principal of the execution network:
principal-destruct?returnserrfor another network's version byte, andnameisnonefor a standard principal. Acceptance requires(is-eq (some contract-caller) (var-get pending-admin))and clears the nomination. - Direct handoff to a contract (
set-contract-admin) accepts only a contract principal (nameissome), clears any nomination, and requires a reviewed onward administration route; see ownership setters. - Print every change (for example
actor,previousand the newadministrator). Application errors use a range separate from SIP transfer and native codes (for exampleu1000and up; keep a project's existing range).
;; fragment: nomination/acceptance (standard-account nominee); ERR_* are (err u1000+)
(define-public (propose-admin (new-admin principal))
(begin
(asserts! (is-eq contract-caller (var-get administrator)) ERR_OWNER_ONLY)
(asserts! (is-none (get name (unwrap! (principal-destruct? new-admin) ERR_ADMIN_KIND))) ERR_ADMIN_KIND)
(var-set pending-admin (some new-admin))
(print {event: "admin-proposed", actor: contract-caller, previous: (var-get administrator), administrator: new-admin})
(ok true)))
(define-public (accept-admin)
(let ((previous (var-get administrator)))
(asserts! (is-eq (some contract-caller) (var-get pending-admin)) ERR_PENDING_ADMIN)
(var-set administrator contract-caller)
(var-set pending-admin none)
(print {event: "admin-accepted", actor: contract-caller, previous: previous, administrator: contract-caller})
(ok true)))SIP-010 fungible tokens
Source: SIP-010. Mainnet trait: 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.sip-010-trait, defined as:
;; SIP-010 trait as deployed at SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard
(define-trait sip-010-trait
(
(transfer (uint principal principal (optional (buff 34))) (response bool uint))
(get-name () (response (string-ascii 32) uint))
(get-symbol () (response (string-ascii 32) uint))
(get-decimals () (response uint uint))
(get-balance (principal) (response uint uint))
(get-total-supply () (response uint uint))
(get-token-uri () (response (optional (string-utf8 256)) uint))
)
)- Return bounds are maxima: a
(string-ascii 10)return satisfies(string-ascii 32); a declared bound of 40 does not, even if the current value is short. Check return-type admission, not textual type equality, and do not extrapolate the same direction to parameter types. - Getters are recommended to be read-only. Return balance and supply from the native asset (
(ok (ft-get-balance token who)),(ok (ft-get-supply token))) and check them against real mint/burn/transfer operations, including contract holders.impl-traitchecks compatible function types, not honest balances or transfer semantics. - Error codes should follow
u1insufficient balance,u2identical sender/recipient,u3zero amount,u4unauthorized.ft-transfer?itself returnsu1/u2/u3; the owner check returns(err u4). Classify a deviation at its actual normative strength and explain consumer impact; do not move these into a project's local error range and still claim conventional compatibility. - Memo: print a present memo unwrapped via
printafter a successful native transfer:(match memo to-print (print to-print) 0x).noneemits no memo;some 0xis present and is still emitted; wrapping the memo in a custom tuple is a different event. Error paths must not leave transferred funds or success events. - Client postconditions are explicitly recommended; if a wrapper transfers native STX, state the native asset consumers must constrain.
- For sBTC, the deployed
get-balanceincludes locked units and availability needs its separate getter; classify that integration fact separately from a blanket claim of SIP noncompliance.
;; fragment: SIP-010 transfer; ERR_NOT_TOKEN_OWNER is (err u4)
(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34))))
(begin
(asserts! (or (is-eq tx-sender sender) (is-eq contract-caller sender)) ERR_NOT_TOKEN_OWNER)
(try! (ft-transfer? example-token amount sender recipient))
(match memo to-print (print to-print) 0x)
(ok true)))- Regression set: direct authorized transfer; unauthorized third-party transfer and unauthorized indirect transfer (
err u4); intended authorized contract transfer; insufficient balance (err u1); zero amount (err u3); self-transfer (err u2);nonememo emits no print;(some 0x)emits an empty-buffer print after theft_transfer_event; 34-byte memo; oversized memo rejected by type; failed transfer emits nothing; balance/supply before and after mint/burn/transfer.
SIP-009 non-fungible tokens
Source: SIP-009. Mainnet trait: 'SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait.nft-trait, defined as:
;; SIP-009 trait as deployed at SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait
(define-trait nft-trait
(
(get-last-token-id () (response uint uint))
(get-token-uri (uint) (response (optional (string-ascii 256)) uint))
(get-owner (uint) (response (optional principal) uint))
(transfer (uint principal principal) (response bool uint))
)
)- The NFT URI is optional ASCII 256, unlike SIP-010's UTF-8 URI. SIP-016 clients substitute
{id}with the decimal token ID. - Getters must never return
err. Unknown IDs give(ok none)for owner and URI; IDs above the last ID have no owner.get-last-token-idis an upper bound, not the number currently minted after burns. - A successful transfer changes the owner to the recipient, and a transfer of an ID above
get-last-token-idmust fail. - SIP-009 says nothing about authorization: rejecting transfers by non-owners is a security requirement of your implementation, not SIP text. The owner check in
transferis the only theft guard.nft-transfer?then checks thatsenderowns the ID (err u1) and that the ID exists (err u3). NFT application errors use a range of their own (for exampleu1000and up) so they do not collide with native codes. - Mint: authorize minting the way the design requires (an administrator, a minter role or contract, or a public mint with its own payment and supply checks). The common scheme below mints
last-token-id + 1and stores it; sparse or derived IDs are valid ifget-last-token-idstays at least the highest minted ID. Return(ok id). - The standard requires native NFT assets for postcondition observability. Its clause that a
transferwithout a deny-mode or NFT owner-change postcondition must fail withabort_by_post_conditionis not enforced by the node for allow-mode transactions, and a contract cannot read postconditions: record it as "normative text not implementable at contract level" (not applicable), not a failed check, and usedefine-non-fungible-tokenso wallets can attach NFT conditions. Verify transaction-level postconditions with an SDK/node that enforces them. get-ownerstability: onceget-ownerreturnsA, it must return the same value untiltransferis called withAas sender. A burn (nft-burn?) changes the owner withouttransfer; document it as a deviation or do not offer burns. With burns,last-token-idstays an upper bound, not a count.
;; fragment: SIP-009 transfer, mint and getters (ERR_* are (err u1000+))
(define-public (transfer (id uint) (sender principal) (recipient principal))
(begin
(asserts! (or (is-eq tx-sender sender) (is-eq contract-caller sender)) ERR_NOT_TOKEN_OWNER)
(nft-transfer? example-nft id sender recipient)))
(define-public (mint (recipient principal))
(begin
(asserts! (is-eq contract-caller (var-get administrator)) ERR_OWNER_ONLY)
(let ((id (+ (var-get last-token-id) u1)))
(try! (nft-mint? example-nft id recipient))
(var-set last-token-id id)
(ok id))))
(define-read-only (get-owner (id uint)) (ok (nft-get-owner? example-nft id)))
(define-read-only (get-token-uri (id uint))
(ok (if (is-some (nft-get-owner? example-nft id)) (some "ipfs://example/{id}.json") none)))- Tests: unknown ID getters return
(ok none), transfer of an ID aboveget-last-token-idfails, owner after transfer equals recipient, a third party's transfer fails, contract principals can own tokens.
SIP-013 semi-fungible tokens
Source: SIP-013. Mainnet trait: 'SPDBEG5X8XD50SPM1JJH0E5CTXGDV5NJTKAKKR5V.sip013-semi-fungible-token-trait.sip013-semi-fungible-token-trait.
- This is an SFT standard, not a generic SIP-010 batch-transfer standard.
- Trait functions, all returning
(response T uint):get-balance (uint principal),get-overall-balance (principal),get-total-supply (uint),get-overall-supply ()andget-decimals (uint)→uint;get-token-uri (uint)→(optional (string-ascii 256));transfer (uint uint principal principal)andtransfer-memo (uint uint principal principal (buff 34))→bool. transferargument order is token ID, amount, sender, recipient;transfer-memoadds a non-optional(buff 34).- Balance and supply getters should never return
err. Unknown IDs and holders giveu0; the overall balance and supply are sums over all IDs. - Postconditions cannot see map-only balances. Mirror them in native assets as SIP-013 recommends: one FT for all IDs plus a tag NFT keyed
{token-id: uint, owner: principal}, which each transfer burns and re-mints for the sender. Wallets can then bound the amount (FT) and the ID (tag). Contract pattern, client conditions and the Deny-mode recipient trap: SFT post-conditions. - Custom
sft_transfer,sft_mint,sft_burnevents carry the specified token ID, amount, and relevant principals. Order: native event, SFT event, then memo when present. - The optional send-many extension has its own trait with bounded lists (200 in the current spec). If one entry fails, the batch should fail: test a late failure and prove earlier state is rolled back; an outer
okcontaining a list oferrvalues does not establish atomicity.
Metadata: SIP-016 and SIP-019
- Validate the URI type from the token's interface separately from the JSON schema it serves. Check actual required fields and token-class extensions; do not infer metadata compliance from a reachable image URL. Consumers should prefer authoritative on-chain fields where specified.
- Restrict URI setters to the administrator. After a metadata change, emit the SIP-019 notification for the token's class. For an FT:
(print {notification: "token-metadata-update", payload: {token-class: "ft", contract-id: current-contract}}). An NFT usestoken-class: "nft"and may list the changedtoken-ids; an SFT uses"sft"and must list them. - An NFT notification without
token-idsrefreshes every token. Useupdate-modeandttlonly as defined. - Indexers must validate notification provenance/target and treat a notification as a refresh hint, not authority to replace token ownership or financial state.
- A contract test cannot prove the availability or correctness of off-chain metadata; list it as an evidence gap.
SIP-018: signed structured data
Source: SIP-018.
- Use consensus serialization and SHA-256, not JSON text. The digest is SHA-256 of prefix
0x534950303138, the domain hash and the message hash. The domain includes application name, version and chain ID with the specified types. - Use the SIP's vectors to establish cross-language compatibility, including field ordering imposed by consensus serialization.
- Bind actions, amount, asset, recipient and the intended contract/application as the protocol needs. Nonce, expiry and replay protection are security requirements of the application's message and state, not fields supplied by SIP-018.
- Reject wrong signer, chain, domain, expired data, altered amount/recipient and replay.
- Clarity 1 retains the testnet-only
principal-of?behavior even under later epochs; Clarity 2+ selects the execution network. - Do not confuse secp256k1 recoverable signatures with secp256r1 verification or assume their encodings are interchangeable.
Consensus and adjacent standards
The specification's wording governs; check versions and the activated node implementation.
- SIP-002/005 define language/serialization foundations.
- SIP-021 (Nakamoto) and later upgrades change timing and execution.
- SIP-024 repairs historical type/serialization validation.
- SIP-033/039/044 introduce Clarity 4/5/6; SIP-035 is informational (documents the Clarity 4
secp256r1-verifydouble hash). - SIP-040 adds Originator post-condition mode and NFT may-send; epoch 4.0 adds Staking/PoX post-conditions.
- SIP-042 disables
at-blockfor all versions from epoch 3.4: merely keepingclarity_version = 4does not preserve historical execution. SIP-039's earlier proposed historical-state repairs are superseded by that removal. - SIP-045 describes PoX-5; its boot-contract requirements belong to the actual network epoch and PoX version, not a fabricated 'SIP-010-compatible staking' trait.
- Wallet interface SIP-030 and transaction multisig SIP-027 are relevant only when the project implements those client/transaction flows.
- Drafts such as SIP-038 are not universal requirements for NFTs.
- For consensus upgrades, state the effect on existing deployments as well as new source.
Conformance review
- Start with the protocol's claims and exposed interfaces. Select applicable standards, pin the official SIP repository commit, and inspect proposal status, layer, specification, amendments, superseding proposals and activation; consult versions for activation questions.
- Refresh the dated catalog before deciding requirements: compare its
commitwithgh api repos/stacksgov/sips/commits/main --jq .sha(orgit -C <sips checkout> log -1 --format=%H) and re-read the status of each SIP you rely on. - Ratification does not mandate universal implementation; applicability follows interfaces and claims. Contracts can implement token/signing interfaces; arbitrary application functions cannot implement VM/network consensus upgrades. Draft/withdrawn proposals require explicit product intent.
- Read beyond the trait: semantic clauses, events, native assets, error conventions and client obligations can be outside it. Check ABI types, argument order, list/buffer bounds, native assets, response variants, authorization, errors, memo/event order, getters, metadata and invariants.
- Inspect the code and real dependency behavior first. A name scanner can miss compatible but differently named aliases, optional extension traits and malicious implementations. Traits, function-name scans, audit labels and happy-path transfers cannot establish complete compliance.
- Record each clause in a table: SIP/section; normative strength (must/should/may or exact wording); applicable component; code location; positive/negative test; result (pass, fail, not applicable, unverified); explanation.
- A 'should' deviation is not a 'must' violation. Separate mandatory violations, recommendation deviations and security issues; keep ordinary application bugs separate from standards violations even when both need repair. Do not silently strengthen a recommendation because an audit report called it noncompliance.
- Use the official test vectors for serialization/signing; assert balance/supply/owner invariants for assets. Test direct and contract-mediated callers on the selected network, since standard users include other protocols. Default to Clarigen-generated calls backed by the Clarinet SDK. A contract test cannot prove a wallet's transaction postconditions.
- Reuse a verified deployed trait where appropriate, verifying network principals against the system addresses; SIP-listed testnet examples may no longer exist. Resolve relative names in the deployment context; compile with the selected language/epoch, then test behavior.
- When sources conflict, quote only the short disputed clause, pin both sources, and mark the affected conclusion unverified until the version-matched implementation/test resolves it.
- Deliver the conformance matrix, changes, executed tests and evidence gaps (unresolved remote metadata, missing transaction-level tests, unverified deployments). Limit claims to the inspected scope/version; explain intentional extensions and consumer effects.
References
- Catalog: dated SIP numbers, titles, status and paths.
- SFT post-conditions: FT plus tag-NFT mirror, client conditions, recipient tags and tests.
Reference baseline
Examples use Clarity 4+ syntax unless marked, checked on epoch 4.0. Source links in this skill and its references use these pins; links into sibling skills use their owner's SKILL.md.
stacks-core: ccf31dc69c.sips: 642af6804d.stx-semi-fungible-token: 2b6206b106, the SIP-013 reference implementation.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

