Solidity

本页使用了标题或全文手工转换
维基百科,自由的百科全书
Solidity
Solidity的标志
当前版本
  • 0.8.25 (2024年3月14日;稳定版本)[1]
编辑维基数据链接
网站github.com/ethereum/solidity
启发语言
JavaScriptC++PythonPowerShell

Solidity是一种合约导向式语言,被应用于各种不同的区块链平台[2],其主要开发者为加文·伍德英语Gavin Wood,Christian Reitwiessner,Alex Beregszaszi,Liana Husikyan,Yoichi Hirai和其他几位早期以太坊核心贡献者。[3][4]Solidity 可使程序开发人员能在区块链上(例如以太坊)编写智能合约[5][6][7]

历史[编辑]

Solidity的语法概念最早是由加文·伍德英语Gavin Wood在2014年提出,[8]后期则以Christian Reitwiessner所领导的以太坊团队Solidity接手开发。该语言是针对以太坊虚拟机(EVM)所设计的四种语言之一(其他的还有Serpent,LLL,Viper(实验中)和Mutan(已弃用))。有关这些语言的更多信息,请参阅以太坊编程语言

Solidity是目前在以太坊及其他以太坊竞争平台中的主要编程语言,例如Monax及其Burrow Hyperledger的区块链就是使用Tendermint完成共识机制。 SWIFT亦已经使用Solidity在Burrow上完成了概念验证。[9]

康奈尔大学的研究人员指出,Solidity即是导致DAO在2016年被黑客攻击的部分原因之一。他表示:“这实际上并不是DAO合同本身的缺陷或漏洞;技术上来说,DAO确实是在EVM上如预期般地被执行,反而是Solidity将安全上的漏洞引入了合约之中,而这些漏洞不仅没被开发社群察觉,Solidity语言的设计者们也忽略了。[10][11]

描述[编辑]

Solidity是一种静态类型的编程语言,用于开发在EVM上执行的智能合约。 Solidity被编译为可在EVM上执行的字节码[12][13] 借由Solidity,开发人员能够编写出可自我执行其欲实现之商业逻辑的应用程序,该程序可被视为一份具权威性且永不可悔改的交易合约。[14][15]对已具备程序编辑能力的人而言,编写Solidity的难易度就如同编写一般的编程语言。[16]

Gavin Wood最初在规划Solidity语言时引用了ECMAScript的语法概念,使其对现有的Web开发者更容易入门;与ECMAScript不同的地方在于Solidity具有静态类型和可变返回类型。而与目前其他EVM目标语言(如Serpent和Mutan)相比,其重要的差异在于Solidity具有一组复杂的成员变量使得合约可支持任意层次结构的映射和结构。Solidity也支持继承,包含C3线性化多重继承。 另外还引入了一个应用程序二进制接口(ABI),该接口(ABI)可在单一合同中实现多种类型安全的功能。 

以下为使用Solidity编写的程序示例:

contract GavCoin
{
  mapping(address=>uint) balances;
  uint constant totalCoins = 100000000000;

  /// Endows creator of contract with 1m GAV.
  function GavCoin(){
      balances[msg.sender] = totalCoins;
  }

  /// Send $((valueInmGAV / 1000).fixed(0,3)) GAV from the account of $(message.caller.address()), to an account accessible only by $(to.address()).
  function send(address to, uint256 valueInmGAV) {
    if (balances[msg.sender] >= valueInmGAV) {
      balances[to] += valueInmGAV;
      balances[msg.sender] -= valueInmGAV;
    }
  }

  /// getter function for the balance
  function balance(address who) constant returns (uint256 balanceInmGAV) {
    balanceInmGAV = balances[who];
  }

}

开发平台[编辑]

区块链平台[编辑]

Solidity可在下列平台中运作:

