Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
LABS
Glossary

Natural Language Specification

A Natural Language Specification (NLS) is a human-readable document that precisely defines the requirements, logic, and behavior of a smart contract, serving as the single source of truth for both legal review and code development.
Chainscore © 2026
definition
BLOCKCHAIN DEVELOPMENT

What is a Natural Language Specification?

A foundational document that translates complex protocol logic into human-readable rules, serving as the source of truth for formal verification and smart contract implementation.

A Natural Language Specification (NLS) is a comprehensive, human-readable document that describes the intended behavior, rules, and security properties of a blockchain protocol or smart contract system in plain English or another natural language. It acts as the authoritative source of truth, bridging the gap between high-level design intent and low-level code. Unlike technical whitepapers or API docs, an NLS is structured with the explicit goal of being unambiguous and testable, enabling formal methods like verification and audits. This process is crucial for systems where correctness is paramount, such as decentralized finance (DeFi) protocols or consensus mechanisms.

The core purpose of an NLS is to enable formal verification. Engineers use tools to translate the natural language rules into machine-checkable formal models, often written in languages like TLA+ or Coq. These models are then rigorously proven to satisfy the system's security invariants and liveness properties. Any discrepancies between the NLS and the formal model must be resolved, ensuring the specification is logically consistent. Subsequently, the final smart contract code (e.g., in Solidity or Rust) is verified against this formal model, creating a verifiable chain of correctness from human intent to deployed bytecode.

Creating a high-quality NLS requires meticulous attention to detail. It must define all system state variables, invariants (conditions that must always hold), and transitions (how state changes in response to actions or messages). For example, an NLS for a lending protocol would specify rules for collateralization ratios, liquidation logic, and interest accrual with no room for implementation ambiguity. This discipline forces designers to confront edge cases and implicit assumptions early in the development process, significantly reducing the risk of critical bugs that could lead to financial loss or system failure post-deployment.

The practice of using Natural Language Specifications is a hallmark of high-assurance blockchain engineering. Projects like the Ethereum consensus layer (the Beacon Chain), major DeFi protocols, and other critical infrastructure increasingly adopt this methodology. It represents a shift from "code as law" to "specification as law," where the executable code is merely a verified implementation of the canonical rules. This approach enhances security, improves auditability, and provides clear documentation for developers building on top of the protocol, making the entire system more robust and trustworthy.

purpose-and-role
FOUNDATIONAL CONCEPT

Purpose and Role in Smart Contract Development

A Natural Language Specification (NLS) is a human-readable document that defines the intended behavior, rules, and constraints of a smart contract system before any code is written.

The primary purpose of a Natural Language Specification is to create a single source of truth that bridges the communication gap between stakeholders—including product managers, auditors, and developers—and the final smart contract code. It acts as a formal, yet non-technical, blueprint that explicitly states what the system should do, its business logic, access controls, state transitions, and failure modes. This document is crucial for aligning all parties on the system's requirements and expected outcomes before a single line of Solidity or Vyper is written, reducing costly misunderstandings and rework.

In the development lifecycle, the NLS serves as the foundational artifact for several critical processes. Developers use it to guide implementation, ensuring the code faithfully reflects the agreed-upon rules. Security auditors rely on it as a benchmark to verify that the contract's behavior matches its intended design and to identify logic flaws or deviations. Furthermore, it forms the basis for creating formal specification languages like Act or Scribble, and for generating test cases and invariant checks for tools like fuzzing and symbolic execution. This creates a verifiable link from human intent to machine execution.

A well-structured NLS typically includes several core components: a clear definition of all actors and roles (e.g., owner, minter, user), the precise state variables and their permissible changes, the complete set of functions with their pre-conditions and post-conditions, and a detailed description of all possible events and error states. For example, a specification for a decentralized lending protocol would meticulously define the rules for calculating collateral ratios, the conditions for liquidations, and the exact mechanics of interest accrual, leaving no room for ambiguous interpretation.

The role of the NLS extends beyond initial development into long-term maintenance and compliance. It provides essential documentation for future developers who need to understand or upgrade the system, serving as a historical record of design decisions. In regulated environments or for decentralized autonomous organizations (DAOs), the NLS can function as a transparent public record of the system's governing rules, allowing users to verify its operation independently. This emphasis on clarity and auditability makes the Natural Language Specification a cornerstone of professional and secure smart contract engineering.

