Solidity
{{Short description|Programming language}}
{{About|the programming language|the state of matter|Solid}}
{{primary sources|date=May 2021}}
{{Use dmy dates|date=July 2018}}
{{Infobox programming language
| name = Solidity
| logo = Solidity logo.svg
| logo caption = The Solidity language logo
| logo size = 80px
| paradigm = Imperative
| file ext = .sol
| released = August 2014
| designer = Gavin Wood
| developer = Christian Reitwiessner,{{Cite web |title=Contributors to ethereum/solidity |url=https://github.com/ethereum/solidity |access-date=2023-03-30 |website=GitHub |language=en}} Alex Beregszaszi,{{Cite web |title=Contributors to ethereum/solidity |url=https://github.com/ethereum/solidity |access-date=2023-03-30 |website=GitHub |language=en}} and several former Ethereum core contributors.
| programming language = C++{{Cite web |title=Build software better, together |url=https://github.com/ |access-date=2023-03-30 |website=GitHub |language=en}}
| latest release version = {{wikidata|property|reference|P348}}
| latest release date = {{start date and age|{{wikidata|qualifier|P348|P577}}}}
| influenced_by = JavaScript, C++, Python
| license = GNU General Public License v3.0{{Citation |title=The Solidity Contract-Oriented Programming Language |date=2023-03-30 |url=https://github.com/ethereum/solidity/blob/bca3fb8ffd7c57a3f6920fd5a115a9a0fc0edb21/LICENSE.txt |access-date=2023-03-30 |publisher=ethereum}}
| website = {{URL|https://soliditylang.org}}
}}
Solidity is a programming language for implementing smart contracts{{Cite web|url=https://www.huffpost.com/entry/ethereum-is-the-second-most-valuable-digital-currency_b_596bc5c7e4b022bb9372b2b2|title=Ethereum Is The Second Most Valuable Digital Currency, Behind Bitcoin|last1=Afshar|first1=Vala|date=2017-07-17|website=HuffPost|language=en|access-date=2019-04-10}}{{cite news |date=24 November 2016 |url=https://www.finextra.com/newsarticle/29813/sofe-berlin-swift-unveils-blockchain-proof-of-concept |title=SOFE Berlin: Swift unveils blockchain proof-of-concept |work=Finextra |type=News|access-date=24 November 2016}} on various blockchain platforms, most notably, Ethereum.{{cite magazine |title=Someone Just Stole $50 Million from the Biggest Crowdfunded Project Ever. (Humans Can't Be Trusted) |url=https://www.wired.com/2016/06/50-million-hack-just-showed-dao-human/ |magazine=Wired |language=en-us|last1=Finley |first1=Klint }} Solidity is licensed under GNU General Public License v3.0.{{Citation |title=The Solidity Contract-Oriented Programming Language |date=2023-03-30 |url=https://github.com/ethereum/solidity/blob/bca3fb8ffd7c57a3f6920fd5a115a9a0fc0edb21/LICENSE.txt |access-date=2023-03-30 |publisher=ethereum}} Solidity was designed by Gavin Wood{{Cite web |last=Wood |first=Gavin |date=January 13, 2015 |title=Created Solidity |url=https://github.com/ethereum/wiki/commit/a7849d4089240c00dc1974b469fe5053852df687?short_path=78b9c36#diff-78b9c36766ad236b6a23f87a983e91c2d18634e32bcd5f8d2d8e34322c7ecfb1 |access-date=2024-03-23 |website=Ethereum Wiki (Archived)}}{{primary source inline|date=February 2024}} and developed by Christian Reitwiessner, Alex Beregszaszi, and several former Ethereum core contributors.{{cite web|url=https://github.com/ethereum/solidity/graphs/contributors|title=List of contributors|website=GitHub}} Programs in Solidity run on Ethereum Virtual Machine or on compatible virtual machines.{{Cite book |last=College |first=A. M. C. |url=https://books.google.com/books?id=l96YEAAAQBAJ&dq=%22Solidity%22+-wikipedia&pg=PA20 |title=Blockchain & Cryptocurrency Technology with Solidity Level 1 |date=2022-11-01 |publisher=Advanced Micro Systems Sdn Bhd |language=en}}
History
Solidity was proposed in August 2014 by Gavin Wood{{Cite web |title=Gavin Wood |url=https://gavwood.com/ |url-status=dead |archive-url=https://web.archive.org/web/20230330221513/https://gavwood.com/ |archive-date=30 March 2023 |access-date=2023-03-30 |website=gavwood.com}}{{primary source inline|date=February 2024}} The language was later developed by the Ethereum project's Solidity team, led by Christian Reitwiessner.
Solidity is the primary language used to develop smart contracts for Ethereum as well as other private blockchains, such as the enterprise-oriented Hyperledger Fabric blockchain. SWIFT deployed a proof of concept using Solidity running on Hyperledger Fabric.{{cite arXiv |eprint=1802.06038 |class=cs.CR |first1=Ivica |last1=Nikolic |first2=Aashish |last2=Kolluri |title=Finding The Greedy, Prodigal, and Suicidal Contracts at Scale |date=14 March 2018 |last3=Sergey |first3=Ilya |last4=Saxena |first4=Prateek |last5=Hobor |first5=Aquinas |quote=Different source languages compile to the EVM semantics, the predominant of them being Solidity}}{{Cite web |title=Westpac joins SWIFT's blockchain proof of concept |url=https://www.zdnet.com/article/westpac-joins-swifts-blockchain-proof-of-concept/ |access-date=2022-07-13 |website=ZDNet |language=en}}
Description
Solidity is a statically typed programming language designed for developing smart contracts that run on the Ethereum Virtual Machine (EVM) or compatible virtual machines.{{Cite web|url=https://developer.ibm.com/patterns/loyalty-points-fabric-evm/|title=Hyperledger Fabric Tutorial - Create a blockchain app for loyalty points|website=IBM Developer|language=en-US|access-date=2019-04-10}}
Solidity uses ECMAScript-like syntax which makes it familiar for existing web developers;{{Cite web |title=Language Influences — Solidity 0.8.17 documentation |url=https://docs.soliditylang.org/en/v0.8.17/language-influences.html |access-date=2023-03-30 |website=docs.soliditylang.org}} however unlike ECMAScript it has static typing and variadic return types. Solidity is different from other EVM-targeting languages such as Serpent and Mutan in some important ways. It supports complex member variables for smart contracts, including arbitrarily hierarchical mappings and structs. Solidity smart contract support inheritance, including multiple inheritance with C3 linearization. Solidity introduces an application binary interface (ABI) that facilitates multiple type-safe functions within a single smart contract (this was also later supported by Serpent). The Solidity proposal also includes "Natural Language Specification", a documentation system for specifying user-centric descriptions of the ramifications of method-calls.{{Sfn|Kapetanios-2008-06-27|p=309}}{{cite web|url=https://github.com/ethereum/wiki/wiki/Ethereum-Natural-Specification-Format|title=Ethereum Natural Specification Format|author=ethereum|work=GitHub}}{{Primary source inline|date=December 2018}}
Example of a Solidity program:{{Cite web |title=Introduction to Smart Contracts — Solidity 0.8.19 documentation |url=https://docs.soliditylang.org/en/v0.8.19/introduction-to-smart-contracts.html#subcurrency-example |access-date=2023-03-30 |website=docs.soliditylang.org}}{{r|Bhargavan-2016-08-27}}
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.4;
contract Coin {
// The keyword "public" makes variables
// accessible from other contracts
address public minter;
mapping(address => uint) public balances;
// Events allow clients to react to specific
// contract changes you declare
event Sent(address from, address to, uint amount);
// Constructor code is only run when the contract
// is created
constructor() {
minter = msg.sender;
}
// Sends an amount of newly created coins to an address
// Can only be called by the contract creator
function mint(address receiver, uint amount) public {
require(msg.sender == minter);
balances[receiver] += amount;
}
// Errors allow you to provide information about
// why an operation failed. They are returned
// to the caller of the function.
error InsufficientBalance(uint requested, uint available);
// Sends an amount of existing coins
// from any caller to an address
function send(address receiver, uint amount) public {
if (amount > balances[msg.sender])
revert InsufficientBalance({
requested: amount,
available: balances[msg.sender]
});
balances[msg.sender] -= amount;
balances[receiver] += amount;
emit Sent(msg.sender, receiver, amount);
}
}
Development IDEs
- Microsoft Visual Studio Code
- JetBrains IntelliJ
- Remix Online Editor{{Cite web |title=Remix - Ethereum IDE |url=https://remix.ethereum.org/ |access-date=2023-03-30 |website=remix.ethereum.org}}
- EthFiddle Online Editor{{Cite web |title=EthFiddle - Solidity in the Browser. Powered By Loom Network |url=https://ethfiddle.com/OGURL |access-date=2023-03-30 |website=ethfiddle.com}}
Editor extensions
- Solidity Support for Visual Studio Code{{Cite web |title=solidity - Visual Studio Marketplace |url=https://marketplace.visualstudio.com/items?itemName=JuanBlanco.solidity |access-date=2023-03-30 |website=marketplace.visualstudio.com |language=en-us}}
- Solidity Support For IntelliJ{{Cite web |title=Solidity - IntelliJ IDEs Plugin {{!}} Marketplace |url=https://plugins.jetbrains.com/plugin/9475-solidity |access-date=2023-03-30 |website=JetBrains Marketplace}}
Blockchain platforms
Solidity is available on:
- Avalanche C-Chain
- Binance Smart Chain{{Cite web|title=Binance Smart Chain|website=GitHub|date=26 October 2021|url=https://github.com/binance-chain/bsc}}
- Counterparty (which runs on Bitcoin){{Cite news|last=Vigna|first=Michael J. Casey and Paul|date=2014-11-12|title=BitBeat: Bitcoin 2.0 Firm Counterparty Adopts Ethereum's Software|language=en-US|work=Wall Street Journal|url=https://blogs.wsj.com/moneybeat/2014/11/12/bitbeat-bitcoin-2-0-firm-counterparty-adopts-ethereums-software/|access-date=2021-04-16|issn=0099-9660}}{{Cite book|last=Swan|first=Melanie|url=https://www.worldcat.org/oclc/900781291|title=Blockchain : blueprint for a new economy|date=2015|isbn=978-1-4919-2047-3|edition=1st.|location=[Sebastopol, Calif.]|oclc=900781291}}
- Ethereum
- Ethereum Classic
- Tron
- Hedera Hashgraph
- Polygon
- Metis
- Arbitrum
- Optimism
Criticism
Many security properties of smart contracts are inherently difficult to reason about directly, and the Turing-completeness of Solidity means that verification of arbitrary properties cannot be decidably automated. Current automated solutions for smart contract security analysis can miss critical violations, produce false positives, and fail to achieve sufficient code coverage on realistic contracts.{{cite book |last1=Tsankov |first1=Petar |last2=Dan |first2=Andrei |last3=Drachsler-Cohen |first3=Dana |last4=Gervais |first4=Arthur |last5=Bünzli |first5=Florian |last6=Vechev |first6=Martin |chapter=Securify: Practical Security Analysis of Smart Contracts |title=Proceedings of the 2018 ACM SIGSAC Conference on Computer and Communications Security |publisher=Association for Computing Machinery |pages=67–82 |doi=10.1145/3243734.3243780 |date=15 October 2018|arxiv=1806.01143 |hdl=10044/1/87935 |isbn=978-1-4503-5693-0 |s2cid=46936025 }} Solidity has been blamed for the error-prone implementation of Ethereum smart contracts due to its counterintuitive nature, its lack of constructs to deal with blockchain domain-specific aspects, and its lack of centralized documentation of known vulnerabilities.{{cite book |last1=Atzei |first1=Nicola |last2=Bartoletti |first2=M. |last3=Cimoli |first3=Tiziana |title=Principles of Security and Trust, 6th International Conference, 2017, Proceedings |chapter=A Survey of Attacks on Ethereum Smart Contracts (SoK) |series=Lecture Notes in Computer Science |date=2017 |pages=164–186 |doi=10.1007/978-3-662-54455-6_8 |isbn=978-3-662-54454-9 |s2cid=15494854 }}
In 2016, a Cornell University researcher stated that Solidity was partially to blame for The DAO hack that took place that year. He stated: "this was actually not a flaw or exploit in the DAO contract itself: technically the Ethereum Virtual Machine (EVM) was operating as intended, but Solidity was introducing security flaws into contracts that were not only missed by the community, but missed by the designers of the language themselves."{{cite magazine |first1=Klint |last1=Finley |date=18 June 2016 |url=https://www.wired.com/2016/06/50-million-hack-just-showed-dao-human/ |title=A $50 Million Hack Just Showed That the DAO Was All Too Human |magazine=Wired |type=News |access-date=18 February 2017}}
The developers community often cites Solidity requiring much of third party interfaces and APIs, and its inability to create critical information intensive smart contracts.
Comparison with other smart contract languages
= Solidity vs. Rust =
Solidity is the primary programming language for developing smart contracts on the Ethereum Virtual Machine (EVM).{{Cite book |last1=Zheng |first1=Gavin |url=https://books.google.com/books?id=OGn6DwAAQBAJ&dq=%22Solidity%22+-wikipedia&pg=PR7 |title=Ethereum Smart Contract Development in Solidity |last2=Gao |first2=Longxiang |last3=Huang |first3=Liqun |last4=Guan |first4=Jian |date=2020-08-31 |publisher=Springer Nature |isbn=978-981-15-6218-1 |language=en}} However, Rust has emerged as a strong alternative in the blockchain ecosystem, especially for blockchains that support WebAssembly (Wasm), such as Polkadot, Klever and Solana.
== Memory safety ==
Rust offers built-in memory safety features that prevent common programming errors, such as null pointer dereferencing and buffer overflows, which are not as rigorously enforced in Solidity. This makes Rust contracts potentially less prone to security vulnerabilities that could be exploited in smart contract environments.
== Concurrency ==
Rust supports concurrent programming, which allows developers to write highly performant code that can handle multiple tasks simultaneously. This is particularly beneficial for high-performance blockchains like Solana,{{Cite web |title=Developing with Rust {{!}} Solana |url=https://solana.com/docs/programs/lang-rust |access-date=2024-08-16 |website=solana.com |language=en}} which need to process thousands of transactions per second. Solidity, on the other hand, does not natively support concurrency, which can limit its performance in certain applications.{{Cite web |title=Rust Official Documentation |url=https://www.rust-lang.org/}}
== Ecosystem integration ==
While Solidity is deeply integrated with the Ethereum ecosystem and its numerous development tools,{{Cite web |title=Solidity Lang |url=https://soliditylang.org/}} Rust is versatile and can be used across various blockchain platforms that leverage Wasm. Rust’s growing popularity is reflected in its adoption by new blockchain projects that prioritize performance and security.
References
{{Reflist|refs=
{{cite journal
| url = http://research.microsoft.com/en-us/um/people/nswamy/papers/solidether.pdf
| last1 = Schneier
| first1 = Karthikeyan
| last2 = Schneier
| first2 = Antoine
| last3 = Bhargavan
| first3 = Cedric
| last4 = Delignat-Lavaud
| first4 = Anitha
| last5 = Fournet
| first5 = Gollamudi
| last6 = Schneier
| first6 = Bruce
| last7 = Rastogi
| first7 = Nadim
| last8 = Sibut-Pinote
| first8 = Aseem
| last9 = Rastogi1
| first9 = Thomas
| last10 = Swamy
| first10 = Nikhil
| last11 = Zanella-Beguelin
| first11 = Santiago
| date = 27 August 2016
| title = Short Paper: Formal Verification of Smart Contracts
| journal = Microsoft Research, French Institute for Research in Computer Science and Automation, Harvard University
| language = en
| archive-url = https://web.archive.org/web/20160827092146/http://research.microsoft.com/en-us/um/people/nswamy/papers/solidether.pdf
| url-status = live
| archive-date = 27 August 2016
}}
}}
{{Cryptocurrencies}}
Category:Domain-specific programming languages