智能合约

What are Smart Contracts

SMART CONTRACT DEFINITION

智能合约是一种防篡改程序,当满足某些预定义条件时,它在区块链网络上运行。

What is a Smart Contract

1
//Smart contracts are computer programs that are hosted and executed on a blockchain network. Each smart contract consists of code specifying predetermined conditions that, when met, trigger outcomes. By running on a decentralized blockchain instead of a centralized server, smart contracts allow multiple parties to come to a shared result in an accurate, timely, and tamper-proof manner. 

智能合约是在区块链网络上托管和执行的计算机程序。每个智能合约都包含指定预定条件的代码,这些条件在满足时会触发结果。通过在去中心化区块链而不是集中化服务器上运行,智能合约允许多方以准确、及时和防篡改的方式达成共享结果。

1
//Smart contracts are a powerful infrastructure for automation because they are not controlled by a central administrator and are not vulnerable to single points of attack by malicious entities. When applied to multi-party digital agreements, smart contract applications can reduce counterparty risk, increase efficiency, lower costs, and provide new levels of transparency into processes.

智能合约是一种强大的自动化基础设施,因为它们不受中央管理员的控制,不易受到恶意实体的单点攻击。当应用于多方数字协议时,智能合约应用程序可以降低交易对手风险、提高效率、降低成本,并为流程提供新的透明度。

History of Smart Contracts

智能合约最早由美国计算机科学家尼克·沙博于1994年创造。在他的开创性著作中,他给出了一个宽泛的智能合约定义:“执行合约条款的计算机化交易协议”,其总体目标是“满足共同的合同条件,最大限度地减少恶意和意外的异常,并最大限度地降低对可信中介的需求”

虽然智能合约的一般概念可以在自动售货机等系统中看到(例如,特定代码导致预期的零食),但区块链形成了数字、防篡改和无许可的智能合约的基础。2009年比特币区块链的引入支持了第一个协议智能合约,该合约建立了一组必须满足的条件,才能在网络上的用户之间传输比特币。这些条件包括用户使用与其公共地址匹配的正确私钥(类似于链接到特定帐户的密码)签署交易,以及用户拥有足够的资金来支付交易。

2012年,比特币区块链演变为提供另一种主要类型的智能合约,称为多签名交易。多重签名交易需要定义数量的人(公钥)使用其私钥签署交易,然后才被认为有效。这通过减少单点故障(如被盗或丢失的私钥)来提高用户资金的安全性。

在接下来的几年中,区块链开始尝试添加新的编程条件(称为操作码opcodes)。然而,2013年Vitalik Buterin发布了以太坊白皮书,这是智能合约的下一个重大飞跃。2015年,以太坊作为可编程智能合约的新型区块链推出。以太坊智能合约区块链提供了一台可以同时运行多个独立智能合约的“世界计算机”,而不是区块链作为单个智能合约应用程序或提供一些有限的操作码。

How Smart Contracts Work

智能合约是区块链上的防篡改程序,具有以下逻辑:“如果/当x事件发生时,执行y操作。”一个智能合约可以有多个不同的条件,一个应用程序可以有多种不同的智能合约,以支持一组相互连接的流程。还有多种用于编程的智能合约语言,以太坊的Solidity是最受欢迎的。

1
//Any developer can create a smart contract and deploy it on a public blockchain for their own purposes, e.g., a personal yield aggregator that automatically shifts their funds to the highest-earning application. However, many smart contracts involve multiple independent parties that may or may not know one another and don’t necessarily trust one another. The smart contract defines exactly how users can interact with it, involving who can interact with the smart contract, at what times, and what inputs result in what outputs.  The result is multi-party digital agreements that evolve from today’s probabilistic state, where they will probably execute as desired, to a new deterministic state where they are guaranteed to execute according to their code. 

任何开发者都可以创建一个智能合约,并将其部署在公共区块链上,用于他们自己的目的,例如,一个个人收益聚合器,自动将他们的资金转移到最高收益的应用程序。然而,许多智能合约涉及多个独立方,这些独立方可能相互了解,也可能不相互信任。智能合约准确定义了用户如何与智能合约交互,包括谁可以与智能合约进行交互,在什么时间,以及什么输入导致什么输出。结果是多方数字协议,从今天的概率状态演变而来,他们可能会按需执行,到一个新的确定性状态,在该状态下它们保证根据它们的代码执行。

