mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge remote-tracking branch 'origin/develop' into breaking
This commit is contained in:
@@ -1,4 +1,12 @@
|
||||
[
|
||||
{
|
||||
"name": "MemoryArrayCreationOverflow",
|
||||
"summary": "The creation of very large memory arrays can result in overlapping memory regions and thus memory corruption.",
|
||||
"description": "No runtime overflow checks were performed for the length of memory arrays during creation. In cases for which the memory size of an array in bytes, i.e. the array length times 32, is larger than 2^256-1, the memory allocation will overflow, potentially resulting in overlapping memory areas. The length of the array is still stored correctly, so copying or iterating over such an array will result in out-of-gas.",
|
||||
"introduced": "0.2.0",
|
||||
"fixed": "0.6.5",
|
||||
"severity": "low"
|
||||
},
|
||||
{
|
||||
"name": "YulOptimizerRedundantAssignmentBreakContinue",
|
||||
"summary": "The Yul optimizer can remove essential assignments to variables declared inside for loops when Yul's continue or break statement is used. You are unlikely to be affected if you do not use inline assembly with for loops and continue and break statements.",
|
||||
|
||||
@@ -151,6 +151,7 @@
|
||||
},
|
||||
"0.2.0": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"ExpExponentCleanup",
|
||||
"NestedArrayFunctionCallDecoder",
|
||||
"ZeroFunctionSelector",
|
||||
@@ -171,6 +172,7 @@
|
||||
},
|
||||
"0.2.1": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"ExpExponentCleanup",
|
||||
"NestedArrayFunctionCallDecoder",
|
||||
"ZeroFunctionSelector",
|
||||
@@ -191,6 +193,7 @@
|
||||
},
|
||||
"0.2.2": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"ExpExponentCleanup",
|
||||
"NestedArrayFunctionCallDecoder",
|
||||
"ZeroFunctionSelector",
|
||||
@@ -211,6 +214,7 @@
|
||||
},
|
||||
"0.3.0": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"IncorrectEventSignatureInLibraries_0.4.x",
|
||||
"ExpExponentCleanup",
|
||||
@@ -233,6 +237,7 @@
|
||||
},
|
||||
"0.3.1": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"IncorrectEventSignatureInLibraries_0.4.x",
|
||||
"ExpExponentCleanup",
|
||||
@@ -254,6 +259,7 @@
|
||||
},
|
||||
"0.3.2": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"IncorrectEventSignatureInLibraries_0.4.x",
|
||||
"ExpExponentCleanup",
|
||||
@@ -275,6 +281,7 @@
|
||||
},
|
||||
"0.3.3": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"IncorrectEventSignatureInLibraries_0.4.x",
|
||||
"ExpExponentCleanup",
|
||||
@@ -295,6 +302,7 @@
|
||||
},
|
||||
"0.3.4": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"IncorrectEventSignatureInLibraries_0.4.x",
|
||||
"ExpExponentCleanup",
|
||||
@@ -315,6 +323,7 @@
|
||||
},
|
||||
"0.3.5": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"IncorrectEventSignatureInLibraries_0.4.x",
|
||||
"ExpExponentCleanup",
|
||||
@@ -335,6 +344,7 @@
|
||||
},
|
||||
"0.3.6": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"IncorrectEventSignatureInLibraries_0.4.x",
|
||||
"ExpExponentCleanup",
|
||||
@@ -353,6 +363,7 @@
|
||||
},
|
||||
"0.4.0": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"IncorrectEventSignatureInLibraries_0.4.x",
|
||||
"ExpExponentCleanup",
|
||||
@@ -371,6 +382,7 @@
|
||||
},
|
||||
"0.4.1": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"IncorrectEventSignatureInLibraries_0.4.x",
|
||||
"ExpExponentCleanup",
|
||||
@@ -389,6 +401,7 @@
|
||||
},
|
||||
"0.4.10": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"UninitializedFunctionPointerInConstructor_0.4.x",
|
||||
@@ -405,6 +418,7 @@
|
||||
},
|
||||
"0.4.11": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"UninitializedFunctionPointerInConstructor_0.4.x",
|
||||
@@ -420,6 +434,7 @@
|
||||
},
|
||||
"0.4.12": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"UninitializedFunctionPointerInConstructor_0.4.x",
|
||||
@@ -434,6 +449,7 @@
|
||||
},
|
||||
"0.4.13": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"UninitializedFunctionPointerInConstructor_0.4.x",
|
||||
@@ -448,6 +464,7 @@
|
||||
},
|
||||
"0.4.14": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"UninitializedFunctionPointerInConstructor_0.4.x",
|
||||
@@ -461,6 +478,7 @@
|
||||
},
|
||||
"0.4.15": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"UninitializedFunctionPointerInConstructor_0.4.x",
|
||||
@@ -473,6 +491,7 @@
|
||||
},
|
||||
"0.4.16": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"ABIEncoderV2StorageArrayWithMultiSlotElement",
|
||||
@@ -487,6 +506,7 @@
|
||||
},
|
||||
"0.4.17": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"ABIEncoderV2StorageArrayWithMultiSlotElement",
|
||||
@@ -502,6 +522,7 @@
|
||||
},
|
||||
"0.4.18": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"ABIEncoderV2StorageArrayWithMultiSlotElement",
|
||||
@@ -516,6 +537,7 @@
|
||||
},
|
||||
"0.4.19": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"ABIEncoderV2StorageArrayWithMultiSlotElement",
|
||||
@@ -531,6 +553,7 @@
|
||||
},
|
||||
"0.4.2": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"IncorrectEventSignatureInLibraries_0.4.x",
|
||||
"ExpExponentCleanup",
|
||||
@@ -548,6 +571,7 @@
|
||||
},
|
||||
"0.4.20": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"ABIEncoderV2StorageArrayWithMultiSlotElement",
|
||||
@@ -563,6 +587,7 @@
|
||||
},
|
||||
"0.4.21": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"ABIEncoderV2StorageArrayWithMultiSlotElement",
|
||||
@@ -578,6 +603,7 @@
|
||||
},
|
||||
"0.4.22": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"ABIEncoderV2StorageArrayWithMultiSlotElement",
|
||||
@@ -593,6 +619,7 @@
|
||||
},
|
||||
"0.4.23": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"ABIEncoderV2StorageArrayWithMultiSlotElement",
|
||||
@@ -607,6 +634,7 @@
|
||||
},
|
||||
"0.4.24": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"ABIEncoderV2StorageArrayWithMultiSlotElement",
|
||||
@@ -621,6 +649,7 @@
|
||||
},
|
||||
"0.4.25": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"ABIEncoderV2StorageArrayWithMultiSlotElement",
|
||||
@@ -633,6 +662,7 @@
|
||||
},
|
||||
"0.4.26": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"ABIEncoderV2StorageArrayWithMultiSlotElement",
|
||||
@@ -642,6 +672,7 @@
|
||||
},
|
||||
"0.4.3": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"IncorrectEventSignatureInLibraries_0.4.x",
|
||||
"ExpExponentCleanup",
|
||||
@@ -658,6 +689,7 @@
|
||||
},
|
||||
"0.4.4": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"IncorrectEventSignatureInLibraries_0.4.x",
|
||||
"ExpExponentCleanup",
|
||||
@@ -673,6 +705,7 @@
|
||||
},
|
||||
"0.4.5": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"UninitializedFunctionPointerInConstructor_0.4.x",
|
||||
"IncorrectEventSignatureInLibraries_0.4.x",
|
||||
@@ -690,6 +723,7 @@
|
||||
},
|
||||
"0.4.6": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"UninitializedFunctionPointerInConstructor_0.4.x",
|
||||
"IncorrectEventSignatureInLibraries_0.4.x",
|
||||
@@ -706,6 +740,7 @@
|
||||
},
|
||||
"0.4.7": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"UninitializedFunctionPointerInConstructor_0.4.x",
|
||||
@@ -722,6 +757,7 @@
|
||||
},
|
||||
"0.4.8": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"UninitializedFunctionPointerInConstructor_0.4.x",
|
||||
@@ -738,6 +774,7 @@
|
||||
},
|
||||
"0.4.9": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"UninitializedFunctionPointerInConstructor_0.4.x",
|
||||
@@ -754,6 +791,7 @@
|
||||
},
|
||||
"0.5.0": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"ABIEncoderV2StorageArrayWithMultiSlotElement",
|
||||
@@ -766,6 +804,7 @@
|
||||
},
|
||||
"0.5.1": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"ABIEncoderV2StorageArrayWithMultiSlotElement",
|
||||
@@ -778,6 +817,7 @@
|
||||
},
|
||||
"0.5.10": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"YulOptimizerRedundantAssignmentBreakContinue0.5",
|
||||
"ABIEncoderV2CalldataStructsWithStaticallySizedAndDynamicallyEncodedMembers"
|
||||
@@ -786,6 +826,7 @@
|
||||
},
|
||||
"0.5.11": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"YulOptimizerRedundantAssignmentBreakContinue0.5"
|
||||
],
|
||||
@@ -793,6 +834,7 @@
|
||||
},
|
||||
"0.5.12": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"YulOptimizerRedundantAssignmentBreakContinue0.5"
|
||||
],
|
||||
@@ -800,6 +842,7 @@
|
||||
},
|
||||
"0.5.13": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"YulOptimizerRedundantAssignmentBreakContinue0.5"
|
||||
],
|
||||
@@ -807,6 +850,7 @@
|
||||
},
|
||||
"0.5.14": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"YulOptimizerRedundantAssignmentBreakContinue0.5",
|
||||
"ABIEncoderV2LoopYulOptimizer"
|
||||
@@ -815,6 +859,7 @@
|
||||
},
|
||||
"0.5.15": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"YulOptimizerRedundantAssignmentBreakContinue0.5"
|
||||
],
|
||||
@@ -822,16 +867,20 @@
|
||||
},
|
||||
"0.5.16": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden"
|
||||
],
|
||||
"released": "2020-01-02"
|
||||
},
|
||||
"0.5.17": {
|
||||
"bugs": [],
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow"
|
||||
],
|
||||
"released": "2020-03-17"
|
||||
},
|
||||
"0.5.2": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"ABIEncoderV2StorageArrayWithMultiSlotElement",
|
||||
@@ -844,6 +893,7 @@
|
||||
},
|
||||
"0.5.3": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"ABIEncoderV2StorageArrayWithMultiSlotElement",
|
||||
@@ -856,6 +906,7 @@
|
||||
},
|
||||
"0.5.4": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"ABIEncoderV2StorageArrayWithMultiSlotElement",
|
||||
@@ -868,6 +919,7 @@
|
||||
},
|
||||
"0.5.5": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"SignedArrayStorageCopy",
|
||||
"ABIEncoderV2StorageArrayWithMultiSlotElement",
|
||||
@@ -882,6 +934,7 @@
|
||||
},
|
||||
"0.5.6": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"ABIEncoderV2CalldataStructsWithStaticallySizedAndDynamicallyEncodedMembers",
|
||||
"SignedArrayStorageCopy",
|
||||
@@ -896,6 +949,7 @@
|
||||
},
|
||||
"0.5.7": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"ABIEncoderV2CalldataStructsWithStaticallySizedAndDynamicallyEncodedMembers",
|
||||
"SignedArrayStorageCopy",
|
||||
@@ -908,6 +962,7 @@
|
||||
},
|
||||
"0.5.8": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"YulOptimizerRedundantAssignmentBreakContinue0.5",
|
||||
"ABIEncoderV2CalldataStructsWithStaticallySizedAndDynamicallyEncodedMembers",
|
||||
@@ -919,6 +974,7 @@
|
||||
},
|
||||
"0.5.9": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"privateCanBeOverridden",
|
||||
"YulOptimizerRedundantAssignmentBreakContinue0.5",
|
||||
"ABIEncoderV2CalldataStructsWithStaticallySizedAndDynamicallyEncodedMembers",
|
||||
@@ -929,24 +985,37 @@
|
||||
},
|
||||
"0.6.0": {
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow",
|
||||
"YulOptimizerRedundantAssignmentBreakContinue"
|
||||
],
|
||||
"released": "2019-12-17"
|
||||
},
|
||||
"0.6.1": {
|
||||
"bugs": [],
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow"
|
||||
],
|
||||
"released": "2020-01-02"
|
||||
},
|
||||
"0.6.2": {
|
||||
"bugs": [],
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow"
|
||||
],
|
||||
"released": "2020-01-27"
|
||||
},
|
||||
"0.6.3": {
|
||||
"bugs": [],
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow"
|
||||
],
|
||||
"released": "2020-02-18"
|
||||
},
|
||||
"0.6.4": {
|
||||
"bugs": [],
|
||||
"bugs": [
|
||||
"MemoryArrayCreationOverflow"
|
||||
],
|
||||
"released": "2020-03-10"
|
||||
},
|
||||
"0.6.5": {
|
||||
"bugs": [],
|
||||
"released": "2020-04-06"
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,49 @@
|
||||
.. index:: ! constant
|
||||
|
||||
************************
|
||||
Constant State Variables
|
||||
************************
|
||||
**************************************
|
||||
Constant and Immutable State Variables
|
||||
**************************************
|
||||
|
||||
State variables can be declared as ``constant``. In this case, they have to be
|
||||
assigned from an expression which is a constant at compile time. Any expression
|
||||
State variables can be declared as ``constant`` or ``immutable``.
|
||||
In both cases, the variables cannot be modified after the contract has been constructed.
|
||||
For ``constant`` variables, the value has to be fixed at compile-time, while
|
||||
for ``immutable``, it can still be assigned at construction time.
|
||||
|
||||
The compiler does not reserve a storage slot for these variables, and every occurrence is
|
||||
replaced by the respective value.
|
||||
|
||||
Not all types for constants and immutables are implemented at this time. The only supported types are
|
||||
`strings <strings>`_ (only for constants) and `value types <value-types>`_.
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >0.6.4 <0.7.0;
|
||||
|
||||
contract C {
|
||||
uint constant X = 32**22 + 8;
|
||||
string constant TEXT = "abc";
|
||||
bytes32 constant MY_HASH = keccak256("abc");
|
||||
uint immutable decimals;
|
||||
uint immutable maxBalance;
|
||||
address immutable owner = msg.sender;
|
||||
|
||||
constructor(uint _decimals, address _reference) public {
|
||||
decimals = _decimals;
|
||||
// Assignments to immutables can even access the environment.
|
||||
maxBalance = _reference.balance;
|
||||
}
|
||||
|
||||
function isBalanceTooHigh(address _other) public view returns (bool) {
|
||||
return _other.balance > maxBalance;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Constant
|
||||
========
|
||||
|
||||
For ``constant`` variables, the value has to be a constant at compile time and it has to be
|
||||
assigned where the variable is declared. Any expression
|
||||
that accesses storage, blockchain data (e.g. ``now``, ``address(this).balance`` or
|
||||
``block.number``) or
|
||||
execution data (``msg.value`` or ``gasleft()``) or makes calls to external contracts is disallowed. Expressions
|
||||
@@ -18,18 +56,17 @@ The reason behind allowing side-effects on the memory allocator is that it
|
||||
should be possible to construct complex objects like e.g. lookup-tables.
|
||||
This feature is not yet fully usable.
|
||||
|
||||
The compiler does not reserve a storage slot for these variables, and every occurrence is
|
||||
replaced by the respective constant expression (which might be computed to a single value by the optimizer).
|
||||
Immutable
|
||||
=========
|
||||
|
||||
Not all types for constants are implemented at this time. The only supported types are
|
||||
value types and strings.
|
||||
Variables declared as ``immutable`` are a bit less restricted than those
|
||||
declared as ``constant``: Immutable variables can be assigned an arbitrary
|
||||
value in the constructor of the contract or at the point of their declaration.
|
||||
They cannot be read during construction time and can only be assigned once.
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.4.0 <0.8.0;
|
||||
|
||||
contract C {
|
||||
uint constant X = 32**22 + 8;
|
||||
string constant TEXT = "abc";
|
||||
bytes32 constant MY_HASH = keccak256("abc");
|
||||
}
|
||||
The contract creation code generated by the compiler will modify the
|
||||
contract's runtime code before it is returned by replacing all references
|
||||
to immutables by the values assigned to the them. This is important if
|
||||
you are comparing the
|
||||
runtime code generated by the compiler with the one actually stored in the
|
||||
blockchain.
|
||||
|
||||
@@ -184,7 +184,7 @@ invalid bids.
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >0.4.23 <0.8.0;
|
||||
pragma solidity >=0.5.0 <0.8.0;
|
||||
|
||||
contract BlindAuction {
|
||||
struct Bid {
|
||||
|
||||
@@ -1,193 +0,0 @@
|
||||
SourceUnit = (PragmaDirective | ImportDirective | ContractDefinition)*
|
||||
|
||||
// Pragma actually parses anything up to the trailing ';' to be fully forward-compatible.
|
||||
PragmaDirective = 'pragma' Identifier ([^;]+) ';'
|
||||
|
||||
ImportDirective = 'import' StringLiteral ('as' Identifier)? ';'
|
||||
| 'import' ('*' | Identifier) ('as' Identifier)? 'from' StringLiteral ';'
|
||||
| 'import' '{' Identifier ('as' Identifier)? ( ',' Identifier ('as' Identifier)? )* '}' 'from' StringLiteral ';'
|
||||
|
||||
ContractDefinition = 'abstract'? ( 'contract' | 'library' | 'interface' ) Identifier
|
||||
( 'is' InheritanceSpecifier (',' InheritanceSpecifier )* )?
|
||||
'{' ContractPart* '}'
|
||||
|
||||
ContractPart = StateVariableDeclaration | UsingForDeclaration
|
||||
| StructDefinition | ModifierDefinition | FunctionDefinition | EventDefinition | EnumDefinition
|
||||
|
||||
InheritanceSpecifier = UserDefinedTypeName ( '(' Expression ( ',' Expression )* ')' )?
|
||||
|
||||
StateVariableDeclaration = TypeName ( 'public' | 'internal' | 'private' | 'constant' | OverrideSpecifier )* Identifier ('=' Expression)? ';'
|
||||
UsingForDeclaration = 'using' Identifier 'for' ('*' | TypeName) ';'
|
||||
StructDefinition = 'struct' Identifier '{'
|
||||
( VariableDeclaration ';' (VariableDeclaration ';')* ) '}'
|
||||
|
||||
ModifierDefinition = 'modifier' Identifier ParameterList? ( 'virtual' | OverrideSpecifier )* Block
|
||||
ModifierInvocation = Identifier ( '(' ExpressionList? ')' )?
|
||||
|
||||
FunctionDefinition = FunctionDescriptor ParameterList
|
||||
( ModifierInvocation | StateMutability | 'external' | 'public' | 'internal' | 'private' | 'virtual' | OverrideSpecifier )*
|
||||
( 'returns' ParameterList )? ( ';' | Block )
|
||||
|
||||
FunctionDescriptor = 'function' Identifier | 'constructor' | 'fallback' | 'receive'
|
||||
|
||||
OverrideSpecifier = 'override' ( '(' UserDefinedTypeName (',' UserDefinedTypeName)* ')' )?
|
||||
|
||||
EventDefinition = 'event' Identifier EventParameterList 'anonymous'? ';'
|
||||
|
||||
EnumValue = Identifier
|
||||
EnumDefinition = 'enum' Identifier '{' EnumValue? (',' EnumValue)* '}'
|
||||
|
||||
ParameterList = '(' ( Parameter (',' Parameter)* )? ')'
|
||||
Parameter = TypeName StorageLocation? Identifier?
|
||||
|
||||
EventParameterList = '(' ( EventParameter (',' EventParameter )* )? ')'
|
||||
EventParameter = TypeName 'indexed'? Identifier?
|
||||
|
||||
FunctionTypeParameterList = '(' ( FunctionTypeParameter (',' FunctionTypeParameter )* )? ')'
|
||||
FunctionTypeParameter = TypeName StorageLocation?
|
||||
|
||||
// semantic restriction: mappings and structs (recursively) containing mappings
|
||||
// are not allowed in argument lists
|
||||
VariableDeclaration = TypeName StorageLocation? Identifier
|
||||
|
||||
TypeName = ElementaryTypeName
|
||||
| UserDefinedTypeName
|
||||
| Mapping
|
||||
| ArrayTypeName
|
||||
| FunctionTypeName
|
||||
| ( 'address' 'payable' )
|
||||
|
||||
UserDefinedTypeName = Identifier ( '.' Identifier )*
|
||||
|
||||
Mapping = 'mapping' '(' ( ElementaryTypeName | UserDefinedTypeName ) '=>' TypeName ')'
|
||||
ArrayTypeName = TypeName '[' Expression? ']'
|
||||
FunctionTypeName = 'function' FunctionTypeParameterList ( 'internal' | 'external' | StateMutability )*
|
||||
( 'returns' FunctionTypeParameterList )?
|
||||
StorageLocation = 'memory' | 'storage' | 'calldata'
|
||||
StateMutability = 'pure' | 'view' | 'payable'
|
||||
|
||||
Block = '{' Statement* '}'
|
||||
Statement = IfStatement | TryStatement | WhileStatement | ForStatement | Block | InlineAssemblyStatement |
|
||||
( DoWhileStatement | PlaceholderStatement | Continue | Break | Return |
|
||||
Throw | EmitStatement | SimpleStatement ) ';'
|
||||
|
||||
ExpressionStatement = Expression
|
||||
IfStatement = 'if' '(' Expression ')' Statement ( 'else' Statement )?
|
||||
TryStatement = 'try' Expression ( 'returns' ParameterList )? Block CatchClause+
|
||||
CatchClause = 'catch' ( Identifier? ParameterList )? Block
|
||||
WhileStatement = 'while' '(' Expression ')' Statement
|
||||
PlaceholderStatement = '_'
|
||||
SimpleStatement = VariableDefinition | ExpressionStatement
|
||||
ForStatement = 'for' '(' (SimpleStatement)? ';' (Expression)? ';' (ExpressionStatement)? ')' Statement
|
||||
InlineAssemblyStatement = 'assembly' StringLiteral? AssemblyBlock
|
||||
DoWhileStatement = 'do' Statement 'while' '(' Expression ')'
|
||||
Continue = 'continue'
|
||||
Break = 'break'
|
||||
Return = 'return' Expression?
|
||||
Throw = 'throw'
|
||||
EmitStatement = 'emit' FunctionCall
|
||||
VariableDefinition = (VariableDeclaration | '(' VariableDeclaration? (',' VariableDeclaration? )* ')' ) ( '=' Expression )?
|
||||
|
||||
// Precedence by order (see github.com/ethereum/solidity/pull/732)
|
||||
Expression
|
||||
= Expression ('++' | '--')
|
||||
| NewExpression
|
||||
| IndexAccess
|
||||
| IndexRangeAccess
|
||||
| MemberAccess
|
||||
| FunctionCall
|
||||
| Expression '{' NameValueList '}'
|
||||
| '(' Expression ')'
|
||||
| ('!' | '~' | 'delete' | '++' | '--' | '+' | '-') Expression
|
||||
| Expression '**' Expression
|
||||
| Expression ('*' | '/' | '%') Expression
|
||||
| Expression ('+' | '-') Expression
|
||||
| Expression ('<<' | '>>') Expression
|
||||
| Expression '&' Expression
|
||||
| Expression '^' Expression
|
||||
| Expression '|' Expression
|
||||
| Expression ('<' | '>' | '<=' | '>=') Expression
|
||||
| Expression ('==' | '!=') Expression
|
||||
| Expression '&&' Expression
|
||||
| Expression '||' Expression
|
||||
| Expression '?' Expression ':' Expression
|
||||
| Expression ('=' | '|=' | '^=' | '&=' | '<<=' | '>>=' | '+=' | '-=' | '*=' | '/=' | '%=') Expression
|
||||
| PrimaryExpression
|
||||
|
||||
PrimaryExpression = BooleanLiteral
|
||||
| NumberLiteral
|
||||
| HexLiteral
|
||||
| StringLiteral
|
||||
| TupleExpression
|
||||
| Identifier
|
||||
| ElementaryTypeNameExpression
|
||||
|
||||
ExpressionList = Expression ( ',' Expression )*
|
||||
NameValueList = Identifier ':' Expression ( ',' Identifier ':' Expression )*
|
||||
|
||||
FunctionCall = Expression '(' FunctionCallArguments ')'
|
||||
FunctionCallArguments = '{' NameValueList? '}'
|
||||
| ExpressionList?
|
||||
|
||||
NewExpression = 'new' TypeName
|
||||
MemberAccess = Expression '.' Identifier
|
||||
IndexAccess = Expression '[' Expression? ']'
|
||||
IndexRangeAccess = Expression '[' Expression? ':' Expression? ']'
|
||||
|
||||
BooleanLiteral = 'true' | 'false'
|
||||
NumberLiteral = ( HexNumber | DecimalNumber ) (' ' NumberUnit)?
|
||||
NumberUnit = 'wei' | 'szabo' | 'finney' | 'ether'
|
||||
| 'seconds' | 'minutes' | 'hours' | 'days' | 'weeks' | 'years'
|
||||
HexLiteral = 'hex' ('"' ([0-9a-fA-F]{2})* '"' | '\'' ([0-9a-fA-F]{2})* '\'')
|
||||
StringLiteral = '"' ([^"\r\n\\] | '\\' .)* '"'
|
||||
Identifier = [a-zA-Z_$] [a-zA-Z_$0-9]*
|
||||
|
||||
HexNumber = '0x' [0-9a-fA-F]+
|
||||
DecimalNumber = [0-9]+ ( '.' [0-9]* )? ( [eE] [0-9]+ )?
|
||||
|
||||
TupleExpression = '(' ( Expression? ( ',' Expression? )* )? ')'
|
||||
| '[' ( Expression ( ',' Expression )* )? ']'
|
||||
|
||||
ElementaryTypeNameExpression = ElementaryTypeName
|
||||
|
||||
ElementaryTypeName = 'address' | 'bool' | 'string' | Int | Uint | Byte | Fixed | Ufixed
|
||||
|
||||
Int = 'int' | 'int8' | 'int16' | 'int24' | 'int32' | 'int40' | 'int48' | 'int56' | 'int64' | 'int72' | 'int80' | 'int88' | 'int96' | 'int104' | 'int112' | 'int120' | 'int128' | 'int136' | 'int144' | 'int152' | 'int160' | 'int168' | 'int176' | 'int184' | 'int192' | 'int200' | 'int208' | 'int216' | 'int224' | 'int232' | 'int240' | 'int248' | 'int256'
|
||||
|
||||
Uint = 'uint' | 'uint8' | 'uint16' | 'uint24' | 'uint32' | 'uint40' | 'uint48' | 'uint56' | 'uint64' | 'uint72' | 'uint80' | 'uint88' | 'uint96' | 'uint104' | 'uint112' | 'uint120' | 'uint128' | 'uint136' | 'uint144' | 'uint152' | 'uint160' | 'uint168' | 'uint176' | 'uint184' | 'uint192' | 'uint200' | 'uint208' | 'uint216' | 'uint224' | 'uint232' | 'uint240' | 'uint248' | 'uint256'
|
||||
|
||||
Byte = 'byte' | 'bytes' | 'bytes1' | 'bytes2' | 'bytes3' | 'bytes4' | 'bytes5' | 'bytes6' | 'bytes7' | 'bytes8' | 'bytes9' | 'bytes10' | 'bytes11' | 'bytes12' | 'bytes13' | 'bytes14' | 'bytes15' | 'bytes16' | 'bytes17' | 'bytes18' | 'bytes19' | 'bytes20' | 'bytes21' | 'bytes22' | 'bytes23' | 'bytes24' | 'bytes25' | 'bytes26' | 'bytes27' | 'bytes28' | 'bytes29' | 'bytes30' | 'bytes31' | 'bytes32'
|
||||
|
||||
Fixed = 'fixed' | ( 'fixed' [0-9]+ 'x' [0-9]+ )
|
||||
|
||||
Ufixed = 'ufixed' | ( 'ufixed' [0-9]+ 'x' [0-9]+ )
|
||||
|
||||
|
||||
AssemblyBlock = '{' AssemblyStatement* '}'
|
||||
|
||||
AssemblyStatement = AssemblyBlock
|
||||
| AssemblyFunctionDefinition
|
||||
| AssemblyVariableDeclaration
|
||||
| AssemblyAssignment
|
||||
| AssemblyIf
|
||||
| AssemblyExpression
|
||||
| AssemblySwitch
|
||||
| AssemblyForLoop
|
||||
| AssemblyBreakContinue
|
||||
| AssemblyLeave
|
||||
AssemblyFunctionDefinition =
|
||||
'function' Identifier '(' AssemblyIdentifierList? ')'
|
||||
( '->' AssemblyIdentifierList )? AssemblyBlock
|
||||
AssemblyVariableDeclaration = 'let' AssemblyIdentifierList ( ':=' AssemblyExpression )?
|
||||
AssemblyAssignment = AssemblyIdentifierList ':=' AssemblyExpression
|
||||
AssemblyExpression = AssemblyFunctionCall | Identifier | Literal
|
||||
AssemblyIf = 'if' AssemblyExpression AssemblyBlock
|
||||
AssemblySwitch = 'switch' AssemblyExpression ( AssemblyCase+ AssemblyDefault? | AssemblyDefault )
|
||||
AssemblyCase = 'case' Literal AssemblyBlock
|
||||
AssemblyDefault = 'default' AssemblyBlock
|
||||
AssemblyForLoop = 'for' AssemblyBlock AssemblyExpression AssemblyBlock AssemblyBlock
|
||||
AssemblyBreakContinue = 'break' | 'continue'
|
||||
AssemblyLeave = 'leave'
|
||||
AssemblyFunctionCall = Identifier '(' ( AssemblyExpression ( ',' AssemblyExpression )* )? ')'
|
||||
|
||||
AssemblyIdentifierList = Identifier ( ',' Identifier )*
|
||||
@@ -788,6 +788,7 @@ Modifiers
|
||||
- ``view`` for functions: Disallows modification of state.
|
||||
- ``payable`` for functions: Allows them to receive Ether together with a call.
|
||||
- ``constant`` for state variables: Disallows assignment (except initialisation), does not occupy storage slot.
|
||||
- ``immutable`` for state variables: Allows exactly one assignment at construction time and is constant afterwards. Is stored in code.
|
||||
- ``anonymous`` for events: Does not store event signature as topic.
|
||||
- ``indexed`` for event parameters: Stores the parameter as topic.
|
||||
- ``virtual`` for functions and modifiers: Allows the function's or modifier's
|
||||
@@ -809,5 +810,5 @@ These keywords are reserved in Solidity. They might become part of the syntax in
|
||||
Language Grammar
|
||||
================
|
||||
|
||||
.. literalinclude:: grammar.txt
|
||||
:language: none
|
||||
.. literalinclude:: Solidity.g4
|
||||
:language: antlr
|
||||
|
||||
@@ -124,6 +124,12 @@ Accessing an array past its end causes a failing assertion. Methods ``.push()``
|
||||
to append a new element at the end of the array, where ``.push()`` appends a zero-initialized element and returns
|
||||
a reference to it.
|
||||
|
||||
.. index:: ! string, ! bytes
|
||||
|
||||
.. _strings:
|
||||
|
||||
.. _bytes:
|
||||
|
||||
``bytes`` and ``strings`` as Arrays
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
@@ -381,7 +387,7 @@ If ``start`` is greater than ``end`` or if ``end`` is greater
|
||||
than the length of the array, an exception is thrown.
|
||||
|
||||
Both ``start`` and ``end`` are optional: ``start`` defaults
|
||||
to ``0`` and ``end`` defaults to the length of the array.
|
||||
to ``0`` and ``end`` defaults to the length of the array.
|
||||
|
||||
Array slices do not have any members. They are implicitly
|
||||
convertible to arrays of their underlying type
|
||||
@@ -494,7 +500,7 @@ shown in the following example:
|
||||
|
||||
The contract does not provide the full functionality of a crowdfunding
|
||||
contract, but it contains the basic concepts necessary to understand structs.
|
||||
Struct types can be used inside mappings and arrays and they can itself
|
||||
Struct types can be used inside mappings and arrays and they can themselves
|
||||
contain mappings and arrays.
|
||||
|
||||
It is not possible for a struct to contain a member of its own type,
|
||||
|
||||
@@ -302,7 +302,8 @@ Input Description
|
||||
// evm.bytecode.opcodes - Opcodes list
|
||||
// evm.bytecode.sourceMap - Source mapping (useful for debugging)
|
||||
// evm.bytecode.linkReferences - Link references (if unlinked object)
|
||||
// evm.deployedBytecode* - Deployed bytecode (has the same options as evm.bytecode)
|
||||
// evm.deployedBytecode* - Deployed bytecode (has all the options that evm.bytecode has)
|
||||
// evm.deployedBytecode.immutableReferences - Map from AST ids to bytecode ranges that reference immutables
|
||||
// evm.methodIdentifiers - The list of function hashes
|
||||
// evm.gasEstimates - Function gas estimates
|
||||
// ewasm.wast - eWASM S-expressions format (not supported at the moment)
|
||||
@@ -424,8 +425,14 @@ Output Description
|
||||
}
|
||||
}
|
||||
},
|
||||
// The same layout as above.
|
||||
"deployedBytecode": { },
|
||||
"deployedBytecode": {
|
||||
..., // The same layout as above.
|
||||
"immutableReferences": [
|
||||
// There are two references to the immutable with AST ID 3, both 32 bytes long. One is
|
||||
// at bytecode offset 42, the other at bytecode offset 80.
|
||||
"3": [{ "start": 42, "length": 32 }, { "start": 80, "length": 32 }]
|
||||
]
|
||||
},
|
||||
// The list of function hashes
|
||||
"methodIdentifiers": {
|
||||
"delegate(address)": "5c19a95c"
|
||||
@@ -605,8 +612,8 @@ Assume you have the following contracts you want to update declared in ``Source.
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
// This will not compile
|
||||
pragma solidity >0.4.23;
|
||||
// This will not compile after 0.5.0
|
||||
pragma solidity >0.4.23 <0.5.0;
|
||||
|
||||
contract Updateable {
|
||||
function run() public view returns (bool);
|
||||
|
||||
Reference in New Issue
Block a user