key-features
ARCHITECTURE

Key Features of a Natural Language Specification

A Natural Language Specification (NLS) is a formal, human-readable document that defines the core logic and constraints of a smart contract system. It serves as the single source of truth, bridging the gap between high-level intent and executable code.

01

Human-Readable Abstraction

An NLS abstracts away low-level Solidity or Vyper syntax, expressing contract logic in plain English (or other languages). This makes the system's intended behavior accessible to non-developers like auditors, product managers, and legal teams. For example, a rule like "Only the contract owner can pause minting" is stated directly, rather than being buried in modifier code.

02

Formalized Business Logic

The specification codifies all business rules, state transitions, and access controls in a structured format. It explicitly defines:

  • Pre-conditions required for an action.
  • Post-conditions guaranteed after an action.
  • Invariants that must always hold true (e.g., "total supply equals sum of all balances"). This creates an unambiguous blueprint for developers to implement and for tools to verify.
03

Single Source of Truth

The NLS acts as the canonical reference that all other artifacts—smart contract code, tests, documentation, and formal verification models—are derived from and checked against. This eliminates discrepancies between what the code does and what the team thinks it does, a common source of vulnerabilities.

04

Toolchain Integration

Specifications are designed to be machine-parsable, enabling integration with a development and security toolchain. Tools can:

  • Generate skeleton code or tests from the spec.
  • Verify that the compiled bytecode satisfies the spec's constraints via formal verification.
  • Monitor protocol activity for violations of specified invariants in production.
05

Example: Token Transfer Rule

A concrete example of an NLS rule for an ERC-20 transfer:

Rule: transfer

  • Pre-condition: Caller's (msg.sender) token balance ≥ amount.
  • Post-condition: Caller's balance decreases by amount; recipient's balance increases by amount; total supply is unchanged.
  • Invariant: Sum of all balances always equals total supply.

This plain-language rule can be directly translated into code and mathematically verified.

06

Contrast with Traditional Documentation

Unlike standard documentation or code comments, which can become outdated, an NLS is executable and verifiable. It is maintained as a primary artifact, not an afterthought. While comments describe how code works, a specification defines what the system must do and why, enabling a shift from testing for known bugs to proving the absence of whole classes of errors.

how-it-works-process
THE ENGINEERING PIPELINE

How It Works: The Specification-to-Code Process

This section details the systematic pipeline for transforming high-level protocol designs into secure, executable smart contract code.

The specification-to-code process is a formal engineering methodology that translates a natural language specification—a human-readable document detailing a protocol's rules, behaviors, and security properties—into verifiable smart contract code. This process is critical for reducing ambiguity, preventing implementation errors, and establishing a single source of truth for developers and auditors. It typically involves stages of formalization, design, implementation, and verification, ensuring the final code is a faithful and secure execution of the original design intent.

The journey begins with the natural language specification, which serves as the authoritative requirements document. This document defines the protocol's state variables, the precise logic for state transitions (e.g., minting, swapping, staking), all invariants that must always hold, and explicit security guarantees. A high-quality specification is unambiguous, comprehensive, and structured, often using pseudocode and mathematical notation to clarify complex logic. This document becomes the benchmark against which all subsequent artifacts are measured.

From the specification, engineers create more formal models, such as state machines or mathematical models, to capture the protocol's logic in a structured, analyzable format. This intermediate step helps identify edge cases, logical contradictions, or missing requirements before a single line of Solidity or Move is written. Tools like TLA+ or Alloy can be used for model checking, providing a higher-confidence blueprint for the implementation phase and forming the basis for later formal verification efforts.

The implementation phase involves writing the actual smart contract code in a language like Solidity, aiming for a direct, readable translation of the formal model. Property-based testing and fuzzing are employed extensively during this stage, using the specification's invariants to generate thousands of random transactions and state configurations, searching for violations. Concurrently, auditors review the code against the specification, a process greatly streamlined by having a clear, shared document detailing intended behavior.

The final, rigorous stage is formal verification, where mathematical proofs are constructed to demonstrate that the compiled bytecode satisfies the critical properties and invariants laid out in the original specification. This may involve using tools like Certora Prover or Halmos to prove that, for all possible inputs and states, the code cannot enter an invalid state or break a defined security property. This creates a cryptographically strong link between the human-readable design and the on-chain contract, representing the highest standard of correctness assurance in blockchain development.