Smart Contract Examples

  1. 智能合约的一个目的是在不同的实体组之间自动化特定的业务流程。这些实体共同就所有智能合约的条款达成一致,如支付、流程和争议解决。一个简单的全球贸易智能合约示例可能包含以下条款:

  • Term 1: If the goods arrive on time, then execute a payment from the retailer(零售商) to the supplier(供货商) in full amount.
  • Term 2: If the goods arrive one day late, then execute a payment from the retailer to the supplier for 98% of the full amount.
  1. 智能合约另外支持公共去中心化应用程序(dApps),任何人都可以在不需要任何权限的情况下与之交互。公共dApps通常是开源的,so anyone in the world can inspect exactly how they function before deciding whether or not to interact with them。公共dApp的一个例子是去中心化借贷市场【decentralized lending/borrowing market】,可能有以下条款:

  • Term 1: If the user deposits collateral into the specific smart contract, they can receive a loan that’s up to 50% of the value of their collateral (i.e., $100 deposit can borrow up to a $50 loan). –100美元存款最多可借50美元贷款
  • Term 2: If the user’s collateralization ratio (collateral/outstanding loan value) drops below 200%, then the user’s collateral is automatically liquidated and transferred to the lenders to ensure they don’t lose money.—抵押比率(抵押物/未偿贷款价值),保证lenders权益
  • Term 3: Lenders can deposit funds into a specific contract that other users can borrow from at predefined collateralization ratios, while the lender receives a claim to a portion of the interest rate payments.

Smart Contract Benefits

1
//Most traditional digital agreements involve two parties that don’t know each other, introducing risk that either participant won’t uphold their commitments. To resolve counterparty risk, digital agreements are often hosted and executed by larger, centralized institutions like a bank that can enforce the contract’s terms. These digital contracts can be directly between a user and a large company or involve a large company acting as a trusted intermediary between two users. While this dynamic allows many contracts to exist that otherwise wouldn’t take on such risk, it also creates a situation where the larger, centralized institutions exert asymmetrical influence over the contracts.

The difference in how user funds are handled when making a payment through a blockchain vs. the banking system

智能合约在数字协议的基础上提供了一些优势。

  • Security安全性】 – Running the contract on decentralized blockchain infrastructure ensures there is no central point of failure to attack, no centralized intermediary to bribe【贿赂中间机构】, and no mechanism for either party or a central admin to use to tamper with the outcome.
  • Reliability【可靠性】 – Having the contract logic redundantly processed and verified by a decentralized network of nodes provides strong tamper-proof, uptime, and correctness guarantees that the contract will execute on time according to its terms.
  • Equitable【公平性】 – Using a decentralized network to host and enforce the terms of the agreement reduces the ability of a for-profit middleman to use their position of privilege to rent-seek and siphon off value.
  • Efficiency高效性】 – Automating the backend processes of the agreement—escrow, maintenance, execution, and/or settlement—means neither party has to wait for manual data to be entered, the counterparty to fulfill their obligations, or a middleman to process the transaction.

Smart Contract Use Cases【智能合约的用例】

  • Rights Management (Tokens) – 权限管理(令牌)

    Token smart contracts are used to create, track, and assign ownership rights to specific digital tokens existing on blockchain networks. The token contract programs functionalities into the tokens it issues, providing holders features like utility/insurance in a dApp (utility token), voting weight in a protocol (governance token), equity in a company (security token), ownership claim to a unique real-world or digital asset (non-fungible token), and more. For example, the FIL token is used to pay for Filecoin’s decentralized storage services and the COMP token allows users to participate in the governance of Compound protocol.

  • Financial Products (DeFi) (去中心化金融)

    Decentralized finance (DeFi) consists of applications that use smart contracts to recreate traditional financial products and services such as money markets, options, stablecoins, exchanges, and asset management, as well as combine multiple services to create new financial primitives via permissionless composability. The smart contract can hold user’s funds in escrow and distribute them between users based on predefined conditions. For example, BarnBridge uses smart contracts to automate trades for users wanting fixed asset exposure to a price pair (e.g., 45% token A, 55% token B), and Aave uses smart contracts to facilitate lending and borrowing in a permissionless and decentralized manner.

