Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Validation and Analysis

Clarinet provides tools for validating, analyzing, linting, and debugging your smart contracts. From static type checking to real-time cost analysis, you can check your contracts for errors and costs before deployment.

Contract validation spans static analysis, runtime debugging, and cost optimization.

Understanding contract validation

Static analysis vs. runtime debugging

Static analysis
Runtime debugging

Catches issues before deployment

Reveals behavior during execution

Flags type mismatches and syntax errors

Shows actual execution costs

Ensures trait compliance

Exposes state changes and side effects

Detects undefined variables

Highlights transaction flow

Validates function signatures

Surfaces performance bottlenecks

Static analysis

Run validation with clarinet check:

Successful output resembles:

When validation fails, Clarinet prints diagnostics:

1

Run basic checks

Use clarinet check to validate your contracts and catch type/syntax errors before deployment.

2

Check a specific contract

Focus validation during development on a single contract file:

Clarinet applies the [linter] settings from the Clarinet.toml given with --manifest-path, or from the nearest Clarinet.toml above the current directory. If there is no manifest, it uses the default lints. The project's include and exclude filters do not apply to a file you name explicitly.

3

Integrate into CI

Automate validation in continuous integration pipelines. Example GitHub Actions workflow:

Validation scope

Clarinet validates multiple aspects of your contracts:

Validation type
What it checks

Type safety

Function parameters, return values, variable types

Trait compliance

Implementation matches trait definitions

Response consistency

ok/err branches return the same types

Variable scope

Variables defined before use

Function visibility

Proper use of public, private, and read-only

clarinet check --output=<format>

Add the --output=<format> option to clarinet check to print diagnostics as JSON or other formats. LLMs and other tools can parse this output. Currently supported formats are standard, json, and jsonpretty.

Linter analysis

Clarinet includes a built-in linter as part of clarinet check that flags common mistakes, inefficiencies, and unused code in Clarity contracts.

Clarinet 4.0 has 24 lints in five groups:

  • correctness: code that is certainly wrong

  • unused: dead code

  • perf: inefficient code

  • safety: code that might not do what you intended

  • style: naming conventions

You can configure each lint on its own or through its group. The correctness lints are the exception: you cannot configure them.

Identifier
Description
Lint group

call_checker

Detects calls that pass the wrong number of arguments to a function.

correctness

unused_binding

Detects unused function parameters and let bindings.

unused

unused_const

Detects unused define-constant declarations.

unused

unused_data_var

Detects define-data-var declarations that are never used, never read, or never written (a value that is never written can be a constant).

unused

unused_map

Detects define-map declarations that are never accessed.

unused

unused_private_fn

Detects private functions that are never called.

unused

unused_token

Detects fungible and non-fungible tokens that are never minted.

unused

unused_trait

Detects traits imported with use-trait that are never used as parameter types.

unused

flatten_variadic

Suggests flattening nested calls to a variadic function, for example (+ a (+ b c)) to (+ a b c). From Clarity 6 this includes concat, which became variadic.

perf

unnecessary_as_max_len

Detects unnecessary as-max-len? calls.

perf

unnecessary_public

Detects public functions that could be read-only because they change no state.

perf

unnecessary_tuple

Detects tuples with a single field.

perf

at_block

Warns about uses of at-block, which is proposed for removal.

safety

error_const

Checks that every ERR_ constant is an (err ...) value and that no two ERR_ constants share a value.

safety

noop

Detects expressions that have no effect, such as (is-eq 1).

safety

panic

Warns about unwrap-panic and unwrap-err-panic.

safety

renamed_builtin

Detects calls to a builtin that a later Clarity version renamed. The one rename today is with-stacking to with-staking (Clarity 6); the old spelling keeps working in Clarity 4 and 5 contracts.

safety

case_binding

Enforces kebab-case on let bindings and function argument names.

style

case_const

Enforces SCREAMING_SNAKE_CASE on constants.

style

case_data_var

Enforces kebab-case on data variables.

style

case_fn

Enforces kebab-case on function names.

style

case_map

Enforces kebab-case on maps.

style

case_token

Enforces kebab-case on fungible and non-fungible token names.

style

case_trait

Enforces kebab-case on trait names.

style

Bypassing the linter

Code can look unused when it is used in a way the linter can't see. Examples include private functions used only in tests, or bindings whose evaluation has side effects.

Clarinet follows a convention similar to Rust: the linter allows identifiers with a trailing _ (a leading _ does not work) to be unused, but other lints still apply to them.

Individual lints can also be disabled for a specific line using Clarity's annotation syntax:

Configuration

By default, lints in the unused, perf and safety groups report at the warning level and style lints at the notice level. Change the level per lint or per group in the [linter] section of Clarinet.toml.

Lints in the correctness group always report at the error level and reject the contract. [linter] settings do not change them: call_checker = "warning", correctness = false and all = false have no effect on these lints.

Each value is a level ("error", "warning" or "notice"), false or "off" to turn the lint off, or true or "on" to turn it on at its default level. A lint that is already on keeps its current level, so style = true gives notices, not warnings. To get warnings, set "warning" explicitly.

Files to analyze

Individual lint configuration

Lint group configuration

Migrating from Clarinet 3.x

Clarinet 4.0 moved the linter settings out of [repl.analysis]. Rename [repl.analysis.lints] to [linter.lints] and [repl.analysis.lint_groups] to [linter.groups]. Clarinet 4.0 also removed the check-checker pass, so remove passes = ["check_checker"] and the [repl.analysis.check_checker] settings. Clarinet warns when Clarinet.toml still contains [repl.analysis] or an analysis key in [project].

The check-checker annotations #[filter(...)], #[allow(unchecked_data)] and #[allow(unchecked_params)] are still accepted, so existing contracts compile, but they have no effect.

Runtime analysis

The Clarinet console has commands for inspecting behavior during execution.

Cost analysis with ::toggle_costs

Turn on automatic cost display after every expression:

Execution tracing with ::trace

Trace function calls to understand execution flow:

Interactive debugging with ::debug

Set breakpoints and step through execution:

Common navigation commands:

  • step or s: step into subexpressions

  • finish or f: complete the current expression

  • next or n: step over subexpressions

  • continue or c: resume execution

Using ::get_costs for targeted analysis

Spotting costly operations with ::trace

Review the trace for loops with high iteration counts, nested map/filter operations, repeated contract calls, and large data structure manipulations.

Debugging workflows

Run ::debug to pause execution and show the current source location:

Analyzing failed transactions with ::trace

Using ::encode and ::decode for inspection

Testing time-dependent logic

Last updated

Was this helpful?