Solidity

Solidity
Solidity的標誌
当前版本
  • 0.8.25 (2024年3月14日;穩定版本)[1]
編輯維基數據鏈接
網站github.com/ethereum/solidity
啟發語言
JavaScript、C++、Python、PowerShell

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];
  }

}

開發平台

  • Remix,Solidity官方IDE
  • ChainIDE
  • Microsoft Visual Studio[17][18]
  • ConsenSys Enterprise
  • Tendermint 
  • AWS的ErisDB

區塊鏈平台

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 將安全漏洞導入到合約中,這些漏洞不僅被社區遺漏,還包括原本的語言設計人。”

外部連結

  • Solidity home and documentation