Vyper Overview
Despite there being concerns about its compiler and the slower rate of development compared to Solidity, there are still many resources and ways to build smart contracts using Vyper. In this section, we’ll discuss more about the Vyper language and provide resources where you can learn more about the language. Please note, Vyper is still considered somewhat experimental.
Vyper Design Principles
Vyper has a few principles and goals that aim to make it a language that is ideal for programming smart contracts. From its docs (which we quote extensively in this section):
- Security is a primary focus for any smart contract language and Vyper maintains that “it should be possible and natural to build secure smart contracts in Vyper.”
- Vyper code should be not just human readable, but make it difficult to write misleading code. This directive is aimed at making contract audits as successful as possible.
- Striving for language and compiler simplicity support the other goals by keeping confusing complexity under control.
To achieve these goals, Vyper implements the following features:
- Bounds and overflow checking
- Support for signed integers and decimal fixed point numbers
- Decidability - Reliably compute upper bounds for gas consumption of any function call
- Strong typing
- Small and understandable compiler code
- Limited support for pure functions
There is a notable lack of the following features that are present in Solidity:
- Modifiers Modifiers make it easier to write misleading code. It encourages writing code where execution jumps around the source file, making audits more difficult. Vyper encourages inline checks in each function to improve clarity.
- Class Inheritance Inheritance also makes it easier to write misleading code. Contracts’ logic is spread across multiple files, decreasing readability and requires additional understanding about how inheritance works in case of conflicts.
- Inline Assembly Inline assembly makes it possible to manipulate variables without referencing it directly by name. This makes development and auditing more difficult and can obfuscate bugs.
- Function overloading Contracts with overloaded functions can be confusing. It may not be clear which function is being called in specific situations.
- Operator overloading
- Recursive calling It is not possible to set an upper bound on gas limits in contracts with recursive calling
- Infinite-length loops It is not possible to set an upper bound on gas limits in contracts with infinite length loops
- Binary fixed point In binary fixed point, approximations are required (e.g. in Python 0.3 + 0.3 + 0.3 + 0.1 != 1).
As you can see in the list of features that Vyper is lacking, writing clear, understandable code is of primary importance.
Vyper is not trying to be a replacement for Solidity. It is meant to be a more security focused smart contract programming language and will likely not be able to do everything that Solidity can.
Additional Links
- Code: Simple Bank in Vyper (ConsenSys Academy) This is a Vyper version of our Simple Bank exercise (normally in Solidity) you’ll encounter later in this section.
- Course: Learn Vyper (0.2) A comprehensive series of videos that covers Data Types, Functions, Variables, Logic Control, Errors, Interfaces and much more.
- Tutorial: Develop a DeFi Project using Python (Chainlink)
- Tutorial: Vyper and Brownie Contract Development on EVM Chains An interesting tutorial walking through developing a contract using Vyper and Brownie.
- Docs: Vyper by Example From the Vyper documentation, a walkthrough of common development patterns in Vyper.