慣性聚合 高效追讀感興趣之博客、新聞、科技資訊
閱原文 以慣性聚合開啟

推薦訂閱源

博客园 - 司徒正美
V
V2EX
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队
aimingoo的专栏
aimingoo的专栏
Apple Machine Learning Research
Apple Machine Learning Research
IT之家
IT之家
Blog — PlanetScale
Blog — PlanetScale
A
About on SuperTechFans
月光博客
月光博客
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
V
Visual Studio Blog
WordPress大学
WordPress大学
酷 壳 – CoolShell
酷 壳 – CoolShell
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python)
倘有供应商能自证其合于交易,而不必示人以底牌,将如何?
Niomi Langal · 2026-05-24 · via DEV Community

吾为君言,一奇之议,吾偶逢之。

试想之:企业购能者,欲确认氢气供应商持有认证绿能信用至少三千兆瓦时,方肯签购能之约。诚然。供应商持有此信用。其欲成此交易。遂示其实际库存之数。

彼时,室中顿生变。

盖今买者知供应商坐拥八千五百兆瓦时。忽而买者明察供应商之困窘。。杠杆已移。供应商之交易条件将恶化,无可奈何,因其已示其牌。

吾思此问题久矣。忽有所悟,此非交涉之题也。乃信息架构难题。供方欲言“是也,吾合之”,而毋言“且此其量之确也”。

此乃吾所建也H2Ledger(H2账本):此乃一去中心化之市集,用以交易绿氢信用凭证。供方可凭actualAmount >= threshold,以全然之密码学确证,向智能合约自证其能,而实际之数,永不得现于任何处。非于链上,非于证中,非于流转之际,无处可见。

。使此法得以施行之器,名曰零知识之证。,吾将示君其理,观其码,诚然,亦述吾所愿异行者。


未入其境:零知识证明者何?

吾誓此非闻之惊惧。

思之若此。设君之友以知保险箱密码相胁,君固辞不言其数。零知识证明者,实乃数学之约也,使君得胜此戏言。君使他方信某言为真,而隐其本末于不言。

更详言之,须有三事具:

  • 完满也 若尔所言非虚,且具密钥之正,则可恒产合宜之证。
  • 正确性: 若尔所言为妄,则伪证之合宜者不可得。数理使欺瞒之计于计算上难以为继。
  • 零知识: 检证之者所学者,惟此而已。 其真伪何如。别无他泄。

H2Ledger 之中,此言为 actualAmount >= threshold。密钥(名曰“证物”)乃 actualAmount。而验之者非人,乃 Solidity 智能合约,栖于 EVM 兼容之链上。

无需信约。无需中媒。惟数学而已。


真问题:绿氢信用市场实属堪忧

然“灾难”之词或过,然时下之状确实脆弱。

今氢信用市场所涉者:

  • 纸质认证之链。同证之信,可潜呈于众贾,涉诸议而无声。无人有共账以察之。
  • 散列之册,行于不协之规,无互操作之能。德之贾与智利之供,或持全异之证,无以验其隙。
  • 显明与晦暗,不可两全.将信用余额置于公链之上,则众敌皆可实时窥尔之货。藏于链外,则无信力之结算。必择其害焉.

零知识证明,使尔尽脱此跷跷板。得共享之账簿以结算其下人物之隐秘也。二者同时焉。


H2Ledger之实然运作:三层之图景

高视之,系统有三层相语:

[ Supplier (off-chain) ]
        |
        | Private: actualAmount (stays here, never transmitted)
        v
[ Circom Circuit + Groth16 Prover ]
        |
        | Outputs: proof.json (256 bytes) + public.json (threshold only)
        v
[ GreenHydrogenMarketplace.sol ]
        |
        | Delegates the heavy cryptographic check to:
        v
[ Verifier.sol ]  -->  true / false

入全景模式 出全景模式

供应商之实存,未尝离其机。链上流转者,乃二百五十六字节之证,及公钥之阈值也。智能合约验此证,确认其诚,乃易订单之状为已满。此乃结算之全流程也。


ZK回路:神妙之处渐入平淡(然甚佳)

回路者,即ZK证系统所验之程也。吾所撰者,以Circom 2.0者,实为专域之语,用以表算之为算术约束之系。此乃其核模:

template ThresholdVerification(n) {
    signal input actualAmount;    // Private: never leaves the prover's machine
    signal input threshold;       // Public: the buyer's stated minimum
    signal output isValid;        // 1 if actualAmount >= threshold, else 0

    // Uses LessThan from circomlib to prove:
    // NOT (actualAmount < threshold) = (actualAmount >= threshold)
}

