From e3791d6dcff4fccd6f3b8e54abda953eb624799f Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 22 Jan 2019 12:30:46 +0100 Subject: [PATCH] Fix reported packed encoded size for arrays and structs. --- Changelog.md | 4 ++++ libsolidity/ast/Types.cpp | 11 +++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Changelog.md b/Changelog.md index ceb1402a8..9ab994bf4 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,9 @@ ### 0.5.4 (unreleased) +Bugfixes: + * Type system: Properly report packed encoded size for arrays and structs (mostly unused until now). + + Language Features: diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 3a8c9878f..691579042 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -1716,8 +1716,10 @@ bigint ArrayType::unlimitedCalldataEncodedSize(bool _padded) const { if (isDynamicallySized()) return 32; - bigint size = bigint(length()) * (isByteArray() ? 1 : baseType()->calldataEncodedSize(_padded)); - size = ((size + 31) / 32) * 32; + // Array elements are always padded. + bigint size = bigint(length()) * (isByteArray() ? 1 : baseType()->calldataEncodedSize(true)); + if (_padded) + size = ((size + 31) / 32) * 32; return size; } @@ -2034,7 +2036,7 @@ bool StructType::operator==(Type const& _other) const return ReferenceType::operator==(other) && other.m_struct == m_struct; } -unsigned StructType::calldataEncodedSize(bool _padded) const +unsigned StructType::calldataEncodedSize(bool) const { unsigned size = 0; for (auto const& member: members(nullptr)) @@ -2042,7 +2044,8 @@ unsigned StructType::calldataEncodedSize(bool _padded) const return 0; else { - unsigned memberSize = member.type->calldataEncodedSize(_padded); + // Struct members are always padded. + unsigned memberSize = member.type->calldataEncodedSize(true); if (memberSize == 0) return 0; size += memberSize;