Security Trait Standards for Clarity: Access Control, Pausable Contracts & More

The Problem I Hit Building Glamora

I’m building Glamora, a decentralized fashion marketplace on Stacks that uses sBTC for payments. While writing the smart contracts, I had to implement security patterns from scratch.

Access control for admin functions? Wrote it myself across three contracts.
Input validation for every user action. Wrote it myself.
Authorization checks? Wrote it myself.

Then I realized every Clarity developer is doing this same work.

We all write our own access control. We all write our own input validation. We all write our own authorization logic. And some of us get it wrong.

This creates problems:

  • Duplicated work - Everyone writes the same security code over and over
  • Inconsistent security - My access control implementation isn’t the same as yours
  • More bugs - Custom security code = more surface area for vulnerabilities
  • Steeper learning curve - New devs need to understand security before they can build anything
  • Expensive audits - Auditors review the same basic patterns in every contract instead of focusing on business logic

What I’m Proposing

Create standardized security traits for Clarity the same way SIP-009 standardized NFTs and SIP-010 standardized tokens.

Here’s What It Looks Like

Today (what I actually wrote for Glamora):

;; From my glamora-nft.clar contract - access control I had to write myself
(define-data-var authorized-caller principal tx-sender)
(define-data-var admin principal tx-sender)

(define-public (set-authorized-caller (new-caller principal))
    (begin
        ;; Manual authorization check I wrote
        (asserts! (is-eq tx-sender (var-get admin)) ERR-NOT-AUTHORIZED)
        (var-set authorized-caller new-caller)
        (ok true)
    )
)

(define-public (create-fashion-collection ...)
    (begin
        ;; Authorization check I have to write in every function
        (asserts! (is-eq contract-caller (var-get authorized-caller)) ERR-NOT-AUTHORIZED)
        ;; ... rest of function
    )
)

What I want (standardized trait):

;; Just implement the standard
(impl-trait .sip-security.ownable)

(define-public (create-fashion-collection ...)
    (begin
        ;; Security handled by the trait
        (try! (assert-owner))
        ;; I just write my marketplace logic
    )
)

Same security, less code, already audited.

Which Security Patterns Matter

From my experience building Glamora (and planning for mainnet launch):

1. Access Control
I implemented this across glamora-nft.clar, storage.clar, and main.clar. Every contract has owner/admin checks. Almost every production contract needs “only the owner can call this function” but we all write it differently.

2. Input Validation
I validate tip amounts, collection sizes, category numbers, listing prices throughout Glamora. Each validation is custom-written. Everyone writing (asserts! (>= amount MIN-AMOUNT) ERR-INVALID-INPUT) in slightly different ways.

3. Pausable Contracts
Emergency stop mechanism. If something breaks in production, I need to pause operations. Right now, I’d have to redeploy everything. Any contract handling real money needs this.

4. Reentrancy Guards
Prevent functions from being called before they finish executing. I’m not sure if Clarity’s design already prevents this (maybe someone can clarify?), but every Solidity DeFi protocol has reentrancy guards. If Clarity needs them, they should be standardized.

5. Rate Limiting
Stop spam. Right now, nothing prevents someone from calling my mint function repeatedly in one transaction. As Glamora scales, I’ll need rate limiting on minting, tipping, and marketplace operations.

Why these 5? Because they’re not optional for production contracts handling real value. Every project building toward mainnet will need them.

Why Solidity Already Solved This (OpenZeppelin)

Professional Solidity developers stopped writing security primitives from scratch years ago. They use OpenZeppelin the library powering nearly every onchain application on Ethereum.

What OpenZeppelin does:

import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MyContract is ReentrancyGuard, Ownable {
  function withdraw() public onlyOwner nonReentrant {
    // Security handled by OpenZeppelin
  }
}

Why it works:

The result: Every serious developer leans on OpenZeppelin instead of rolling their own security code.

Clarity should have the same thing.

We Already Have the Foundation

Clarity already does this for tokens and NFTs:

  • SIP-009 - NFT trait standard (everyone implements this)
  • SIP-010 - Fungible token standard (everyone implements this)

These work. Contracts that implement SIP-009 are composable. Wallets know how to interact with them. It’s the right pattern.

Security traits are the next logical step.

Instead of:

(impl-trait .sip-009-nft-trait.nft-trait)

We’d also have:

(impl-trait .sip-security.ownable)
(impl-trait .sip-security.pausable)

Same pattern. Same benefits.

What This Actually Fixes

For developers like me:

  • Stop writing the same security code in every contract
  • Build faster (import security, write business logic)
  • Ship with more confidence (traits are audited, my custom code might not be)

For auditors:

  • See (impl-trait .sip-security.ownable) and move on
  • Spend time on actual business logic vulnerabilities
  • Cheaper, faster audits

For the ecosystem:

  • Fewer bugs (everyone uses the same vetted implementation)
  • Better composability (contracts using the same security traits work together cleanly)
  • Easier onboarding (new devs don’t need to be security experts to build safely)

What I’m Not Sure About