入全景模式 出全景模式

若尔编译此,则生百二八 R1CS 约束于百九十三线。此诸约束之所为,实若此:

  • 其六十四者,皆能分解二者。actualAmountthreshold入其六十四位二进制之象。
  • 其余六十四者,施以逐位比较之法,以辨何数为大。

论六十四位之择:企业市场氢能之量,以兆瓦时计。六十四位之域,可容至2^64,其裕量约2^40,远超凡所交易之极。实无上限之虑。

Groth16之证者,取此电路、证物及仪式所设之证钥,于BN254上出三椭圆曲线群元。

π_a, π_b, π_c

入全景模式 出全屏模式

此三者在也其证也。若次第而列之,则恒恰得二百五十六字节,无论证词如何。此固定大小于实践确有裨益:燃气之费可预,ABI编码之洁,存储亦非问题。

生成证明,寻常之笔记本电脑约需一时至二时,皆于链外行之。区块链未睹其计算;唯睹其输出耳。


智能合约:权柄之控,实合情理

onlyOwner之陷

此乃吾初欲避之模式也。

多合约系统,常归于一onlyOwner 为每项特权操作之修饰。其简明,其有效。于单主系统,或可无碍。

然 H2Ledger 有三类迥异之主,其信条亦全然相异:生产者(持贷之供者),购买者(发采购令之公司),及验证代理。(链下认证之真伪者)。三者汇于单一之地址,遂成独断之枢纽,与全系统无信之根基大相径庭。

故作基于角色之访问层。每地址得赋四态之一:NONEPRODUCERVERIFIER_AGENTBUYER凡有敏感之能,必先验其司者之职。

pragma solidity ^0.8.0;
import "./Verifier.sol";

contract GreenHydrogenMarketplace {
    Verifier verifier;

    enum Role { NONE, PRODUCER, VERIFIER_AGENT, BUYER }

    mapping(address => Role) private roles;
    address public admin;

    modifier onlyRole(Role _required) {
        require(roles[msg.sender] == _required, "Access denied: insufficient role");
        _;
    }

    modifier onlyAdmin() {
        require(msg.sender == admin, "Access denied: not admin");
        _;
    }

    constructor(address _verifier) {
        verifier = Verifier(_verifier);
        admin = msg.sender;
    }

    function assignRole(address _account, Role _role) external onlyAdmin {
        roles[_account] = _role;
    }
}

入全景模式 出全景模式

其果何?无地可兼二职。买者不得呈验。造者不得立令。职分之授,亦需管钥,此乃余将诚论于下文所载之唯一中枢之枢。onlyRole修饰可组合,故扩新函数类型,损一行耳。

创制一单

BUYER地址可立采购之令。既立令,则阈限不可易。吾欲重此末节,盖其要逾于表象也。

若买方得于供方既成其证之后,降其阈限,则可逆溯而黜合格之供方。设阈限于创制之时,则此弊绝矣。

struct ProcurementOrder {
    address buyer;
    address supplier;
    uint256 threshold;
    bool fulfilled;
}

mapping(uint256 => ProcurementOrder) public orders;
uint256 public nextOrderId;

function createOrder(address _supplier, uint256 _threshold)
    external
    onlyRole(Role.BUYER)
    returns (uint256 orderId)
{
    orderId = nextOrderId++;
    orders[orderId] = ProcurementOrder({
        buyer: msg.sender,
        supplier: _supplier,
        threshold: _threshold,
        fulfilled: false
    });
}

入全景模式 出全屏模式

呈稿:廉验先,贵验后

此乃 ZK 验证之实境。当供应商呈上其证时,契约按刻意之序,自廉至贵,行五重检核:

  1. 职分检视:呼者是否为注册之PRODUCER乎?(修饰,~200气)
  2. 供应商身份:此乃此单专属供应商乎?(SLOAD,~2,100气)
  3. 防重播之策:此订单已竟否?(SLOAD,~2,100 gas)
  4. 阈限结合公信号是否与所存阈值相合?(较验,约二百气)
  5. 配对验之:ZK证明乎,其于密码学可乎?(~285,000 gas)

昂贵的配对计算,置于末位运行。凡较廉之守卫,若其前失败,则可救呼者免于耗285k气于必败之交易.

