aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-08-06 23:47:23 +0800
committerGitHub <noreply@github.com>2018-08-06 23:47:23 +0800
commit18588439085585afde8da81ca09b127db3b13d7b (patch)
tree8fe456f6fdf3e1fa4d2a23b4729c595848b05797
parentbc73617f5ebc6d8f254b8e7faa630738c9967bd5 (diff)
parent3b5eee499862c8df0a751527d310f68c42f08edf (diff)
downloaddexon-solidity-18588439085585afde8da81ca09b127db3b13d7b.tar
dexon-solidity-18588439085585afde8da81ca09b127db3b13d7b.tar.gz
dexon-solidity-18588439085585afde8da81ca09b127db3b13d7b.tar.bz2
dexon-solidity-18588439085585afde8da81ca09b127db3b13d7b.tar.lz
dexon-solidity-18588439085585afde8da81ca09b127db3b13d7b.tar.xz
dexon-solidity-18588439085585afde8da81ca09b127db3b13d7b.tar.zst
dexon-solidity-18588439085585afde8da81ca09b127db3b13d7b.zip
Merge pull request #4659 from ethereum/abiv2-fixedbytes
FixedBytes(0) is invalid, do not check for it in ABIEncoderV2
-rw-r--r--libsolidity/codegen/ABIFunctions.cpp3
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp38
2 files changed, 40 insertions, 1 deletions
diff --git a/libsolidity/codegen/ABIFunctions.cpp b/libsolidity/codegen/ABIFunctions.cpp
index 1ce77d67..dda77958 100644
--- a/libsolidity/codegen/ABIFunctions.cpp
+++ b/libsolidity/codegen/ABIFunctions.cpp
@@ -228,7 +228,8 @@ string ABIFunctions::cleanupFunction(Type const& _type, bool _revertOnFailure)
if (type.numBytes() == 32)
templ("body", "cleaned := value");
else if (type.numBytes() == 0)
- templ("body", "cleaned := 0");
+ // This is disallowed in the type system.
+ solAssert(false, "");
else
{
size_t numBits = type.numBytes() * 8;
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 066e97e6..9c287e5e 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -12489,6 +12489,44 @@ BOOST_AUTO_TEST_CASE(abi_encode_with_signaturev2)
ABI_CHECK(callContractFunction("f4()"), expectation);
}
+BOOST_AUTO_TEST_CASE(abi_encode_empty_string)
+{
+ char const* sourceCode = R"(
+ // Tests that this will not end up using a "bytes0" type
+ // (which would assert)
+ contract C {
+ function f() public pure returns (bytes memory, bytes memory) {
+ return (abi.encode(""), abi.encodePacked(""));
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ ABI_CHECK(callContractFunction("f()"), encodeArgs(
+ 0x40, 0xc0,
+ 0x60, 0x20, 0x00, 0x00,
+ 0x00
+ ));
+}
+
+BOOST_AUTO_TEST_CASE(abi_encode_empty_string_v2)
+{
+ char const* sourceCode = R"(
+ // Tests that this will not end up using a "bytes0" type
+ // (which would assert)
+ pragma experimental ABIEncoderV2;
+ contract C {
+ function f() public pure returns (bytes memory, bytes memory) {
+ return (abi.encode(""), abi.encodePacked(""));
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "C");
+ ABI_CHECK(callContractFunction("f()"), encodeArgs(
+ 0x40, 0xa0,
+ 0x40, 0x20, 0x00,
+ 0x00
+ ));
+}
BOOST_AUTO_TEST_CASE(abi_encode_call)
{
char const* sourceCode = R"T(