Feature Guide for Solidity

September 6, 2021 · View on GitHub

Feature Guide for Solidity

Introduction

In this guide, we will list all Solidity language features and briefly summarize the current status and limitations about SOLL implementation.

Supported Language Features

  • Contract declaration
    • Constructor without parameters
  • Type support
    • Value types: bool, int, uint, address
    • Literal types: Address Literals, Rational and Integer Literals, String Literals, Hexadecimal Literals
    • Mapping types: mapping
    • String types: string
    • Array types:
      • Support compile-time fixed size array
      • Fixed-Size byte arrays
      • Dynamically-Size byte arrays
    • Struct types
    • Support both implicit/explicit type casting
  • Storage declaration
  • Event declaration and emit event statements
    • Support keywords event, emit
  • Function declaration
    • Visibility: public, private, internal, external
    • State Mutability view, pure
    • Support payable
    • Support fallback function declaration and keyword fallback
  • Units and Globally Available Variables
    • Ether Units: ether, finney, szabo, wei
    • Time Units: weeks, days, hours, minutes, seconds
    • Members of Address Types:
      • <address>.balance (uint256)
      • <address payable>.transfer(uint256 amount)
      • <address payable>.send(uint256 amount) returns (bool)
    • Block and Transaction Properties:
      • blockhash(uint blockNumber) returns (bytes32)
      • block.coinbase (address payable)
      • block.difficulty (uint)
      • block.gaslimit (uint)
      • block.number (uint)
      • block.timestamp (uint)
      • gasleft() returns (uint256)
      • msg.data (bytes calldata)
      • msg.sender (address payable)
      • msg.sig (bytes4)
      • msg.value (uint)
      • now (uint)
      • tx.gasprice (uint)
      • tx.origin (address payable)
    • ABI Encoding and Decoding Functions(Experimental, Unstable):
      • abi.encode(...) returns (bytes memory)
      • abi.encodePacked(...) returns (bytes memory)
    • Contract Related: this
  • Error handling
    • Support require(), revert()
  • Grammar and statements
    • Binary operators
    • Unary operators
    • Exponentiation operators
    • Condition statements: if, else
    • Function call statements
    • Loop statements: while, do..while, for and nested loop statements are also supported.

Unimplemented Language Features / Known Issues

  • Library declaration
    • Keyword library is not yet supported.
  • Types
    • Contract types
    • Function types
    • Enums
    • Fixed Point Numbers
    • Dynamic size arrays
  • Units and Globally Available Variables
    • ABI Encoding and Decoding Functions:
      • abi.decode(bytes memory encodedData, (...)) returns (...)
      • abi.encodeWithSelector(bytes4 selector, ...) returns (bytes memory)
      • abi.encodeWithSignature(string memory signature, ...) returns (bytes memory)
    • Mathematical and Cryptographic Functions:
      • addmod(uint x, uint y, uint k) returns (uint)
      • mulmod(uint x, uint y, uint k) returns (uint)
      • keccak256(bytes memory) returns (bytes32)
      • sha256(bytes memory) returns (bytes32)
      • ripemd160(bytes memory) returns (bytes20)
      • ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address)
    • Members of Address Types:
      • <address>.call(bytes memory) returns (bool, bytes memory)
      • <address>.delegatecall(bytes memory) returns (bool, bytes memory)
      • <address>.staticcall(bytes memory) returns (bool, bytes memory)
    • Contract related: selfdestruct(address payable recipient)
    • Type Information: type(C).creationCode, type(C).runtimeCode
  • Modifier declaration and usage
    • Keyword modifier is not yet supported.
    • Developers should extend their modifier logic into function body directly
  • Multiple contracts declaration.
    • Developers can declare only one contract in a single file.
  • Contract inheritance
    • Keyword is is not yet supported.
  • Constructor with parameters
    • Because Ewasm deployer does not support deployment with constructor’s parameters.
  • Tuple declaration
    • Grammar () is not yet supported.
  • Multiple function return values
    • Due to the lack support of tuple, functions cannot return multiple values.
  • Inline assembly

Comparison table with Solidity 0.7.1

Layout

Layoutsupport
pragma solidityYes
pragma experimentalNo
interfaceNo
libraryYes
abstractYes
using A for B;No
Inline AssemblyNo

Global Variables