core-components
NATURAL LANGUAGE SPECIFICATION

Core Components of an NLS Document

A Natural Language Specification (NLS) is a structured document that defines the parameters, logic, and intent of a smart contract or protocol in human-readable terms. These components provide the critical link between high-level requirements and executable code.

01

Protocol Intent & Purpose

The foundational component that defines the high-level goal and business logic of the system. It answers why the contract exists, not how it works. This section includes:

  • The primary function (e.g., "This contract facilitates peer-to-peer lending")
  • The intended users and their roles (Lenders, Borrowers, Liquidators)
  • The core value proposition and problem being solved
  • Any overarching design principles or constraints (e.g., "must be non-custodial")
02

State Variables & Data Model

Defines the persistent storage of the contract—the data it remembers. This is the contract's "memory." It specifies:

  • State Variables: Named storage slots (e.g., totalSupply, userBalances)
  • Data Types: Their Solidity/Vyper types (uint256, address, mapping)
  • Initial Values: The state at deployment (e.g., owner = msg.sender)
  • Access Control: Which functions can read or write each variable (public, private, internal)
03

Function Specifications

The executable actions users and other contracts can perform. Each function is defined by:

  • Signature: Name and parameter list (function deposit(uint256 amount))
  • Visibility & Mutability: (public, external, view, payable)
  • Pre-conditions: Requirements that must be true before execution (e.g., caller must have sufficient balance)
  • Post-conditions: Guarantees true after execution (e.g., user's balance increases by *amount*)
  • Effects: All state changes and events emitted
04

Events & Logs

Defines the off-chain signaling mechanism for state changes. Events are the primary way dApp front-ends and indexers track contract activity. This section specifies:

  • Event Declarations: Name and indexed parameters (event Transfer(address indexed from, address indexed to, uint256 value))
  • Emission Triggers: Which functions emit which events and under what conditions
  • Data Payload: The meaning of each parameter in the event
  • Use Cases: How external systems should consume these logs (e.g., for UI updates or analytics)
05

Error Definitions & Revert Conditions

Formalizes the failure modes and safety checks of the contract. This moves beyond simple require() statements to document the intent behind each check. It includes:

  • Custom Error Types: Modern Solidity error declarations (error InsufficientBalance())
  • Revert Conditions: The precise scenarios that will cause a transaction to fail
  • Error Messages: Human-readable strings or error codes for debugging
  • Invariants: System-wide properties that must always hold true (e.g., totalSupply == sum of all balances)
06

External Dependencies & Interfaces

Documents all interactions with other contracts and systems, which are a major source of complexity and risk. This covers:

  • Imported Interfaces: Other contracts this one calls (IERC20, IOracle)
  • Trust Assumptions: What is assumed about those external contracts (e.g., "oracle is assumed to provide accurate prices")
  • Integration Points: How data flows in and out (function calls, callbacks)
  • Upgrade Paths: If the contract is upgradeable, the mechanism and admin controls
DOCUMENT TYPE COMPARISON

NLS vs. Other Documents

A comparison of the Natural Language Specification (NLS) with other common documentation formats used in software and protocol development.

Feature / MetricNatural Language Specification (NLS)Traditional API DocsCode CommentsFormal Specification

Primary Purpose

Define system behavior for AI and human readers

Guide developer implementation

Explain code logic to developers

Provide mathematically rigorous system definition

Audience

AI Agents, Developers, Analysts, CTOs

Developers, Integrators

Developers

Researchers, Protocol Designers

Structure

Structured, templated, versioned

Often ad-hoc or auto-generated

Inline with code

Mathematical notation, formal logic

Machine Parsability

Single Source of Truth

Change Management

Version-controlled, auditable

Manual updates, often outdated

Tied to code commits

Version-controlled, rigorous

Ambiguity

Minimized via templates & validation

High, relies on author clarity

High, informal

Minimized, formally defined

Typical Creation Time

2-4 hours per endpoint

1-2 hours per endpoint

< 30 minutes

Days to weeks per component

benefits
NATURAL LANGUAGE SPECIFICATION

Key Benefits and Advantages

Natural Language Specification (NLS) transforms human-readable requirements into formal, executable code, bridging the gap between business logic and technical implementation.

01

Enhanced Developer Productivity

NLS automates the translation of business rules into smart contract code, drastically reducing manual coding time and potential for human error. Developers can focus on architecture and optimization rather than repetitive boilerplate.

  • Rapid Prototyping: New features can be specified and deployed in hours instead of days.
  • Reduced Debugging: Formal logic derived from unambiguous specifications has fewer logical flaws.
02

Unambiguous Business Logic

By requiring precise, structured natural language, NLS eliminates the ambiguity inherent in traditional requirements documents. This creates a single source of truth for both technical and non-technical stakeholders.

  • Formal Verification: Specifications can be mathematically verified for correctness before code generation.
  • Clear Audit Trail: Every line of generated code can be traced back to a specific requirement statement.
03

Improved Security & Reliability

Code generated from a verified specification is inherently more secure and reliable. The formal model allows for exhaustive testing of edge cases and security properties that are difficult to catch manually.

  • Vulnerability Reduction: Eliminates common coding mistakes like integer overflows or reentrancy bugs at the specification level.
  • Deterministic Output: The same specification always produces the same, predictable bytecode.
04

Seamless Stakeholder Collaboration

NLS acts as a collaboration layer where product managers, auditors, and developers can review, debate, and finalize logic in a common language. This reduces miscommunication and costly post-deployment changes.

  • Accessible Review: Non-coders can validate the logic that will govern financial transactions.
  • Governance Integration: Specification changes can be tied directly to on-chain governance proposals.
05

Formal Verification Integration

NLS specifications are structured inputs for formal verification tools. Properties like "no loss of funds" or "correct interest accrual" can be defined in the spec and proven mathematically, providing the highest level of assurance.

  • Property Specification: Security guarantees are defined alongside business logic.
  • Automated Proof Generation: Tools like model checkers and theorem provers use the spec to verify the generated code.
06

Standardization & Interoperability

NLS promotes standardization of common DeFi primitives (e.g., lending, swaps, options). Specifications for standard components can be shared, audited once, and reused across projects, increasing ecosystem security and composability.

  • Composable Primitives: Verified, spec-driven contracts are trusted building blocks for complex protocols.
  • Cross-Protocol Audits: Auditors can review the specification instead of (or in addition to) the implementation code.
ecosystem-usage
NATURAL LANGUAGE SPECIFICATION

Ecosystem Usage and Applications

Natural Language Specification (NLS) transforms plain English into executable on-chain logic. This section details its core applications for developers and protocols.

01

Smart Contract Abstraction

NLS allows developers to define complex DeFi interactions without writing low-level Solidity or Vyper code. By describing intent in plain English, the specification is compiled into bytecode for deployment. This lowers the barrier to entry and reduces the risk of smart contract vulnerabilities introduced by manual coding errors.

  • Example: "Transfer 100 USDC to Alice if the ETH price is above $3,000."
  • Key Benefit: Enables rapid prototyping and auditability of contract logic.
02

Automated On-Chain Execution

NLS powers automated agents or keepers that monitor blockchain conditions and execute transactions when predefined logic is met. This is the foundation for decentralized limit orders, stop-losses, and recurring payments.

  • Core Mechanism: An off-chain oracle or indexer watches the chain, triggering execution via a relayer when the NLS conditions are satisfied.
  • Use Case: "Swap 1 ETH for DAI every Friday at 12 PM UTC at the best available price."
03

Portfolio Management & Vaults

Yield aggregators and structured product protocols use NLS to create dynamic, rule-based investment strategies. Users can deposit funds into a vault governed by an NLS that automatically rebalances assets or harvests rewards based on market conditions.

  • Strategy Example: "If APY for Compound drops below 5%, move 50% of funds to Aave."
  • Advantage: Allows for sophisticated, hands-off DeFi strategies accessible to non-technical users.
04

Governance & DAO Automation

Decentralized Autonomous Organizations (DAOs) utilize NLS to codify governance rules and automate treasury management. Proposals can specify executable actions that are carried out automatically upon passing a vote, removing manual implementation delays.

  • Application: "If governance proposal #123 passes, transfer 10,000 USDC from the treasury to grant recipient 0xABC..."
  • Impact: Increases transparency and execution speed for on-chain governance.
05

Cross-Chain & Multi-Protocol Logic

NLS can define workflows that span multiple blockchains and DeFi protocols within a single specification. This enables complex cross-chain arbitrage, bridging operations, and composability without requiring users to manually interact with each protocol.

  • Example: "When ETH on Arbitrum is 0.5% cheaper than on Base, bridge 10 ETH and swap for USDC."
  • Enabler: Relies on cross-chain messaging and oracle networks for data and execution.
06

Compliance & Conditional Transfers

Institutions and regulated DeFi projects can use NLS to enforce compliance rules directly on-chain. Transfers or interactions can be gated by conditions related to identity (KYC), jurisdiction, or transaction patterns.

  • Implementation: "Allow this transfer only if the recipient's credential NFT is valid and the amount is under $10,000."
  • Benefit: Embeds regulatory and business logic into the transaction layer itself.
security-considerations
NATURAL LANGUAGE SPECIFICATION

Security and Quality Considerations

A Natural Language Specification (NLS) is a formal, human-readable document that defines a smart contract's intended behavior, serving as a single source of truth for developers, auditors, and users. It bridges the gap between high-level requirements and low-level code.

01

Core Purpose: The Single Source of Truth

The primary function of an NLS is to establish an unambiguous, canonical reference for a protocol's logic. This document is the definitive guide for what the system should do, separate from the implementation code. It serves as the foundation for formal verification, manual audits, and test generation, ensuring all stakeholders are aligned on the intended behavior before a single line of Solidity is written.

02

Mitigating Specification-Implementation Gaps

A critical security risk in smart contract development is the divergence between the intended design and the actual code. An NLS directly addresses this by:

  • Providing auditors with a clear benchmark against which to compare the implementation.
  • Enabling the generation of comprehensive test suites that cover all specified behaviors.
  • Reducing ambiguity that can lead to developer errors or misunderstandings during protocol upgrades.
03

Formal Verification Foundation

An NLS, often written in a logic-based language, is the essential input for formal verification tools. These tools mathematically prove that the smart contract's code correctly implements every property and invariant defined in the specification. This process can eliminate entire classes of bugs (e.g., arithmetic overflows, reentrancy in specified functions) that are difficult to catch with testing alone.

04

Auditability and Transparency

A well-written NLS dramatically improves auditability. It allows security researchers to understand system invariants and complex business logic without reverse-engineering bytecode. This transparency builds trust with users and the community, as the protocol's core rules are explicitly documented in a structured, reviewable format, not hidden within the code.

06

Limitations and Complementary Practices

An NLS is not a silver bullet. Key considerations include:

  • Specification Correctness: The NLS itself must be correct and complete; a bug in the spec leads to a bug in the verification.
  • Coverage: It must specify all critical security properties and invariants.
  • Complementary Tools: NLS and formal verification are most effective when combined with manual expert review, fuzzing, and static analysis to catch issues the spec may have missed.
NATURAL LANGUAGE SPECIFICATION

Frequently Asked Questions (FAQ)

Natural Language Specification (NLS) is a framework for structuring on-chain data to make it easily queryable by AI. These questions address its core concepts, implementation, and practical use cases.

A Natural Language Specification (NLS) is a structured, machine-readable data format that translates blockchain events and smart contract state into a form that can be easily queried and understood by large language models (LLMs) and other AI agents. It works by defining a standardized schema for on-chain data, including entities, relationships, and semantic labels, which acts as a translation layer between raw blockchain data and natural language queries. This allows developers to ask questions like "Show me the top liquidity pools on Uniswap V3" without needing to write complex, protocol-specific code. The NLS framework typically involves indexers that populate the schema and a query engine that interprets natural language to fetch the structured data.

further-reading
NATURAL LANGUAGE SPECIFICATION

Further Reading and Resources

Explore the core concepts, technical specifications, and community resources that define the Natural Language Specification (NLS) standard for blockchain.

05

The Problem of Opaque Signatures

Understand the critical security issue NLS solves. Before NLS, users often signed hex-encoded data blobs with no context, leading to phishing and unintended approvals. This card explains the 'blind signing' problem and how NLS acts as a verified source of truth for off-chain data interpretation.

ENQUIRY

Get In Touch
today.

Our experts will offer a free quote and a 30min call to discuss your project.

NDA Protected
24h Response
Directly to Engineering Team
10+
Protocols Shipped
$20M+
TVL Overall
NDA Protected Directly to Engineering Team