FHE状态操作系统:在保护公民隐私的同时将公共基础设施上链

  • ZamaFHE
  • 发布于 2025-02-13 13:23
  • 阅读 152

本文介绍了Zama的FHE State OS,这是一个基于区块链的IT基础设施,旨在通过全同态加密保护公民隐私,同时管理税收、公共支出等政府职能。文章还讨论了使用FHE构建的几个应用案例,包括:加密的ERC-20 token,使用加密投票的DAO,以及去中心化身份系统。

“网络国家”的概念在全球的技术专家和政策爱好者中越来越受欢迎。Balaji Srinivasan 等支持者设想了完全数字优先的社区,而 Vitalik Buterin 等人则探索了物理飞地(通常在特殊经济区内),以促进长寿研究等领域的创新。尽管他们的愿景有所不同,但他们都有一个核心信念:区块链技术可以通过减少中介、在必要时提高透明度以及在需要时保持信息私密性来简化治理和集体决策。

数字社区框架

然而,区块链系统中的透明度可能是一把双刃剑。许多早期的加密货币采用者在货币、税收和公共支出等领域面临挑战,主要是因为传统的区块链暴露了太多的数据。这阻碍了基于区块链的基础设施在关键政府职能中的应用,因为对于个人记录、税务申报和州级决策而言,保密性至关重要。由此产生了 Zama 的 FHE 状态操作系统(Operating System) 的想法:一种基于区块链的、强大且高效的 IT 基础设施,专为整个州或社区设计,默认使用全同态加密来保护隐私。通过整合身份和货币功能,它旨在以尽可能少地依赖第三方的方式来管理从税收征收到公共支出的所有事务。区块链特别适合这一点,因为它们消除了对中心化中介的需求,从而降低了成本和潜在的故障点。

默认隐私:全同态加密

然而,在公共账本上实现隐私需要先进的密码学工具。零知识(ZK)证明提供了一种途径,使用户能够在不揭示底层数据的情况下证明某些事情。另一种有前景的方法是 全同态加密(FHE),它允许在加密数据上进行计算而无需解密。基于 FHE 的解决方案开始在解决透明度和保密性之间的紧张关系方面显示出真正的希望。一些行业参与者——正在悄悄地致力于弥合这些技术——认为一旦复杂的隐私解决方案成为网络国家的标准,传统机构也会纷纷效仿。

这种以隐私为中心的区块链治理愿景的一个实际例子是 Crecimiento 于 2024 年 12 月举办的 Crecimiento 黑客马拉松,开发人员在其中尝试使用机密智能合约来构建阿根廷公民服务和去中心化预算的新框架。结果表明,在协议级别集成加密(例如在支持 FHE 的环境中)可以保留区块链的核心优势(完整性、不可变性),同时满足国家和地方政府通常要求的隐私要求。

展望未来,创新者们看到了应用 FHE 作为保护隐私的状态操作系统骨干的潜力。这可以简化关键操作,而无需暴露敏感数据。尽管这些解决方案仍在不断发展,但它们代表着朝着更安全、更值得信赖的数字治理迈出的一步。

为创新做贡献

对于那些有兴趣塑造政府服务和数字国家未来的人来说,现在是探索智能合约平台上的隐私增强技术的时候了。通过参与开放黑客马拉松、试验原型系统或为支持同态加密的生态系统做出贡献,开发人员和企业家可以引领下一波公共基础设施的浪潮。

最终,随着网络国家的影响力越来越大,平衡区块链透明度和强大隐私的解决方案将重新定义我们管理公共资源、进行政治流程和确保数据保密的方式。构建下一代国家基础设施的竞赛已经开始。

你是开发者吗?立即编写你的第一个机密智能合约

使用 Zama 的 fhEVM,开发人员可以像编写常规智能合约一样,用普通的 solidity 编写机密智能合约。如果你有兴趣入门,可以查看 Zama 的 fhEVM 文档 上的分步演示。

机密 ERC-20 转账

标准 ERC20 智能合约的一种变体,它结合了加密余额,为代币持有者提供额外的隐私。

代码示例架构

contract EncryptedERC20{
    // ...
    function transfer(address to, einput encryptedAmount, bytes calldata inputProof) public {
        ebool canTransfer = TFHE.le(amount, _balances[msg.sender]); // 确保所有者有足够的代币
        euint64 transferValue = TFHE.select(isTransferable, amount, TFHE.asEuint64(0));
        euint64 newBalanceTo = TFHE.add(_balances[to], transferValue); // 添加到 `to` 的余额
        _balances[to] = newBalanceTo;
        TFHE.allowThis(newBalanceTo);
        TFHE.allow(newBalanceTo, to);
        euint64 newBalanceFrom = TFHE.sub(_balances[from], transferValue); // 从 `for` 的余额中扣除
        _balances[from] = newBalanceFrom;
        TFHE.allowThis(newBalanceFrom);
        TFHE.allow(newBalanceFrom, from);
    }
}
// 在 https://github.com/zama-ai/fhevm-contracts/blob/main/contracts/token/ERC20/ConfidentialERC20.sol 阅读完整代码

机密投票系统

DAO 智能合约,通过加密投票促进治理决策。

代码示例架构