I’ve been building on Clarity for 2 years, but I’m still learning. Here’s what I don’t know:

  1. Does Clarity’s design already prevent some of these issues? Maybe reentrancy isn’t as dangerous in Clarity as it is in Solidity? I’d love to hear from folks who know the language internals better than me.

  2. Should these be separate SIPs or one umbrella proposal? Like “SIP-XXX: Security Traits” with multiple sub-traits?

  3. Who would maintain the reference implementations? Community? Hiro? Stacks Foundation?

  4. What am I missing? Is there a reason this hasn’t been done yet that I’m not seeing?

Real questions. I’m posting this to learn as much as to propose.

Why I’m Posting This

I’m building Glamora, a fashion marketplace on Stacks with sBTC payments. I’m a Stacks Ascent member and contributed to AMM security research through LearnWeb3’s Stacks Course 2.

When I needed access control and input validation for Glamora, I wrote them myself and hoped I didn’t mess up. As I iterate toward mainnet, I’ll need to add pausable contracts and rate limiting - and I’ll write those from scratch too.

If I’m doing this, other builders are too. And if we’re all writing our own versions, we’re all introducing different bugs.

This feels like something that should already exist.

I’m not trying to dictate how this should work I’m asking if the community thinks this is worth building. If yes, I’m happy to help make it happen.


Timothy Chimbiv
Building from Jos, Nigeria :nigeria:

Project: https://glamora-gold.vercel.app
GitHub: Terese678 (Timothy Terese Chimbiv) · GitHub
X: https://x.com/ter_chimbiv

6 Likes

note: moving to subcategory for SIP ideas to further incubate into a potential SIP PR.

@Terese thanks for the post!

4 Likes

Thanks @jwiley

I’m excited to see this in SIP Ideas. I’m particularly curious to hear from: Developers who’ve hit the same pain points I describe; those who know Clarity’s internals better than me or anyone who’s thought about security standardization before. I’m ready to iterate based on the community’s input.

2 Likes

I know @HeroGamer and a few others have been holding calls every friday for things like this. if you can join, i know they’d like to hear about your proposal:
from Events - Stacks Ecosystem :
https://www.addevent.com/event/ue20372724

3 Likes

This is a solid idea. Standardizing common security patterns as Clarity traits could reduce a lot of repeated code and prevent easy mistakes. Starting with a minimal, well-maintained set feels especially important.

2 Likes

Exactly. Start with what 80% of contracts need, my bet is access control and pausable. Make those work perfectly first.

What patterns are hitting you most in production?

3 Likes

Appreciate it @jwiley

I will join the discussion.

2 Likes

Love this!

I’m old school and came up in the world of Interfaces and things like IEnumerable being incredibly important.

The “trait” system needs a bit of work before fully leaning into things like using them as strict Interfaces as you talk about above.

Interesting fact, the “traits” are somewhat optional and inferred. For example, sBTC is considered a SIP-10 even though it does not implement the SIP-10 trait.

I’d focus on the trait system first, and then look into using it for actual interfaces like mentioned above after it has been hardened a bit.

NOTE: Implementing a trait just specifies that the contract has the defined functions available, they still need to be written into each contract. I think what you are looking for is the ability to inherit some base functionality into your contract, which is currently not something that Clarity supports.

3 Likes

I appreciate your feedback; you’re absolutely right about the trait limitations. Devs still write all implementations traits just verify signatures exist.

We can standardize the patterns which is what works now with composition then phase 2: reusable implementations when Clarity supports inheritance.

Your sBTC example is interesting shows the community values consistency in practice, not just formal trait implementation.

What’s your take on Phase 1 as a starting point?

3 Likes

1. Access Control

Maybe clarinet could do checks, but in general we can’t inherit through trait.

2. Input Validation

Again, clarity could help to streamline asserts, however, we can’t inherit.

3. Pausable Contracts

Could you explain what the pattern should be? We can have some core contracts that are the basis, and the top level can be paused and replaced.

4. Reentrancy Guards

Not applicable to Clarity.

5. Rate Limiting

Are there patterns that apply to more than your contract? What would that be?

4 Likes

MAJOR UPDATE: From Traits to Templates (Jan 21, 2026)

After incredible feedback from the Clarity WG (Setzeus, Friedger, Gary, Hero Gamer) and @friedger’s technical input, I’m refining this proposal:

New Name: Security Template Standardization

Refined Approach:

Traits verify function signatures (not code inheritance), combined with a three-layer system:

  1. Trait Definitions - Standard security interfaces developers implement (like SIP-009/010)
  2. Template Contracts - Audited copy-paste code for reference implementations
  3. Verification Registry - On-chain tracking of verified secure contracts

Key Advantages:

  • :white_check_mark: Works with current Clarity (no new features needed)
  • :white_check_mark: Mirrors proven SIP-009/010 pattern
  • :white_check_mark: Verifiable security (hash matching + trait implementation)
  • :white_check_mark: Practical for developers (copy template → implement trait → get verified)