Aave supports decentralized lending markets by using asset prices to determine a user’s borrowing borrower and to see if loans are undercollateralized and subject to liquidation

  • Gaming and NFTs

    1
    //Blockchain-based games use smart contracts for tamper-proof execution of in-game actions. One example is [PoolTogether](https://medium.com/pooltogether/improving-pooltogether-with-chainlink-vrf-dcf1a3d6ea), a no-loss savings game where users stake their funds in a shared pool that is then routed into a money market where it earns interest. After a predefined time period, the game ends and a winner is randomly awarded all the accrued interest while everyone else can withdraw their original deposit. Similarly, limited-edition NFTs can have fair distribution models and RPGs can support unpredictable loot drops using randomness, helping to ensure all users have a fair shot at getting rare digital assets. Many projects access randomness using [Chainlink Verifiable Random Function (VRF)](https://blog.chain.link/chainlink-vrf-now-live-on-ethereum-mainnet/)—a random number generator (RNG) that uses cryptography to prove it's tamper-proof, meaning the RNG process is publicly auditable.

游戏和NFT基于区块链的游戏使用智能合约来防止游戏内动作的执行。一个例子是Pool Together,这是一个无损失的储蓄游戏,用户将他们的资金存入共享池,然后将其转入货币市场,在那里赚取利息。在预定义的时间段后,游戏结束,获胜者将随机获得所有应计利息,而其他人可以提取他们的原始存款。类似地,限量版NFT可以有公平的分配模型,RPG可以使用随机性支持不可预测的战利品掉落,有助于确保所有用户都有机会获得稀有的数字资产。许多项目使用Chainlink可验证随机函数(VRF)访问随机性,这是一种随机数生成器(RNG),使用密码学来证明其不可篡改,这意味着RNG过程是可公开审核的。

MLB baseball player Trey Mancini did an NFT drop to raise money for cancer patient support, where Chainlink VRF was used to randomly assign additional utility to some NFTs

  • Insurance

    1
    //Parametric insurance is a type of insurance where a payout is tied directly to a specific predefined event. Smart contracts provide tamper-proof infrastructure for creating parametric insurance contracts that trigger based on data inputs. For example, crop insurance can be created using smart contracts, where a user purchases a policy based on specific weather information like seasonal rainfall in a geographic location. At the end of the policy, the smart contract will automatically issue a payout if the amount of rainfall in the specific location exceeds the original stated amount. Not only do end-users receive timely payouts with less overhead, but the supply side of insurance can become open to the public via smart contracts. The smart contract allows users to deposit funds into a pool and then distributes collected premiums to pool participants based on the percentage of their contribution to the pool.

保险参数保险是一种支付直接与特定预定义事件相关的保险类型。智能合约为创建基于数据输入触发的参数保险合约提供了防篡改基础设施。例如,可以使用智能合约创建作物保险,用户根据特定天气信息(如地理位置的季节性降雨)购买保单。在保单结束时,如果特定地点的降雨量超过了最初规定的降雨量,智能合约将自动支付。不仅最终用户能够以更少的开销及时获得付款,而且保险的供应端也可以通过智能合约向公众开放。智能合约允许用户将资金存入池中,然后根据池中参与者的贡献百分比将收取的保费分配给池参与者

Arbol uses Ethereum smart contracts and Chainlink oracles to enable parametric insurance based on weather data in a particular geographic region

Smart Contract Limitations

智能合约的一个固有限制是,它们运行的底层区块链是孤立的网络,这意味着区块链没有与外部世界的内置连接。没有外部连接,智能合约无法与外部系统通信以确认真实世界事件的发生,也无法访问成本高效的计算资源。与没有互联网的计算机类似,如果没有真实世界的连接,智能合约是极其有限的。例如,他们无法在执行交易前了解资产的价格,无法在支付作物保险索赔前检查月平均降雨量,也无法在与供应商结算前核实货物是否已到达。

‍因此,区块链行业正在进行的主要演变是可编程智能合约,它与区块链之外的真实世界数据和传统系统连接,扩展了智能合约逻辑中使用的输入和输出。这些混合智能合约使用称为oracle的安全中间件,将链上代码与链下基础设施相结合,例如,使用外部数据触发智能合约,或在传统支付轨道上结算链下合同。

Oracles connect inputs and outputs to blockchains to create hybrid smart contracts

与互联网对计算机的影响类似,oracles是将新兴区块链网络与当今遗留系统连接起来的关键,以实现互连、高效和隐私保护的智能合约,从而保持底层区块链网络的安全性和可靠性。通过启用混合智能合约,oracles极大地扩展和增强了区块链的宝贵属性,从而在更多行业和用例中基于加密真实性达成了卓越的数字协议。

谢谢你的支持哦,继续加油.