contract VotingDapp is GatewayCaller, Ownable {
    uint256 public dateEndVote;
    uint256 public totalVotes;
    euint64 internal totalVotesForProposalEncrypted;
    uint64 public totalVotesForProposalResult;
    bool public finalResultIsDecrypted;

    mapping(address user => bool canVote) public isWhiteListed;
    mapping(address user => bool hasVoted) public hasAlreadyVoted;
    /// ...

    constructor(uint256 voteDuration) Ownable(msg.sender) {
        dateEndVote = block.timestamp + voteDuration;
        totalVotesForProposalEncrypted = TFHE.asEuint64(0);
        TFHE.allowThis(totalVotesForProposalEncrypted);
    }

    function whiteListUser(address user) external onlyOwner {
        isWhiteListed[user] = true;
    }

    function castVote(einput encryptedSupport, bytes calldata inputProof) external {
        if (block.timestamp >= dateEndVote) revert TooLateToCastVote();
        if (!isWhiteListed[msg.sender] || hasAlreadyVoted[msg.sender]) revert UserUnauthorized();
        ebool voteFor = TFHE.asEbool(encryptedSupport, inputProof);
        totalVotesForProposalEncrypted = TFHE.add(totalVotesForProposalEncrypted, TFHE.asEuint64(voteFor));
        TFHE.allowThis(totalVotesForProposalEncrypted);
        totalVotes++;
        hasAlreadyVoted[msg.sender] = true;
    }

    function requestRevealVoteResult() external { // 任何人都可以在投票期结束后请求解密最终结果
        if (block.timestamp < dateEndVote) revert TooEarlyToRevealResult();

        // 通过网关请求解密投票结果
        uint256[] memory cts = new uint256[](1);
        cts[0] = Gateway.toUint256(totalVotesForProposalEncrypted);
        Gateway.requestDecryption(cts, this.revealVoteResult.selector, 0, block.timestamp + 100, false);
    }

    function revealVoteResult(uint256 /*requestId*/, uint64 result) external onlyGateway {
        totalVotesForProposalResult = result;
        finalResultIsDecrypted = true;
    }

    function isProposalVoted() public view returns (bool) {
        if (!finalResultIsDecrypted) revert ResultNotRevealedYet();
        if (2 * totalVotesForProposalResult >= totalVotes) return true;
        return false;
    }
}
// 在 https://github.com/zama-ai/fhevm-contracts/blob/main/contracts/governance/ConfidentialERC20Votes.sol 阅读完整代码

机密去中心化身份系统

一种基于区块链的身份管理系统,使用智能合约来存储和管理加密的个人数据。

代码示例架构

contract DID is Ownable {
    struct Identity {
        euint128 id; // 加密的唯一 ID
        ebytes64 name; // 加密的姓名
        euint64 birthdate; // 用于年龄验证的加密出生日期
    }
    mapping(address user => Identity) private citizenIdentities;
    // ...

    /// @dev 所有者能够为特定用户地址添加新身份
    function registerIdentity(
        address user, einput name_, einput birthdate_, bytes calldata inputProof
    ) public onlyOwner {
        euint64 newId = TFHE.randEuint128(); // 生成一个新的加密随机唯一 ID
        citizenIdentities[user] = Identity({
            id: newId,
            name: TFHE.asEbytes64(name_, inputProof),
            birthdate: TFHE.asEuint64(birthdate_, inputProof)
        });
        /// @dev 允许用户访问自己的数据
        TFHE.allow(citizenIdentities[user].id, addressToBeAllowed);
        TFHE.allow(citizenIdentities[user].name, addressToBeAllowed);
        TFHE.allow(citizenIdentities[user].birthdate, addressToBeAllowed);

        /// @dev 允许合约访问数据
        TFHE.allowThis(citizenIdentities[user].id);
        TFHE.allowThis(citizenIdentities[user].name);
        TFHE.allowThis(citizenIdentities[user].birthdate);
    }

    /// @dev 授予 claim 合约访问加密出生日期的权限
    function generateAgeClaim(address claimAddress, string memory claimFn) public {
        TFHE.allowTransient(citizenIdentities[msg.sender].birthdate, claimAddress);
        (bool success, bytes memory data) = claimAddress.call(abi.encodeWithSignature(claimFn, msg.sender));
        if (!success) revert ClaimGenerationFailed(data);
    }

    function getBirthdate(address user) public view returns (euint64) {
        return citizenIdentities[user].birthdate;
    }
}

contract EmployerClaim {
  mapping(address user => ebool isAdult) private adultClaims;
  // ...

  /// @dev 生成一个加密的 claim,验证用户是否已满 18 岁
  function generateAdultClaim(address user) public {
      if (msg.sender != address(didContract)) revert NotAuthorized();
      euint64 birthdate = didContract.getBirthdate(user); // 从 DID 合约检索用户的加密出生日期
      ebool isAdult = TFHE.le(birthdate, _AGE_THRESHOLD); // 检查用户是否已成年
      adultClaims[user] = isAdult; // 存储 claim 结果
      TFHE.allowThis(isAdult);
      TFHE.allow(isAdult, user);
  }
}
// 在 https://github.com/poppyseedDev/FHEPass/blob/main/contracts/PassportID.sol 阅读完整代码

更多链接

  • 原文链接: zama.ai/post/fhe-state-o...
  • 登链社区 AI 助手,为大家转译优秀英文文章,如有翻译不通的地方,还请包涵~
点赞 0
收藏 0
分享
本文参与登链社区写作激励计划 ,好文好收益,欢迎正在阅读的你也加入。

0 条评论

请先 登录 后评论
ZamaFHE
ZamaFHE
Zama是一家开源密码学公司,专注于为区块链和人工智能构建最先进的完全同态加密(FHE)解决方案。