Skip to content

Latest commit

 

History

28 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ClauseLens

AI document forensics on GenLayer Studio Network.

ClauseLens lets you paste any document — a Terms of Service, a whitepaper, a governance proposal, an airdrop announcement — & have it analyzed by independent LLM validators on GenLayer. The validators reach consensus on the document's hidden manipulation, surface specific dangerous clauses, & expose buried risks that lawyers, marketers, & whitepaper authors hide in plain sight.

Where traditional blockchains can only verify deterministic computation, GenLayer validators can reason about intent. ClauseLens turns that capability into a forensic tool.

🔗 Live: Deployed at clauselens.vercel.app (URL coming soon) 📜 Contract: 0x5e7f754A8541bB9ece96c35Cd8864Bd66FC40179 on GenLayer Studio Network 🔍 Explorer: View contract on Studio


What it does

Each analysis produces:

  • Document type — auto-detected (ToS, Whitepaper, Governance Proposal, Airdrop Rules, Privacy Policy, Pitch Deck, etc.)
  • Manipulation score (0-100) — how predatory or coercive the language is
  • Clarity score (0-100) — how transparently the document explains itself
  • Jargon Inflation score (0-100) — how much technical or marketing jargon obscures meaning
  • Hidden risk level — Low / Medium / High / Critical
  • Human-readable explanation — what the document actually means, in plain English
  • Danger flags — specific quotes from the document paired with why they're concerning
  • Intent ambiguity (0-100): the model's own confidence about how clear the document's intent is, surfaced on-chain via consensus. It is the model's self-assessment, not a measurement of how much validators diverged

Intent ambiguity is a distinctive signal. A predatory ToS reads as clear intent (the manipulation is obvious). An ambiguous whitepaper reads as high ambiguity (the intent is genuinely subjective). This value is the model's self-assessed confidence about intent, run through GenLayer consensus rather than taken from a single call. It is not a measurement of validator-to-validator divergence.

External-evidence verification (V3)

Beyond analyzing a document in isolation, ClauseLens can verify a claim against a live external source. The contract fetches the evidence URL itself, then independent validators read whether the evidence supports the claim and reach consensus on a verdict (Supported, Contradicted, Not addressed, or Insufficient).

Each verification produces a content-addressed receipt:

  • request_id: sha256 of the claim, the URL, and the evidence hash. Identical inputs return the same receipt (idempotent).
  • evidence_hash: sha256 of the exact fetched evidence, so a receipt provably binds to what was read.
  • model_confidence (0-100): the model's self-reported confidence in the verdict.
  • model_uncertainty (0-100): 100 minus that confidence. It is the model's self-assessment, not measured validator divergence.
  • model_counter_argument: a one-sentence, model-generated case for a different verdict.

Architecture

Smart Contract

Single Python contract at contracts/clauselens.py. Uses gl.eq_principle.prompt_comparative to delegate document analysis to GenLayer's validator quorum. Validators each generate a structured JSON analysis & reach consensus before the result is persisted to chain storage.

Key methods:

  • analyze_document(text) — write method, takes a document, returns nothing (analysis ID is derived from the auto-incrementing counter)
  • get_analysis(id) — view, returns the full analysis JSON for a specific ID
  • get_all_analyses() — view, returns all analyses
  • get_analysis_count() — view, returns total analyses

Frontend

Vite + React + TypeScript + genlayer-js v1.x + viem v2 + MetaMask. Single-page dApp at frontend/. Connects to MetaMask, switches to Studio (chainId 61999), submits documents to the contract, polls for consensus results, & renders them in a forensic-intelligence-themed UI.


A note on Bradbury storage bug (May 2026) & migration to Studio Network

During contract development on Bradbury, we hit a non-obvious bug worth documenting for future GenLayer builders. After hitting repeated contract resets on Bradbury (a known testnet behavior), we migrated to GenLayer Studio Network where this dApp is now hosted.

Symptom: A write method that called gl.eq_principle.prompt_comparative(...) would have its transaction reported as ACCEPTED by the consensus layer, but no storage writes would commit. get_analysis_count() would return 0 even after dozens of successful analyze_document transactions.

Root cause: Reading gl.message.sender_address or gl.block.timestamp inside a write method that also called the equivalence principle caused a silent storage rollback after consensus completed. The TX itself succeeded; the writes never persisted.

Workaround:

  1. Don't read gl.message.* or gl.block.* inside any write method that uses an equivalence principle. Capture submitter & timestamp on the client side instead (we use localStorage).
  2. Don't use @allow_storage @dataclass containers wrapping TreeMap. Use parallel flat TreeMap[str, str] & TreeMap[str, u64] structures keyed by analysis ID instead.

This was diagnosed by building progressively-simpler smoke-test contracts (smoketest, smoketest2, etc.) until the failure pattern isolated. If you're seeing TXs accepted with no storage commits, this is probably why.


Running locally

Prerequisites

  • Node.js 18+ & npm
  • MetaMask browser extension
  • A wallet funded with GEN tokens on GenLayer Studio Network (get test tokens from the faucet in your account selector at studio.genlayer.com)

Setup

git clone https://github.com/DaveDave-infosec/clauselens.git
cd clauselens/frontend
npm install
npm run dev

Open http://localhost:5173. Connect MetaMask, switch to Studio Network, paste a document, click Analyze.

Environment variables (optional)

# frontend/.env
VITE_CONTRACT_ADDRESS=0x5e7f754A8541bB9ece96c35Cd8864Bd66FC40179

The contract address defaults to the deployed one if not set.


Tech stack

  • Smart contract: GenLayer Python SDK (py-genlayer:1jb45aa8ynh2a9c9xn3b7qqh8sm5q93hwfp7jqmwsfhh8jpz09h6)
  • Frontend: Vite 5, React 18, TypeScript, viem 2.x, genlayer-js 1.x
  • Wallet: MetaMask via window.ethereum
  • Hosting: Vercel
  • Chain: GenLayer Studio Network (chainId 61999)

License

MIT — see LICENSE.


A note on privacy

ClauseLens stores all analyses on a public blockchain. Anyone can call get_all_analyses() on the contract & see every document analyzed through this contract, along with the submitting wallet address. The "My View" filter in the UI hides others' analyses from your view as a convenience, but the data itself is public. If you need genuinely private document analysis, this is not the right tool.


Built by @ybndave on GenLayer.

About

AI document forensics on GenLayer Bradbury. Paste any document & watch independent LLM validators reach consensus on its hidden manipulation.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages