Skip to content

Commit 337d63a

Browse files
author
Leonardo Alt
committed
Disallow indexed reference types in events when using ABIEncoderV2
1 parent 6c0261e commit 337d63a

File tree

8 files changed

+52
-0
lines changed

8 files changed

+52
-0
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Bugfixes:
108108
* Type Checker: Fix crashes in erroneous tuple assignments in which the type of the right hand side cannot be determined.
109109
* Type Checker: Fix freeze for negative fixed-point literals very close to ``0``, such as ``-1e-100``.
110110
* Type Checker: Report error when using structs in events without experimental ABIEncoderV2. This used to crash or log the wrong values.
111+
* Type Checker: Report error when using indexed structs in events with experimental ABIEncoderV2. This used to log wrong values.
111112
* Type System: Allow arbitrary exponents for literals with a mantissa of zero.
112113

113114
### 0.4.24 (2018-05-16)

libsolidity/analysis/TypeChecker.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,17 @@ bool TypeChecker::visit(EventDefinition const& _eventDef)
895895
for (ASTPointer<VariableDeclaration> const& var: _eventDef.parameters())
896896
{
897897
if (var->isIndexed())
898+
{
898899
numIndexed++;
900+
if (
901+
_eventDef.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::ABIEncoderV2)
902+
&& dynamic_cast<ReferenceType const*>(type(*var).get())
903+
)
904+
m_errorReporter.typeError(
905+
var->location(),
906+
"Reference types cannot be indexed."
907+
);
908+
}
899909
if (!type(*var)->canLiveOutsideStorage())
900910
m_errorReporter.typeError(var->location(), "Type is required to live outside storage.");
901911
if (!type(*var)->interfaceType(false))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pragma experimental ABIEncoderV2;
2+
contract c {
3+
event E(uint[] indexed);
4+
}
5+
// ----
6+
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
7+
// TypeError: (59-65): Reference types cannot be indexed.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pragma experimental ABIEncoderV2;
2+
contract c {
3+
event E(uint[]);
4+
}
5+
// ----
6+
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pragma experimental ABIEncoderV2;
2+
contract c {
3+
event E(uint[][] indexed);
4+
}
5+
// ----
6+
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
7+
// TypeError: (59-67): Reference types cannot be indexed.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pragma experimental ABIEncoderV2;
2+
contract c {
3+
event E(uint[][]);
4+
}
5+
// ----
6+
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pragma experimental ABIEncoderV2;
2+
contract c {
3+
struct S { uint a ; }
4+
event E(S indexed);
5+
}
6+
// ----
7+
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
8+
// TypeError: (85-86): Reference types cannot be indexed.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pragma experimental ABIEncoderV2;
2+
contract c {
3+
struct S { uint a ; }
4+
event E(S);
5+
}
6+
// ----
7+
// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.

0 commit comments

Comments
 (0)