Sway编程语言-更新中(The Sway Programming Language-Updatin
  • Sway编程语言(The Sway Programming Language)
  • 1. 导言(Introduction)
    • 1.1 安装(Installation)
    • 1.2 Sway快速入门 (Sway Quickstart)
    • 1.3 Fuel工具链 (The Fuel Toolchain)
    • 1.4 一个Forc项目 (A Forc Project)
    • 1.5 标准库 (Standard Library)
  • 2. 示例(Example)
    • 2.1计数器(Counter)
    • 2.2子货币(Subcurrency)
    • 2.3 FizzBuzz
    • 2.4 钱包智能合约(Wallet Smart Contract)
  • 3.Sway编程类型(Sway Program Types)
    • 3.1 合约(Contracts)
    • 3.2 库 (Libraries)
    • 3.3 脚本(Scripts)
    • 3.4 谓词 (Predicates)
  • 4. Sway语言基础 (Sway Language basics)
    • 4.1 变量 (Variables)
    • 4.2 内置类型(Built-in Types)
    • 4.3 常用库类型(Commonly Used Library Types)
    • 4.4 区块链类 (Blockchain Types)
    • 4.5 函数 (Functions)
    • 4.6 结构、元祖和穷举 (Structs, Tuples, and Enums)
    • 4.7 方法和关联函数 (Methods and Associated Functions)
    • 4.8 注释和日志 (Comments and Logging)
    • 4.9 控制流 (Control Flow)
  • 5. 用Sway部署区块链 (Blockchain Development with Sway)
    • 5.1 哈希和加密学 (Hashing and Cryptography)
    • 5.2 合约存储(Contract Storage)
    • 5.3 函数纯度 (Function Purity)
    • 5.4 标识符(Identifiers)
    • 5.5 原生资产(Native Assets)
    • 5.6 访问控制 (Access Control)
    • 5.7 调用合约(Calling Contracts)
  • 6. 高级概念 (Advanced Concepts)
    • 6.1 高级类型 (Advanced Types)
    • 6.2 通用类型 (Generic Types)
    • 6.3 特征 (Traits)
    • 6.4 集 (Assembly)
  • 7. 一般集聚 (Common Collections)
    • 7.1 堆上的向量(Vectors on the Heap)
    • 7.2 存储向量 (Storage Vectors)
    • 7.3 存储映射 (Storage Maps)
  • 8.测试(Testing)
    • 8.1 单元测试(Unit Testing)
    • 8.2 用Rust来测试 (Testing with Rust)
  • 9.应用前端开发 (Application Frontend Development)
    • 9.1 TypeScript SDK
  • 10.Sway应用(Sway Reference)
    • 10.1 编译器内部函数(Compiler Intrinsics)
    • 10.2 属性(Attributes)
    • 10.3 风格向导(Style Guide)
    • 10.4 已知各类问题(Known Issues and Workarounds)
    • 10.5 与Solidity的不同之处 (Differences From Solidity)
    • 10.6 与Rust的不同之处 (Differences From Rust)
    • 10.7 向Sway贡献 (Contributing To Sway)
  • 11. Forc引用 (Forc Reference)
    • 11.1清单参考 (Manifest Reference)
    • 11.2 工作区(Workspaces)
    • 11.3 依赖(Dependencies)
    • 11.4 命令(Commands)
      • 11.4.1 forc-addr2line
      • 11.4.2 forc-build
      • 11.4.3 forc-check
Powered by GitBook
On this page
  • 底层虚拟机 (Underlying Virtual Machine)
  • 字符大小(Word Size)
  • 仅支持无符号整数 (Unsigned Integers Only)
  • 全局恢复 (Global Revert)
  • 默认安全数学 (Default Safe Math)
  • 无* 代码大小限制 (No* Code Size Limit)
  • 账户类型 (Account Types)
  1. 10.Sway应用(Sway Reference)

10.5 与Solidity的不同之处 (Differences From Solidity)

This page outlines some of the critical differences between Sway and Solidity, and between the FuelVM and the EVM.

本页概述了 Sway 和 Solidity 之间以及 FuelVM 和 EVM 之间的一些关键区别。

底层虚拟机 (Underlying Virtual Machine)

The underlying virtual machine targeted by Sway is the FuelVM, specified here. Solidity targets the Ethereum Virtual Machine (EVM), specified here.

Sway 所针对的底层虚拟机是 FuelVM,在此处指定。 Solidity 的目标是此处指定的以太坊虚拟机 (EVM)。

字符大小(Word Size)

Words in the FuelVM are 64 bits (8 bytes), rather than the 256 bits (32 bytes) of the EVM. Therefore, primitive integers only go up to u64, and hashes (the b256 type) are not in registers but rather in memory. A b256 is therefore a pointer to a 32-byte memory region containing the hash value.

FuelVM 中的字为 64 位(8 字节),而不是 EVM 的 256 位(32 字节)。因此,原始整数最多只能达到 u64,而哈希值(b256 类型)不在注册器中,而是在内存中。因此,b256 是指向包含哈希值的 32 字节内存区域的指针。

仅支持无符号整数 (Unsigned Integers Only)

Only unsigned integers are provided as primitives: u8, u16, u32, and u64. Signed integer arithmetic is not available in the FuelVM. Signed integers and signed integer arithmetic can be implemented in high-level libraries if needed.

仅支持无符号整数作为原语提供:u8、u16、u32 和 u64。有符号整数算术在 FuelVM 中不可用。但若需要,有符号整数和有符号整数算术可以在高级库中实现。

全局恢复 (Global Revert)

Panics in the FuelVM (called "reverts" in Solidity and the EVM) are global, i.e. they cannot be caught. A panic will completely and unconditionally revert the stateful effects of a transaction, minus gas used.

FuelVM 中的恐慌(在 Solidity 和 EVM 中称为“恢复”)是全局性的,即它们无法被捕获。恐慌将完全无条件地恢复交易的状态影响,会减去所使用的gas。

默认安全数学 (Default Safe Math)

无* 代码大小限制 (No* Code Size Limit)

账户类型 (Account Types)

Account types in the FuelVM have type-safe wrappers around primitive b256 hashes to clearly distinguish their respective types. The wrapper Address mirrors that of an EOA (Externally Owned Account) and has the ability to hold UTXOs in the context of the EVM. The other wrapper, ContractId, reflects that of a deployed contract in the EVM but cannot hold UTXOs.

FuelVM 中的帐户类型具有围绕原始 b256 哈希值的类型安全封装器,进而明确地区分其各自的类型。封装器地址反映了 EOA(外部拥有帐户)的地址,并且能够在 EVM 的上下文中保存 UTXO。另一个封装器 ContractId 反映了 EVM 中已部署合约的封装器,但不能保存 UTXO。

Previous10.4 已知各类问题(Known Issues and Workarounds)Next10.6 与Rust的不同之处 (Differences From Rust)

Last updated 1 year ago

Math in the FuelVM is by default safe (i.e. any overflow or exception is a panic). Safety checks are performed natively in the VM implementation, rather than at the bytecode level like .

FuelVM 中的数学默认是安全的(即任何溢出或异常都会引发恐慌)。安全检查是在 VM 实现中本地执行的,而不是像 Solidity 的默认那样在字节码级别执行。

There is no practical code size limit to Sway contracts. The physical limit is governed by the, which at the time of writing is 64 MiB.

Sway 合约没有实际的代码大小限制。物理限制由 控制,在撰写本文时该参数为 64 MiB。

Solidity's default safe math
安全数学
VM_MAX_RAM VM parameter
VM_MAX_RAM VM 参数