function submitThresholdProof(
    uint256 orderId,
    uint[2] calldata _pA,
    uint[2][2] calldata _pB,
    uint[2] calldata _pC,
    uint[1] calldata _pubSignals
) external onlyRole(Role.PRODUCER) {
    ProcurementOrder storage order = orders[orderId];

    require(msg.sender == order.supplier, "Caller is not the designated supplier");
    require(!order.fulfilled, "Order already fulfilled");
    require(_pubSignals[0] == order.threshold, "Public signal does not match order threshold");

    require(
        verifier.verifyProof(_pA, _pB, _pC, _pubSignals),
        "ZK proof verification failed"
    );

    order.fulfilled = true;
    // Downstream: emit event, trigger escrow release, etc.
}

入全屏模式 出全屏模式

有一检于此,尤当留心:_pubSignals[0] == order.threshold。此看似冗余,然实司要务。无此,供者可提交一有效之证,所对者乃閾(謂之千兆瓦時,彼輩輕易滿足之),與需三千兆瓦時之訂單相配。證明本身亦能通過配對檢查,因其千兆瓦時之有效證明也。唯此綁定檢查能察知替換,拒之。


效能數據:此實際成本何在?

指標
证明大小 256字节(固定不变)
证明生成时间 1至2秒(链下)
验证器部署气费 ~2,850,000(一次性)
每证明验证气费 ~289,096
以太坊L1上30Gwei的代价 ~$0.87每证明
Arbitrum 或 Optimism 上之成本 ~每证明需钱约零点零一

企业采购之约,单约值数百万,L1每证明需钱八角七分,固合宜。若近于频数更高,L2乃明途.


我所得正,及我所欲异之处

其善者

分而别之Verifier.solGreenHydrogenMarketplace.sol 出,乃建筑之正道。验者,无状之密码原语,无业务之逻辑。使之孤立,则可独立审计,不涉他事。表面积小,审计范围洁。

由廉至贵之序,submitThresholdProof 亦验之有效。无效输入之失败提交,较之先验配对检查,成本恒低。

贞悔之篇

可信之设,乃吾未解之负累。 Groth16 需要举行一次 MPC 仪式以生成证验之钥。PoC 乃模拟之仪,于研习之境尚可。然于生产,若仪式中任一参与者留其"毒废"(即其贡献之秘随机性),则可永无止境地伪造伪言之有效证明。生产部署需或举行广大公验之 MPC 仪式,且其记录可审;或迁至透明之证系统,如 PLONK 或 Halo2,此二者皆无需任何可信设置。

管理之钥,乃信任之瓶颈,吾未得全解之.今时,一地址统辖市集之角色授命,此乃显著之集权风险。来版中,管理之职当于首日移转至 Gnosis Safe 多签,于角色授命之操作设有时锁,俾参与者得预闻变故.

燃料价可下矣. Verifier.sol 之BN254配对操作,得EIP-197预编译于以太坊之助,益甚。若所生之验证者能循此预编译而非于EVM解释器中计算,则验证之费减三十至四十之百分。生产部署之前,宜慎测之。

此电路仅证一事耳。 采购契约非惟计其量也,纯度之级、认证之期、原产之国,皆所重焉。延电路以作复合验核 (volume >= min_vol AND purity >= min_purity AND date >= cutoff),增约束约二百五十六,或倍证成之时。此二者皆在实用之限,使系统得增其用,实为有义。


自行运行之

若欲探其码:

git clone <your-repo-url>
cd h2ledger-poc
npm install
npm run verify
# Expected: OK
# (verifies the included proof where actualAmount=5000 >= threshold=3000)

入全景模式 出全屏模式

直视电路统计:

snarkjs r1cs info circuits/credit_proof.r1cs
# Curve: bn-128
# Constraints: 128
# Wires: 193
# Private Inputs: 1
# Public Inputs: 1

入全景模式 出全屏模式


何故此模式超越氢之重要性

吾于营此物时,恒思此理:H2Ledger非氢之专案也,实乃通用范式之示也。

凡市井之中,有需证其数合乎阈限,然示此数则费,此皆此架构之适者。信用评鉴。保险核保。供应链商贾资格。薪俸合规查核。电路虽异,其式不变。

零知识证明之说甚嚣尘上,吾欲示之者,乃以 Circom、SnarkJS 及数百行 Solidity 之码,数周之内即可成实事。此工具有实用之能。其数理非必玄妙,但须脉络贯通,则可矣。

若尔以类此之道营构物,或见有当予修正者,诚愿闻其说。


H2Ledger乃研习之证验(v0.1.0)。证法:Groth16(BN254)。电路:128约束,193线。疑问或协契:nioomeee@gmail.com