aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-06-29 23:41:59 +0800
committerchriseth <chris@ethereum.org>2018-07-03 07:02:00 +0800
commitf7a9c4203e35439de6ff4bdd94c7083c16b73e43 (patch)
treeae55099d02be2a04c769cf4868f57239365d1583
parent4649f9202a93f7573d7fb425fbcbdd50e6d4407c (diff)
downloaddexon-solidity-f7a9c4203e35439de6ff4bdd94c7083c16b73e43.tar
dexon-solidity-f7a9c4203e35439de6ff4bdd94c7083c16b73e43.tar.gz
dexon-solidity-f7a9c4203e35439de6ff4bdd94c7083c16b73e43.tar.bz2
dexon-solidity-f7a9c4203e35439de6ff4bdd94c7083c16b73e43.tar.lz
dexon-solidity-f7a9c4203e35439de6ff4bdd94c7083c16b73e43.tar.xz
dexon-solidity-f7a9c4203e35439de6ff4bdd94c7083c16b73e43.tar.zst
dexon-solidity-f7a9c4203e35439de6ff4bdd94c7083c16b73e43.zip
Disallow packed encoding of literals.
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/analysis/TypeChecker.cpp24
-rw-r--r--libsolidity/interface/ErrorReporter.h6
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp10
-rw-r--r--test/libsolidity/syntaxTests/tight_packing_literals.sol2
-rw-r--r--test/libsolidity/syntaxTests/tight_packing_literals_050.sol9
6 files changed, 20 insertions, 32 deletions
diff --git a/Changelog.md b/Changelog.md
index baa98389..17de16a6 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -27,6 +27,7 @@ Breaking Changes:
* Optimizer: Remove the no-op ``PUSH1 0 NOT AND`` sequence.
* Parser: Disallow trailing dots that are not followed by a number.
* Type Checker: Disallow arithmetic operations for boolean variables.
+ * Type Checker: Disallow tight packing of literals. This was already the case in the experimental 0.5.0 mode.
* Type Checker: Disallow conversions between ``bytesX`` and ``uintY`` of different size.
* Type Checker: Only accept a single ``bytes`` type for ``.call()`` (and family), ``keccak256()``, ``sha256()`` and ``ripemd160()``.
* Remove obsolete ``std`` directory from the Solidity repository. This means accessing ``https://github.com/ethereum/soldity/blob/develop/std/*.sol`` (or ``https://github.com/ethereum/solidity/std/*.sol`` in Remix) will not be possible.
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index b9e3f8d0..500d4123 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -1702,8 +1702,6 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
else
_functionCall.annotation().type = make_shared<TupleType>(returnTypes);
- bool const v050 = m_scope->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050);
-
if (auto functionName = dynamic_cast<Identifier const*>(&_functionCall.expression()))
{
if (functionName->name() == "sha3" && functionType->kind() == FunctionType::Kind::SHA3)
@@ -1723,23 +1721,15 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
auto const& argType = type(*arguments[i]);
if (auto literal = dynamic_cast<RationalNumberType const*>(argType.get()))
{
- /* If no mobile type is available an error will be raised elsewhere. */
if (literal->mobileType())
+ m_errorReporter.typeError(
+ arguments[i]->location(),
+ "Cannot perform packed encoding for a literal. Please convert it to an explicit type first."
+ );
+ else
{
- if (v050)
- m_errorReporter.typeError(
- arguments[i]->location(),
- "Cannot perform packed encoding for a literal. Please convert it to an explicit type first."
- );
- else
- m_errorReporter.warning(
- arguments[i]->location(),
- "The type of \"" +
- argType->toString() +
- "\" was inferred as " +
- literal->mobileType()->toString() +
- ". This is probably not desired. Use an explicit type to silence this warning."
- );
+ /* If no mobile type is available an error will be raised elsewhere. */
+ solAssert(m_errorReporter.hasErrors(), "");
}
}
}
diff --git a/libsolidity/interface/ErrorReporter.h b/libsolidity/interface/ErrorReporter.h
index d1a0030f..fd53587a 100644
--- a/libsolidity/interface/ErrorReporter.h
+++ b/libsolidity/interface/ErrorReporter.h
@@ -92,6 +92,12 @@ public:
void clear();
+ /// @returns true iff there is any error (ignores warnings).
+ bool hasErrors() const
+ {
+ return m_errorCount > 0;
+ }
+
private:
void error(Error::Type _type,
SourceLocation const& _location,
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 31842777..85848d88 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -2082,7 +2082,7 @@ BOOST_AUTO_TEST_CASE(packed_keccak256)
function a(bytes32 input) returns (bytes32 hash) {
uint24 b = 65536;
uint c = 256;
- return keccak256(abi.encodePacked(8, input, b, input, c));
+ return keccak256(abi.encodePacked(uint8(8), input, b, input, c));
}
}
)";
@@ -2134,7 +2134,7 @@ BOOST_AUTO_TEST_CASE(packed_sha256)
function a(bytes32 input) returns (bytes32 hash) {
uint24 b = 65536;
uint c = 256;
- return sha256(abi.encodePacked(8, input, b, input, c));
+ return sha256(abi.encodePacked(uint8(8), input, b, input, c));
}
}
)";
@@ -2161,7 +2161,7 @@ BOOST_AUTO_TEST_CASE(packed_ripemd160)
function a(bytes32 input) returns (bytes32 hash) {
uint24 b = 65536;
uint c = 256;
- return ripemd160(abi.encodePacked(8, input, b, input, c));
+ return ripemd160(abi.encodePacked(uint8(8), input, b, input, c));
}
}
)";
@@ -3578,7 +3578,7 @@ BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments_with_numeric_literals)
contract c {
function foo(uint a, uint16 b) returns (bytes32 d)
{
- d = keccak256(abi.encodePacked(a, b, 145));
+ d = keccak256(abi.encodePacked(a, b, uint8(145)));
}
}
)";
@@ -3603,7 +3603,7 @@ BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments_with_string_literals)
}
function bar(uint a, uint16 b) returns (bytes32 d)
{
- d = keccak256(abi.encodePacked(a, b, 145, "foo"));
+ d = keccak256(abi.encodePacked(a, b, uint8(145), "foo"));
}
}
)";
diff --git a/test/libsolidity/syntaxTests/tight_packing_literals.sol b/test/libsolidity/syntaxTests/tight_packing_literals.sol
index be8482ff..a136aa77 100644
--- a/test/libsolidity/syntaxTests/tight_packing_literals.sol
+++ b/test/libsolidity/syntaxTests/tight_packing_literals.sol
@@ -5,4 +5,4 @@ contract C {
}
// ----
-// Warning: (92-93): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning.
+// TypeError: (92-93): Cannot perform packed encoding for a literal. Please convert it to an explicit type first.
diff --git a/test/libsolidity/syntaxTests/tight_packing_literals_050.sol b/test/libsolidity/syntaxTests/tight_packing_literals_050.sol
deleted file mode 100644
index 4e6210c6..00000000
--- a/test/libsolidity/syntaxTests/tight_packing_literals_050.sol
+++ /dev/null
@@ -1,9 +0,0 @@
-pragma experimental "v0.5.0";
-contract C {
- function k() pure public returns (bytes) {
- return abi.encodePacked(1);
- }
-}
-
-// ----
-// TypeError: (122-123): Cannot perform packed encoding for a literal. Please convert it to an explicit type first.