Focused Scope (Phase 1):

  • Access Control (Ownable) - Standardized owner/admin patterns
  • Pausable Contracts - Emergency stop mechanisms

Dropping: Reentrancy (not needed in Clarity’s design), Rate Limiting (too contract-specific)


Next Steps:

  • Drafting reference template implementations
  • Preparing trait definitions
  • Will share for technical review before Feb 3 WG

@friedger @Setzeus @HeroGamer @Gary - Would love your thoughts on this refined direction.

3 Likes

A good example for a template contract is the xbtc token contract. See https://source-of-clarity-temp.lovable.app/contract/SP3DX3H4FEYZJZ586MFBS25ZW3HZDMEW92260R2PR.Wrapped-Bitcoin?line=202

4 Likes

Hi @Terese thanks for refining the idea

On the Tuesday 20th January Clarity Working Group call, I brought your forum post up for discussion.

  • We talked about your SIP you can watch the video playback, and the recap notes from that call - the senior devs gave really good feedback.
  • Ping me in Telegram for coordination support, or ping Gary in X for dev support.
  • And yes would be great to have you join the next Clarity Working Group on 3rd February to share your refined idea.
4 Likes

Interesting contrast with Ethereum: Solidity contracts compile to unreadable bytecode, so devs rely on OpenZeppelin’s trusted libraries? @Terese

On Stacks, contracts are on-chain readable source code — so a revamped Source of Clarity becomes even more valuable. @friedger

New devs can study battle-tested patterns directly rather than reinventing from scratch or blindly trusting libraries.

How’s your experience been so far building on Clarity? Did you get help from @HeroGamer

If you want a peer review on your contracts before going for a formal audit, happy to take a look — cheaper than audits and often catches valuable stuff. @Terese

1 Like

There is another one (co-authored by me some time ago :wink: )

https://source-of-clarity-temp.lovable.app/contract/SPC0KWNBJ61BDZRPF3W2GHGK3G3GKS8WZ7ND33PS.community-handles-v2?line=128

Exactly, Solidity bytecode has to be decompiled back to something readable that’s a whole technical process. Clarity’s readability is a huge advantage for security.

Building on Clarity has been great the readability makes a huge difference. You can look at the code and understand the logic immediately. That’s really powerful for security.

The goal is to standardize these patterns so devs don’t have to reinvent security every time. It will save time and reduce vulnerabilities.

I’d definitely appreciate a peer review of my contracts before formal audit. That would be valuable.

@HeroGamer shared some helpful resources, working through them now.

Thanks for offering support

2 Likes

@HeroGamer

Thanks for bringing this to the WG and sharing the resources.

See you Feb 3rd.

@friedger

Thanks for the xBTC example.

Got it, thanks

[UPDATE] Security Template Standardization: Ownable Pattern MVP Ready for Review

Today, I’m sharing the first working implementation: The Ownable Pattern.

What I Built

GitHub Repository: https://github.com/Terese678/clarity-security-templates

The repository includes:

Three core files:

  • ownable-trait.clar - Standard ownership interface

  • ownable-template.clar - Copy-paste reference implementation

  • example-dao-treasury.clar - Working demonstration (DAO treasury contract)

Comprehensive testing:

  • 12 automated tests (all passing)

  • Manual console verification

  • Detailed test report with security explanations

How It Works

Instead of writing custom ownership logic in every contract, developers can:

Step 1: Implement the trait

clarity

(impl-trait .ownable-trait.ownable-trait)

Step 2: Copy the template code (owner storage, helper functions, error codes)

Step 3: Protect admin functions with one line

clarity

(define-public (withdraw (amount uint))
    (begin
        (try! (assert-owner))  ;; Security checkpoint
        ;; Withdrawal logic here
    )
)

Public functions that anyone can call don’t need this check.

What This Solves

This pattern provides:

  • Standardized implementation (everyone uses the same tested code)

  • One-line protection for admin functions

  • Clear audit record (implement trait + use template = verifiable security)

  • Educational value (comprehensive tests show exactly how it works)

The Example: DAO Treasury

The example contract demonstrates the pattern with a simple DAO treasury:

Public functions (no ownership check):

  • donate - Anyone can contribute STX to the treasury

  • get-balance - Anyone can check the treasury balance

  • get-owner - Anyone can verify who owns the contract

Admin functions (ownership check required):

  • withdraw - Only owner can withdraw funds

  • set-owner - Only owner can transfer ownership

The tests prove:

  • Non-owners cannot access admin functions (security works)

  • Owners can execute admin operations (functionality works)

  • Ownership transfer is secure (old owner loses access immediately)

Why This Matters

The goal is to give Clarity developers battle-tested, standardized security code that doesn’t need to be written from scratch.

Repository: https://github.com/Terese678/clarity-security-templates
Detailed Test Report: Available in TEST_REPORT.md in the repo

Thanks to everyone who provided feedback on the original proposal. This wouldn’t exist without the guidance from the Clarity WG.

Timothy Chimbiv
Project: Glamora Fashion Marketplace
GitHub: https://github.com/Terese678
X: https://x.com/ter_chimbiv