Change ABIEncoderV1 to not pad empty strings

This commit is contained in:
Alex Beregszaszi
2020-12-01 14:32:18 +00:00
parent 390640f557
commit d22434ee57
6 changed files with 16 additions and 8 deletions
+7 -2
View File
@@ -531,10 +531,15 @@ void CompilerUtils::encodeToMemory(
if (_givenTypes[i]->category() == Type::Category::StringLiteral)
{
auto const& strType = dynamic_cast<StringLiteralType const&>(*_givenTypes[i]);
m_context << u256(strType.value().size());
auto const size = strType.value().size();
m_context << u256(size);
storeInMemoryDynamic(*TypeProvider::uint256(), true);
// stack: ... <end_of_mem'>
storeInMemoryDynamic(strType, _padToWordBoundaries);
// Do not output empty padding for zero-length strings.
// TODO: handle this in storeInMemoryDynamic
if (size != 0)
storeInMemoryDynamic(strType, _padToWordBoundaries);
}
else
{
+3 -2
View File
@@ -104,12 +104,13 @@ public:
/// Stores a 256 bit integer from stack in memory.
/// @param _offset offset in memory
void storeInMemory(unsigned _offset);
/// Dynamic version of @see storeInMemory, expects the memory offset below the value on the stack
/// and also updates that. For reference types, only copies the data pointer. Fails for
/// non-memory-references.
/// non-memory-references. For string literals no value is available on the stack.
/// @param _padToWords if true, adds zeros to pad to multiple of 32 bytes. Array elements
/// are always padded (except for byte arrays), regardless of this parameter.
/// @param _cleanup if true, adds code to cleanup the value before storing it.
/// are always padded (except for byte arrays), regardless of this parameter.
/// Stack pre: memory_offset value...
/// Stack post: (memory_offset+length)
void storeInMemoryDynamic(Type const& _type, bool _padToWords = true, bool _cleanup = true);