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)
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 Solidity's default safe math.
FuelVM 中的数学默认是安全的(即任何溢出或异常都会引发恐慌)。安全检查是在 VM 实现中本地执行的,而不是像 Solidity 的默认安全数学那样在字节码级别执行。
无* 代码大小限制 (No* Code Size Limit)
There is no practical code size limit to Sway contracts. The physical limit is governed by theVM_MAX_RAM
VM parameter, which at the time of writing is 64 MiB.
Sway 合约没有实际的代码大小限制。物理限制由 VM_MAX_RAM
VM 参数控制,在撰写本文时该参数为 64 MiB。
账户类型 (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。
Last updated