参考文献[编辑]

  1. ^ Release 0.8.25. 2024年3月14日 [2024年3月25日]. 
  2. ^ Allison, Ian. PwC blockchain expert pinpoints sources of ambiguity in smart contracts. IBTimes (News). 12 August 2016 [14 December 2016]. (原始内容存档于2018-06-27). 
  3. ^ Alyssa Hertig. Blockchain Veterans Unveil Secure Smart Contracts Framework. CoinDesk. 15 September 2016 [14 December 2016]. (原始内容存档于2018-04-06). 
  4. ^ Rebecca Campbell. Counterparty Brings Ethereum Smart Contracts to the Bitcoin Blockchain. CCN. 6 September 2016 [14 December 2016]. (原始内容存档于2017-09-24). 
  5. ^ In Formal Verification Push, Ethereum Seeks Smart Contract Certainty. CoinDesk (News). 28 September 2016 [12 December 2016]. (原始内容存档于2018-02-27). 
  6. ^ Gomez, Eduardo. A Consensus Issue Between The Geth and Parity Ethereum Clients Caused an Unintentional Fork of the Network. TheMerkle (News). 24 November 2016 [14 December 2016]. (原始内容存档于2018-02-26). 
  7. ^ Browning, David. Digital Siege: Why Young Entrepreneurs Are Winning. May 2016 [2017-01-08]. ISBN 978-1628652963. (原始内容存档于2017-01-09). 
  8. ^ Benoit Schweblin. StackEdit Viewer. stackedit.io. [2018-02-26]. (原始内容存档于2016-04-01). 
  9. ^ KENTOURIS, CHRIS. Blockchain’s Smart Contracts: What’s Smart, What’s Not. Finops (News). 13 December 2016 [14 December 2016]. (原始内容存档于2018-02-27). 
  10. ^ Quentson, Andrew. Ethereum’s Solidity Flaw Exploited in DAO Attack Says Cornell Researcher. CryptocoinNews (News). 19 June 2016 [14 December 2016]. (原始内容存档于2017-07-19). 
  11. ^ Finley, Klint. A $50 MILLION HACK JUST SHOWED THAT THE DAO WAS ALL TOO HUMAN. Wired (News). 18 June 2016 [18 February 2017]. (原始内容存档于2016-07-26). 
  12. ^ Mougayar, William. The Business Blockchain: Promise, Practice, and Application of the Next Internet Technology. Wiley Publishing. 2016-04-26. ISBN 978-1119300311. 
  13. ^ Allison, Ian. Microsoft adds Ethereum language Solidity to Visual Studio. International Business Times. 2016-03-30 [2016-05-11]. (原始内容存档于2016-05-29). 
  14. ^ Bradley, Joseph. Ethereum's Solidity Now Available in Microsoft Visual Studio. Cryptocoinnews. 2016-05-04 [2016-05-11]. (原始内容存档于2016-04-18). 
  15. ^ Allison, Ian. Microsoft adds Ethereum language Solidity to Visual Studio. International Business Times. 30 March 2016 [11 May 2016]. (原始内容存档于2016-05-29). 
  16. ^ Mougayar, William. The Business Blockchain: Promise, Practice, and Application of the Next Internet Technology Hardcover. Wiley Publishing. May 9, 2016 [2017-01-09]. ISBN 978-1119300311. 
  17. ^ Ethereum's Solidity Now Available in Microsoft Visual Studio. CCN: Financial Bitcoin & Cryptocurrency News. [1 May 2016]. (原始内容存档于2016-04-18). 
  18. ^ Microsoft Adds Ethereum to Windows Platform For Over 3 Million Developers. CoinDesk. [1 May 2016]. (原始内容存档于2018-01-09). 
  19. ^ Blockchain and big data worth watching in the coming year. Business. International Business Times. December 20, 2016 [2017-09-28]. (原始内容存档于2022-08-12) (英语). 
  20. ^ Schneier, Karthikeyan; Schneier, Antoine; Bhargavan, Cedric; Delignat-Lavaud, Anitha; Fournet, Gollamudi; Schneier, Bruce; Rastogi, Nadim; Sibut-Pinote, Aseem; Rastogi1, Thomas; Swamy, Nikhil; Zanella-Beguelin, Santiago. Short Paper: Formal Verification of Smart Contracts (PDF). Microsoft Research, French Institute for Research in Computer Science and Automation, Harvard University. August 27, 2016. (原始内容存档 (PDF)于August 23, 2017) (英语). 

批评[编辑]

智能合约的许多安全属性本质上很难直接推理,而 Solidity 的图灵完备性意味着任意属性的验证无法确定地自动化。目前用于智能合约安全分析的自动化解决方案可能会遗漏掉一些严重的违规行为,产生误报,并且无法在现实合约上达到足够的代码覆盖率。由于其违反直觉的性质、缺乏处理区块链领域特定方面的结构以及缺乏已知漏洞的中心化文件,Solidity 被批评为以太坊智能合约的实施容易出错。

2016 年,康奈尔大学的一位研究人员表示,Solidity 是当年发生的 DAO 黑客攻击的部分原因。他表示:“这实际上不是 DAO 合约本身的缺陷或漏洞:就技术而言,以太坊虚拟机 (EVM) 正在按预期运行,但 Solidity 将安全漏洞导入到合约中,这些漏洞不仅被社区遗漏,还包括原本的语言设计人。”

外部链接[编辑]