Global Variablessupport
abi.decodeNo
abi.encodeYes
abi.encodePackedYes
abi.encodeWithSelectorNo
abi.encodeWithSignatureNo
block.coinbaseYes
block.difficultyYes
block.gaslimitYes
block.numberYes
block.timestampYes
gasleftYes
msg.dataYes
msg.senderYes
msg.valueYes
tx.gaspriceYes
tx.originYes
assertYes
require(bool condition)Yes
require(bool condition, string memory message)Yes
revert()Yes
revert(string memory message)Yes
blockhashYes
keccak256Yes
sha256Yes
ripemd160Yes
ecrecoverYes
addmodYes
mulmodYes
thisYes
superNo
selfdestructNo
<address>.balanceYes
<address payable>.sendYes
<address payable>.transferYes
<address>.callYes
<address>.delegatecallYes
<address>.staticcallYes
type(C).nameNo
type(C).creationCodeNo
type(C).runtimeCodeNo
type(I).interfaceIdNo
type(T).minNo
type(T).maxNo

Opcode

Opcodesupport
stop()Yes
add(x, y)Yes
sub(x, y)Yes
mul(x, y)Yes
div(x, y)Yes
sdiv(x, y)Yes
mod(x, y)Yes
smod(x, y)No
exp(x, y)Yes
not(x)Yes
lt(x, y)Yes
gt(x, y)Yes
slt(x, y)Yes
sgt(x, y)Yes
eq(x, y)Yes
iszero(x)Yes
and(x, y)Yes
or(x, y)Yes
xor(x, y)Yes
byte(n, x)No
shl(x, y)Yes
shr(x, y)Yes
sar(x, y)Yes
addmod(x, y, m)Yes
mulmod(x, y, m)Yes
signextend(i, x)Yes
keccak256(p, n)Yes
pc()No
pop(x)No
mload(p)Yes
mstore(p, v)Yes
mstore8(p, v)Yes
sload(p)Yes
sstore(p, v)Yes
msize()Yes
gas()Yes
address()No
balance(a)No
selfbalance()No
caller()Yes
callvalue()Yes
calldataload(p)Yes
calldatasize()Yes
calldatacopy(t, f, s)No
codesize()No
codecopy(t, f, s)Yes
extcodesize(a)No
extcodecopy(a, t, f, s)No
returndatasize()No
returndatacopy(t, f, s)No
extcodehash(a)No
create(v, p, n)No
create2(v, p, n, s)No
call(g, a, v, in, insize, out, outsize)No
callcode(g, a, v, in, insize, out, outsize)No
delegatecall(g, a, in, insize, out, outsize)No
staticcall(g, a, in, insize, out, outsize)No
return(p, s)Yes
revert(p, s)Yes
selfdestruct(a)No
invalid()No
log0(p, s)Yes
log1(p, s, t1)Yes
log2(p, s, t1, t2)Yes
log3(p, s, t1, t2, t3)Yes
log4(p, s, t1, t2, t3, t4)Yes
chainid()No
origin()Yes
gasprice()Yes
blockhash(b)No
coinbase()Yes
timestamp()Yes
number()Yes
difficulty()Yes
gaslimit()Yes
datasize(x)Yes
dataoffset(x)Yes
datacopy(t, f, l)Yes
setimmutableNo
loadimmutableNo
linkersymbolNo

Types

Value Typessupport
BooleansYes
Booleans operatorYes
IntegersYes
Integers shift(<<, >>)No
type()No
Fixed Point NumbersNo
addressYes
address payableYes
EnumsNo
StructsYes (cannot assignment)
Literalssupport
Address LiteralsYes
Rational LiteralsNo
Scientific notationNo
Underscores (123_456)No
escape charactersNo
Unicode LiteralsNo
Hexadecimal LiteralsYes (separated by space not support)
Reference Typessupport
storageYes
memoryYes
calldataYes
Mapping Typessupport
mapping of mappingYes
mapping of string/bytesYes
mapping of structNo
Ether Unitssupport
weiYes
etherYes
gweiNo
Time Unitssupport
secondsYes
minutesYes
hoursYes
daysYes
weeksYes
Other Typessupport
deleteNo
Fixed-Size Byte Array String literals AssignNo
Function multi returnNo

Structure of a Contract

State Variables Typessupport
Value Types(int, uint, bool, ...)Yes
AddressYes
Contract TypesNo
Fixed-size byte arraysYes
Dynamically-sized byte arrayYes
ArraysNo
StructsYes
MappingYes
constantYes
immutableNo
Functions Typessupport
FunctionsYes
receiveNo
constructorYes
ModifiersNo
fallbackYes
Function OverloadingNo
Constructor with parameterNo
virtualNo
overrideNo
Otherssupport
EventsYes
InheritanceNo

Expressions and Control Structures

Control Structuressupport
if elseYes
whileYes
doNo
forYes
breakYes
continueYes
returnYes
Function Callssupport
Internal Function CallsYes
this.func()Yes
External Function CallsNo
Named CallsNo
Omitted Function Parameter NamesYes
Otherssupport
newNo
saltNo
try catchNo
tuple assignNo
Complications for ArraysYes
Complications for StructsYes