本页使用了标题或全文手工转换

Solidity

维基百科,自由的百科全书
跳到导航 跳到搜索
Solidity
Solidity logo.svg
Solidity的標誌
網站 github.com/ethereum/solidity
啟發語言
JavaScriptC++PythonPowerShell

Solidity是一種合約導向式語言,可被應用於各種不同的區塊鏈平台上[1],其主要開發者為加文·伍德英语Gavin Wood,Christian Reitwiessner,Alex Beregszaszi,Liana Husikyan,Yoichi Hirai和其他幾位早期以太坊核心貢獻者。[2][3]Solidity 可使程式開發人員能在區塊鏈上(例如以太坊)編寫智能合約[4][5][6]

歷史[编辑]

Solidity的語法概念最早是由加文·伍德英语Gavin Wood在2014年提出,[7]後期則以Christian Reitwiessner所領導的以太坊團隊Solidity接手開發。該語言是針對以太坊虛擬機(EVM)所設計的四種語言之一(其他的還有Serpent,LLL,Viper(實驗中)和Mutan(已棄用))。有關這些語言的更多信息,請參閱以太坊編程語言

Solidity是目前在以太坊及其他以太坊競爭平台中的主要編程語言,例如Monax及其Burrow Hyperledger的區塊鏈就是使用Tendermint完成共識機制。 SWIFT亦已經使用Solidity在Burrow上完成了概念驗證。[8]

康奈爾大學的研究人員指出,Solidity即是導致DAO在2016年被駭客攻擊的部分原因之一。他表示:“這實際上並不是DAO合同本身的缺陷或漏洞;技術上來說,DAO確實是在EVM上如預期般地被執行,反而是Solidity將安全上的漏洞引入了合約之中,而這些漏洞不僅沒被開發社群察覺,Solidity語言的設計者們也忽略了。[9][10]

描述[编辑]

Solidity是一種靜態型別的程式語言,用於開發在EVM上執行的智能合約。 Solidity被編譯為可在EVM上執行的位元組碼[11][12] 藉由Solidity,開發人員能夠編寫出可自我執行其欲實現之商業邏輯的應用程式,該程式可被視為一份具權威性且永不可悔改的交易合約。[13][14]對已具備程式編輯能力的人而言,編寫Solidity的難易度就如同編寫一般的程式語言。[15]

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可在下列平台中運作:

  • Ethereum
  • Tendermint & ErisDB
  • Zeppelin
  • Counterparty

参考文献[编辑]

  1. ^ Allison, Ian. PwC blockchain expert pinpoints sources of ambiguity in smart contracts. IBTimes (News). 12 August 2016 [14 December 2016]. 
  2. ^ Alyssa Hertig. Blockchain Veterans Unveil Secure Smart Contracts Framework. CoinDesk. 15 September 2016 [14 December 2016]. 
  3. ^ Rebecca Campbell. Counterparty Brings Ethereum Smart Contracts to the Bitcoin Blockchain. CCN. 6 September 2016 [14 December 2016]. 
  4. ^ In Formal Verification Push, Ethereum Seeks Smart Contract Certainty. CoinDesk (News). 28 September 2016 [12 December 2016]. 
  5. ^ 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]. 
  6. ^ Browning, David. Digital Siege: Why Young Entrepreneurs Are Winning. May 2016 [2017-01-08]. ISBN 978-1628652963. (原始内容存档于2017-01-09). 
  7. ^ Benoit Schweblin. StackEdit Viewer. stackedit.io.  |author=|last=只需其一 (帮助)|author=|last=只需其一 (帮助)
  8. ^ KENTOURIS, CHRIS. Blockchain’s Smart Contracts: What’s Smart, What’s Not. Finops (News). 13 December 2016 [14 December 2016]. 
  9. ^ Quentson, Andrew. Ethereum’s Solidity Flaw Exploited in DAO Attack Says Cornell Researcher. CryptocoinNews (News). 19 June 2016 [14 December 2016]. 
  10. ^ Finley, Klint. A $50 MILLION HACK JUST SHOWED THAT THE DAO WAS ALL TOO HUMAN. Wired (News). 18 June 2016 [18 February 2017]. 
  11. ^ Mougayar, William. The Business Blockchain: Promise, Practice, and Application of the Next Internet Technology. Wiley Publishing. 2016-04-26. ISBN 978-1119300311. 
  12. ^ Allison, Ian. Microsoft adds Ethereum language Solidity to Visual Studio. International Business Times. 2016-03-30 [2016-05-11]. 
  13. ^ Bradley, Joseph. Ethereum's Solidity Now Available in Microsoft Visual Studio. Cryptocoinnews. 2016-05-04 [2016-05-11]. 
  14. ^ Allison, Ian. Microsoft adds Ethereum language Solidity to Visual Studio. International Business Times. 30 March 2016 [11 May 2016]. 
  15. ^ 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. 
  16. ^ Ethereum's Solidity Now Available in Microsoft Visual Studio. CCN: Financial Bitcoin & Cryptocurrency News. [1 May 2016]. 
  17. ^ Microsoft Adds Ethereum to Windows Platform For Over 3 Million Developers. CoinDesk. [1 May 2016]. 
  18. ^ Blockchain and big data worth watching in the coming year. Business. International Business Times. December 20, 2016 [2017-09-28] (英语). 
  19. ^ 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) (英语). 

外部連結[编辑]