Vyper 標誌

Vyper

Vyper 是一種 Python 式的智慧合約語言,它可以編譯成以太坊虛擬機(EVM)位元組碼。它優先考慮安全性、可稽核性和簡潔性 。

Principles

  • 安全性:建置安全的智慧合約應該是自然而然的事情,而不是一場艱苦的戰鬥。

  • 簡潔性:語言和編譯器都應該易於理解。

  • 可稽核性:程式碼應盡可能易於閱讀。對讀者而言,簡潔性比對編寫者而言的便利性更為重要。

Key Features

Safety by default

  • Bounds and overflow checking on array accesses and arithmetic

  • Reentrancy protection via the @nonreentrant decorator (see 控制結構)

  • Strong typing with explicit type conversions

Predictable execution

  • Decidable gas consumption: every function call has a calculable upper bound

  • Bounded loops only (compile-time maximum iterations)

  • No recursion: execution flow is structurally decreasing

Clean code reuse

  • Module imports instead of class inheritance

  • Explicit extcall and staticcall keywords for external contract interactions

  • Support for pure functions that cannot modify state

編譯器強制執行的安全機制

Vyper eliminates entire vulnerability classes by excluding features that enable dangerous patterns:

Excluded Feature

Why It Matters

Inline assembly

Preserves type safety, overflow protection, and searchability of variable usage

類別繼承

Removes ambiguity about which code executes and simplifies auditing

Modifiers

All checks are inline and visible, no hidden pre/post conditions

函式覆載

Function calls are unambiguous; foo(x) always means the same thing

運算子覆載

Arithmetic operators do exactly what they appear to do

無限迴圈

Gas costs are always bounded and predictable

遞迴呼叫

Call graphs are simple and gas limits are enforceable

These constraints mean developers cannot accidentally introduce dangerous patterns, even under time pressure or with limited blockchain experience.

十進位定點數

Vyper uses decimal (not binary) fixed point numbers. This ensures that literals like 0.1 have exact representations, avoiding the subtle precision errors common in binary floating-point arithmetic.