diff options
-rw-r--r-- | docs/miscellaneous.rst | 4 | ||||
-rw-r--r-- | libsolidity/interface/CompilerStack.cpp | 1 | ||||
-rw-r--r-- | libyul/YulString.h | 93 | ||||
-rw-r--r-- | libyul/optimiser/RedundantAssignEliminator.cpp | 73 | ||||
-rw-r--r-- | libyul/optimiser/RedundantAssignEliminator.h | 11 | ||||
-rwxr-xr-x | scripts/check_style.sh | 7 | ||||
-rw-r--r-- | test/libyul/Inliner.cpp | 6 | ||||
-rw-r--r-- | test/libyul/YulOptimizerTest.cpp | 2 | ||||
-rw-r--r-- | test/libyul/yulOptimizerTests/fullInliner/multi_fun_callback.yul | 13 | ||||
-rw-r--r-- | test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul | 654 |
10 files changed, 793 insertions, 71 deletions
diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index 8e4e8b99..21978ded 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -31,14 +31,14 @@ Statically-sized variables (everything except mapping and dynamically-sized arra declaring your storage variables in the order of ``uint128, uint128, uint256`` instead of ``uint128, uint256, uint128``, as the former will only take up two slots of storage whereas the latter will take up three. - + .. note:: The layout of state variables in storage is considered to be part of the external interface of Solidity due to the fact that storage pointers can be passed to libraries. This means that any change to the rules outlined in this section is considered a breaking change of the language and due to its critical nature should be considered very carefully before being executed. - + The elements of structs and arrays are stored after each other, just as if they were given explicitly. diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index e0909eb3..7aa0faa7 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -106,7 +106,6 @@ void CompilerStack::reset(bool _keepSources) m_stackState = Empty; m_sources.clear(); } - yul::YulStringRepository::instance().reset(); m_libraries.clear(); m_evmVersion = EVMVersion(); m_optimize = false; diff --git a/libyul/YulString.h b/libyul/YulString.h index a8015239..ad900a70 100644 --- a/libyul/YulString.h +++ b/libyul/YulString.h @@ -22,7 +22,7 @@ #include <boost/noncopyable.hpp> -#include <map> +#include <unordered_map> #include <memory> #include <vector> #include <string> @@ -32,72 +32,101 @@ namespace dev namespace yul { +/// Repository for YulStrings. +/// Owns the string data for all YulStrings, which can be referenced by a Handle. +/// A Handle consists of an ID (that depends on the insertion order of YulStrings and is potentially +/// non-deterministic) and a deterministic string hash. class YulStringRepository: boost::noncopyable { public: - YulStringRepository() + struct Handle { - reset(); - } + size_t id; + std::uint64_t hash; + }; + YulStringRepository(): + m_strings{std::make_shared<std::string>()}, + m_hashToID{std::make_pair(emptyHash(), 0)} + {} static YulStringRepository& instance() { static YulStringRepository inst; return inst; } - size_t stringToId(std::string const& _string) + Handle stringToHandle(std::string const& _string) { if (_string.empty()) - return 0; - size_t& id = m_ids[_string]; - if (id == 0) - { - m_strings.emplace_back(std::make_shared<std::string>(_string)); - id = m_strings.size() - 1; - } - return id; - } - std::string const& idToString(size_t _id) const - { - return *m_strings.at(_id); + return { 0, emptyHash() }; + std::uint64_t h = hash(_string); + auto range = m_hashToID.equal_range(h); + for (auto it = range.first; it != range.second; ++it) + if (*m_strings[it->second] == _string) + return Handle{it->second, h}; + m_strings.emplace_back(std::make_shared<std::string>(_string)); + size_t id = m_strings.size() - 1; + m_hashToID.emplace_hint(range.second, std::make_pair(h, id)); + return Handle{id, h}; } + std::string const& idToString(size_t _id) const { return *m_strings.at(_id); } - void reset() + static std::uint64_t hash(std::string const& v) { - m_strings.clear(); - m_ids.clear(); - m_strings.emplace_back(std::make_shared<std::string>()); - m_ids[std::string{}] = 0; - } + // FNV hash - can be replaced by a better one, e.g. xxhash64 + std::uint64_t hash = emptyHash(); + for (auto c: v) + { + hash *= 1099511628211u; + hash ^= c; + } + return hash; + } + static constexpr std::uint64_t emptyHash() { return 14695981039346656037u; } private: std::vector<std::shared_ptr<std::string>> m_strings; - std::map<std::string, size_t> m_ids; + std::unordered_multimap<std::uint64_t, size_t> m_hashToID; }; +/// Wrapper around handles into the YulString repository. +/// Equality of two YulStrings is determined by comparing their ID. +/// The <-operator depends on the string hash and is not consistent +/// with string comparisons (however, it is still deterministic). class YulString { public: YulString() = default; - explicit YulString(std::string const& _s): m_id(YulStringRepository::instance().stringToId(_s)) {} + explicit YulString(std::string const& _s): m_handle(YulStringRepository::instance().stringToHandle(_s)) {} YulString(YulString const&) = default; YulString(YulString&&) = default; YulString& operator=(YulString const&) = default; YulString& operator=(YulString&&) = default; /// This is not consistent with the string <-operator! - bool operator<(YulString const& _other) const { return m_id < _other.m_id; } - bool operator==(YulString const& _other) const { return m_id == _other.m_id; } - bool operator!=(YulString const& _other) const { return m_id != _other.m_id; } + /// First compares the string hashes. If they are equal + /// it checks for identical IDs (only identical strings have + /// identical IDs and identical strings do not compare as "less"). + /// If the hashes are identical and the strings are distinct, it + /// falls back to string comparison. + bool operator<(YulString const& _other) const + { + if (m_handle.hash < _other.m_handle.hash) return true; + if (_other.m_handle.hash < m_handle.hash) return false; + if (m_handle.id == _other.m_handle.id) return false; + return str() < _other.str(); + } + /// Equality is determined based on the string ID. + bool operator==(YulString const& _other) const { return m_handle.id == _other.m_handle.id; } + bool operator!=(YulString const& _other) const { return m_handle.id != _other.m_handle.id; } - bool empty() const { return m_id == 0; } + bool empty() const { return m_handle.id == 0; } std::string const& str() const { - return YulStringRepository::instance().idToString(m_id); + return YulStringRepository::instance().idToString(m_handle.id); } private: - /// ID of the string. Assumes that the empty string has ID zero. - size_t m_id = 0; + /// Handle of the string. Assumes that the empty string has ID zero. + YulStringRepository::Handle m_handle{ 0, YulStringRepository::emptyHash() }; }; } diff --git a/libyul/optimiser/RedundantAssignEliminator.cpp b/libyul/optimiser/RedundantAssignEliminator.cpp index 775b7673..b7217074 100644 --- a/libyul/optimiser/RedundantAssignEliminator.cpp +++ b/libyul/optimiser/RedundantAssignEliminator.cpp @@ -96,9 +96,15 @@ void RedundantAssignEliminator::operator()(FunctionDefinition const& _functionDe (*this)(_functionDefinition.body); for (auto const& param: _functionDefinition.parameters) + { changeUndecidedTo(param.name, State::Unused); + finalize(param.name); + } for (auto const& retParam: _functionDefinition.returnVariables) + { changeUndecidedTo(retParam.name, State::Used); + finalize(retParam.name); + } } void RedundantAssignEliminator::operator()(ForLoop const& _forLoop) @@ -150,30 +156,48 @@ void RedundantAssignEliminator::run(Block& _ast) RedundantAssignEliminator rae; rae(_ast); - std::set<Assignment const*> assignmentsToRemove; - for (auto const& variables: rae.m_assignments) - for (auto const& assignment: variables.second) - { - assertThrow(assignment.second != State::Undecided, OptimizerException, ""); - if (assignment.second == State::Unused && MovableChecker{*assignment.first->value}.movable()) - assignmentsToRemove.emplace(assignment.first); - } - - AssignmentRemover remover{assignmentsToRemove}; + AssignmentRemover remover{rae.m_assignmentsToRemove}; remover(_ast); } -void RedundantAssignEliminator::join(RedundantAssignEliminator& _other) +template <class K, class V, class F> +void joinMap(std::map<K, V>& _a, std::map<K, V>&& _b, F _conflictSolver) { - for (auto& var: _other.m_assignments) - if (m_assignments.count(var.first)) + // TODO Perhaps it is better to just create a sorted list + // and then use insert(begin, end) + + auto ita = _a.begin(); + auto aend = _a.end(); + auto itb = _b.begin(); + auto bend = _b.end(); + + for (; itb != bend; ++ita) + { + if (ita == aend) + ita = _a.insert(ita, std::move(*itb++)); + else if (ita->first < itb->first) + continue; + else if (itb->first < ita->first) + ita = _a.insert(ita, std::move(*itb++)); + else { - map<Assignment const*, State>& assignmentsHere = m_assignments[var.first]; - for (auto& assignment: var.second) - assignmentsHere[assignment.first].join(assignment.second); + _conflictSolver(ita->second, std::move(itb->second)); + ++itb; } - else - m_assignments[var.first] = std::move(var.second); + } +} + +void RedundantAssignEliminator::join(RedundantAssignEliminator& _other) +{ + m_assignmentsToRemove.insert(begin(_other.m_assignmentsToRemove), end(_other.m_assignmentsToRemove)); + + joinMap(m_assignments, std::move(_other.m_assignments), []( + map<Assignment const*, State>& _assignmentHere, + map<Assignment const*, State>&& _assignmentThere + ) + { + return joinMap(_assignmentHere, std::move(_assignmentThere), State::join); + }); } void RedundantAssignEliminator::changeUndecidedTo(YulString _variable, RedundantAssignEliminator::State _newState) @@ -183,6 +207,19 @@ void RedundantAssignEliminator::changeUndecidedTo(YulString _variable, Redundant assignment.second = _newState; } +void RedundantAssignEliminator::finalize(YulString _variable) +{ + for (auto& assignment: m_assignments[_variable]) + { + assertThrow(assignment.second != State::Undecided, OptimizerException, ""); + if (assignment.second == State{State::Unused} && MovableChecker{*assignment.first->value}.movable()) + // TODO the only point where we actually need this + // to be a set is for the for loop + m_assignmentsToRemove.insert(assignment.first); + } + m_assignments.erase(_variable); +} + void AssignmentRemover::operator()(Block& _block) { boost::range::remove_erase_if(_block.statements, [=](Statement const& _statement) -> bool { diff --git a/libyul/optimiser/RedundantAssignEliminator.h b/libyul/optimiser/RedundantAssignEliminator.h index 805a1f63..76106aae 100644 --- a/libyul/optimiser/RedundantAssignEliminator.h +++ b/libyul/optimiser/RedundantAssignEliminator.h @@ -127,10 +127,10 @@ private: State(Value _value = Undecided): m_value(_value) {} inline bool operator==(State _other) const { return m_value == _other.m_value; } inline bool operator!=(State _other) const { return !operator==(_other); } - inline void join(State const& _other) + static inline void join(State& _a, State const& _b) { // Using "max" works here because of the order of the values in the enum. - m_value = Value(std::max(int(_other.m_value), int(m_value))); + _a.m_value = Value(std::max(int(_a.m_value), int(_b.m_value))); } private: Value m_value = Undecided; @@ -149,8 +149,12 @@ private: } ~BlockScope() { + // This should actually store all declared variables + // into a different mapping for (auto const& var: m_rae.m_declaredVariables) m_rae.changeUndecidedTo(var, State::Unused); + for (auto const& var: m_rae.m_declaredVariables) + m_rae.finalize(var); swap(m_rae.m_declaredVariables, m_outerDeclaredVariables); } @@ -164,10 +168,13 @@ private: /// Will destroy @a _other. void join(RedundantAssignEliminator& _other); void changeUndecidedTo(YulString _variable, State _newState); + void finalize(YulString _variable); std::set<YulString> m_declaredVariables; // TODO check that this does not cause nondeterminism! + // This could also be a pseudo-map from state to assignment. std::map<YulString, std::map<Assignment const*, State>> m_assignments; + std::set<Assignment const*> m_assignmentsToRemove; }; class AssignmentRemover: public ASTModifier diff --git a/scripts/check_style.sh b/scripts/check_style.sh index a8557a54..4f716d66 100755 --- a/scripts/check_style.sh +++ b/scripts/check_style.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash -REPO_ROOT="$(dirname "$0")"/.. - ( +REPO_ROOT="$(dirname "$0")"/.. cd $REPO_ROOT + WHITESPACE=$(git grep -n -I -E "^.*[[:space:]]+$" | grep -v "test/libsolidity/ASTJSON\|test/compilationTests/zeppelin/LICENSE") if [[ "$WHITESPACE" != "" ]] @@ -12,10 +12,7 @@ then echo "$WHITESPACE" >&2 exit 1 fi -) -( -cd $REPO_ROOT FORMATERROR=$( ( git grep -nIE "\<(if|for)\(" -- '*.h' '*.cpp' diff --git a/test/libyul/Inliner.cpp b/test/libyul/Inliner.cpp index 4ed52b47..66810298 100644 --- a/test/libyul/Inliner.cpp +++ b/test/libyul/Inliner.cpp @@ -71,7 +71,7 @@ BOOST_AUTO_TEST_CASE(simple) BOOST_CHECK_EQUAL(inlinableFunctions("{" "function g(a:u256) -> b:u256 { b := a }" "function f() -> x:u256 { x := g(2:u256) }" - "}"), "f,g"); + "}"), "g,f"); } BOOST_AUTO_TEST_CASE(simple_inside_structures) @@ -82,7 +82,7 @@ BOOST_AUTO_TEST_CASE(simple_inside_structures) "function g(a:u256) -> b:u256 { b := a }" "function f() -> x:u256 { x := g(2:u256) }" "}" - "}"), "f,g"); + "}"), "g,f"); BOOST_CHECK_EQUAL(inlinableFunctions("{" "for {" "function g(a:u256) -> b:u256 { b := a }" @@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE(simple_inside_structures) "{" "function h() -> y:u256 { y := 2:u256 }" "}" - "}"), "f,g,h"); + "}"), "h,g,f"); } BOOST_AUTO_TEST_CASE(negative) diff --git a/test/libyul/YulOptimizerTest.cpp b/test/libyul/YulOptimizerTest.cpp index 162b167c..03cd6446 100644 --- a/test/libyul/YulOptimizerTest.cpp +++ b/test/libyul/YulOptimizerTest.cpp @@ -90,8 +90,6 @@ YulOptimizerTest::YulOptimizerTest(string const& _filename) bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted) { - yul::YulStringRepository::instance().reset(); - assembly::AsmPrinter printer{m_yul}; shared_ptr<Block> ast; shared_ptr<assembly::AsmAnalysisInfo> analysisInfo; diff --git a/test/libyul/yulOptimizerTests/fullInliner/multi_fun_callback.yul b/test/libyul/yulOptimizerTests/fullInliner/multi_fun_callback.yul index d09877de..19ac945e 100644 --- a/test/libyul/yulOptimizerTests/fullInliner/multi_fun_callback.yul +++ b/test/libyul/yulOptimizerTests/fullInliner/multi_fun_callback.yul @@ -41,18 +41,19 @@ // h_t := 2 // mstore(7, h_t) // let g_x_1 := 10 -// f(1) +// let g_f_x_8 := 1 +// mstore(0, g_f_x_8) +// mstore(7, h()) +// g(10) +// mstore(1, g_f_x_8) // mstore(1, x) // } // function g(x_1) // { // let f_x_8 := 1 // mstore(0, f_x_8) -// let f_h_t -// f_h_t := 2 -// mstore(7, f_h_t) -// let f_g_x_1 := 10 -// f(1) +// mstore(7, h()) +// g(10) // mstore(1, f_x_8) // } // function h() -> t diff --git a/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul b/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul new file mode 100644 index 00000000..cc6044d3 --- /dev/null +++ b/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul @@ -0,0 +1,654 @@ +{ + let x := abi_encode_t_array$_t_array$_t_contract$_C_$55_$3_memory_$dyn_memory_ptr_to_t_array$_t_array$_t_address_$3_memory_$dyn_memory_ptr(mload(0), 0x20) + let a, b, c, d := abi_decode_tuple_t_uint256t_uint256t_array$_t_uint256_$dyn_memory_ptrt_array$_t_array$_t_uint256_$2_memory_$dyn_memory_ptr(mload(0x20), mload(0x40)) + sstore(a, b) + sstore(c, d) + sstore(0, x) + + function abi_decode_t_address(offset, end) -> value + { + value := cleanup_revert_t_address(calldataload(offset)) + } + function abi_decode_t_array$_t_address_$dyn_memory(offset, end) -> array + { + if iszero(slt(add(offset, 0x1f), end)) + { + revert(0, 0) + } + let length := calldataload(offset) + array := allocateMemory(array_allocation_size_t_array$_t_address_$dyn_memory(length)) + let dst := array + mstore(array, length) + offset := add(offset, 0x20) + dst := add(dst, 0x20) + let src := offset + if gt(add(src, mul(length, 0x20)), end) + { + revert(0, 0) + } + for { + let i := 0 + } + lt(i, length) + { + i := add(i, 1) + } + { + let elementPos := src + mstore(dst, abi_decode_t_address(elementPos, end)) + dst := add(dst, 0x20) + src := add(src, 0x20) + } + } + function abi_decode_t_array$_t_array$_t_uint256_$2_memory_$dyn_memory_ptr(offset, end) -> array + { + if iszero(slt(add(offset, 0x1f), end)) + { + revert(0, 0) + } + let length := calldataload(offset) + array := allocateMemory(array_allocation_size_t_array$_t_array$_t_uint256_$2_memory_$dyn_memory_ptr(length)) + let dst := array + mstore(array, length) + offset := add(offset, 0x20) + dst := add(dst, 0x20) + let src := offset + if gt(add(src, mul(length, 0x40)), end) + { + revert(0, 0) + } + for { + let i := 0 + } + lt(i, length) + { + i := add(i, 1) + } + { + let elementPos := src + mstore(dst, abi_decode_t_array$_t_uint256_$2_memory(elementPos, end)) + dst := add(dst, 0x20) + src := add(src, 0x40) + } + } + function abi_decode_t_array$_t_uint256_$2_memory(offset, end) -> array + { + if iszero(slt(add(offset, 0x1f), end)) + { + revert(0, 0) + } + let length := 0x2 + array := allocateMemory(array_allocation_size_t_array$_t_uint256_$2_memory(length)) + let dst := array + let src := offset + if gt(add(src, mul(length, 0x20)), end) + { + revert(0, 0) + } + for { + let i := 0 + } + lt(i, length) + { + i := add(i, 1) + } + { + let elementPos := src + mstore(dst, abi_decode_t_uint256(elementPos, end)) + dst := add(dst, 0x20) + src := add(src, 0x20) + } + } + function abi_decode_t_array$_t_uint256_$dyn_memory(offset, end) -> array + { + if iszero(slt(add(offset, 0x1f), end)) + { + revert(0, 0) + } + let length := calldataload(offset) + array := allocateMemory(array_allocation_size_t_array$_t_uint256_$dyn_memory(length)) + let dst := array + mstore(array, length) + offset := add(offset, 0x20) + dst := add(dst, 0x20) + let src := offset + if gt(add(src, mul(length, 0x20)), end) + { + revert(0, 0) + } + for { + let i := 0 + } + lt(i, length) + { + i := add(i, 1) + } + { + let elementPos := src + mstore(dst, abi_decode_t_uint256(elementPos, end)) + dst := add(dst, 0x20) + src := add(src, 0x20) + } + } + function abi_decode_t_array$_t_uint256_$dyn_memory_ptr(offset, end) -> array + { + if iszero(slt(add(offset, 0x1f), end)) + { + revert(0, 0) + } + let length := calldataload(offset) + array := allocateMemory(array_allocation_size_t_array$_t_uint256_$dyn_memory_ptr(length)) + let dst := array + mstore(array, length) + offset := add(offset, 0x20) + dst := add(dst, 0x20) + let src := offset + if gt(add(src, mul(length, 0x20)), end) + { + revert(0, 0) + } + for { + let i := 0 + } + lt(i, length) + { + i := add(i, 1) + } + { + let elementPos := src + mstore(dst, abi_decode_t_uint256(elementPos, end)) + dst := add(dst, 0x20) + src := add(src, 0x20) + } + } + function abi_decode_t_contract$_C_$55(offset, end) -> value + { + value := cleanup_revert_t_contract$_C_$55(calldataload(offset)) + } + function abi_decode_t_struct$_S_$11_memory_ptr(headStart, end) -> value + { + if slt(sub(end, headStart), 0x60) + { + revert(0, 0) + } + value := allocateMemory(0x60) + { + let offset := 0 + mstore(add(value, 0x0), abi_decode_t_uint256(add(headStart, offset), end)) + } + { + let offset := calldataload(add(headStart, 32)) + if gt(offset, 0xffffffffffffffff) + { + revert(0, 0) + } + mstore(add(value, 0x20), abi_decode_t_array$_t_uint256_$dyn_memory(add(headStart, offset), end)) + } + { + let offset := calldataload(add(headStart, 64)) + if gt(offset, 0xffffffffffffffff) + { + revert(0, 0) + } + mstore(add(value, 0x40), abi_decode_t_array$_t_address_$dyn_memory(add(headStart, offset), end)) + } + } + function abi_decode_t_uint256(offset, end) -> value + { + value := cleanup_revert_t_uint256(calldataload(offset)) + } + function abi_decode_t_uint8(offset, end) -> value + { + value := cleanup_revert_t_uint8(calldataload(offset)) + } + function abi_decode_tuple_t_contract$_C_$55t_uint8(headStart, dataEnd) -> value0, value1 + { + if slt(sub(dataEnd, headStart), 64) + { + revert(0, 0) + } + { + let offset := 0 + value0 := abi_decode_t_contract$_C_$55(add(headStart, offset), dataEnd) + } + { + let offset := 32 + value1 := abi_decode_t_uint8(add(headStart, offset), dataEnd) + } + } + function abi_decode_tuple_t_struct$_S_$11_memory_ptrt_uint256(headStart, dataEnd) -> value0, value1 + { + if slt(sub(dataEnd, headStart), 64) + { + revert(0, 0) + } + { + let offset := calldataload(add(headStart, 0)) + if gt(offset, 0xffffffffffffffff) + { + revert(0, 0) + } + value0 := abi_decode_t_struct$_S_$11_memory_ptr(add(headStart, offset), dataEnd) + } + { + let offset := 32 + value1 := abi_decode_t_uint256(add(headStart, offset), dataEnd) + } + } + function abi_decode_tuple_t_uint256t_uint256t_array$_t_uint256_$dyn_memory_ptrt_array$_t_array$_t_uint256_$2_memory_$dyn_memory_ptr(headStart, dataEnd) -> value0, value1, value2, value3 + { + if slt(sub(dataEnd, headStart), 128) + { + revert(0, 0) + } + { + let offset := 0 + value0 := abi_decode_t_uint256(add(headStart, offset), dataEnd) + } + { + let offset := 32 + value1 := abi_decode_t_uint256(add(headStart, offset), dataEnd) + } + { + let offset := calldataload(add(headStart, 64)) + if gt(offset, 0xffffffffffffffff) + { + revert(0, 0) + } + value2 := abi_decode_t_array$_t_uint256_$dyn_memory_ptr(add(headStart, offset), dataEnd) + } + { + let offset := calldataload(add(headStart, 96)) + if gt(offset, 0xffffffffffffffff) + { + revert(0, 0) + } + value3 := abi_decode_t_array$_t_array$_t_uint256_$2_memory_$dyn_memory_ptr(add(headStart, offset), dataEnd) + } + } + function abi_encode_t_array$_t_array$_t_contract$_C_$55_$3_memory_$dyn_memory_ptr_to_t_array$_t_array$_t_address_$3_memory_$dyn_memory_ptr(value, pos) -> end + { + let length := array_length_t_array$_t_array$_t_contract$_C_$55_$3_memory_$dyn_memory_ptr(value) + mstore(pos, length) + pos := add(pos, 0x20) + let srcPtr := array_dataslot_t_array$_t_array$_t_contract$_C_$55_$3_memory_$dyn_memory_ptr(value) + for { + let i := 0 + } + lt(i, length) + { + i := add(i, 1) + } + { + abi_encode_t_array$_t_contract$_C_$55_$3_memory_to_t_array$_t_address_$3_memory_ptr(mload(srcPtr), pos) + srcPtr := array_nextElement_t_array$_t_array$_t_contract$_C_$55_$3_memory_$dyn_memory_ptr(srcPtr) + pos := add(pos, 0x60) + } + end := pos + } + function abi_encode_t_array$_t_contract$_C_$55_$3_memory_to_t_array$_t_address_$3_memory_ptr(value, pos) + { + let length := array_length_t_array$_t_contract$_C_$55_$3_memory(value) + let srcPtr := array_dataslot_t_array$_t_contract$_C_$55_$3_memory(value) + for { + let i := 0 + } + lt(i, length) + { + i := add(i, 1) + } + { + abi_encode_t_contract$_C_$55_to_t_address(mload(srcPtr), pos) + srcPtr := array_nextElement_t_array$_t_contract$_C_$55_$3_memory(srcPtr) + pos := add(pos, 0x20) + } + } + function abi_encode_t_bool_to_t_bool(value, pos) + { + mstore(pos, cleanup_assert_t_bool(value)) + } + function abi_encode_t_contract$_C_$55_to_t_address(value, pos) + { + mstore(pos, convert_t_contract$_C_$55_to_t_address(value)) + } + function abi_encode_t_uint16_to_t_uint16(value, pos) + { + mstore(pos, cleanup_assert_t_uint16(value)) + } + function abi_encode_t_uint24_to_t_uint24(value, pos) + { + mstore(pos, cleanup_assert_t_uint24(value)) + } + function abi_encode_tuple_t_bool__to_t_bool_(headStart, value0) -> tail + { + tail := add(headStart, 32) + abi_encode_t_bool_to_t_bool(value0, add(headStart, 0)) + } + function abi_encode_tuple_t_uint16_t_uint24_t_array$_t_array$_t_contract$_C_$55_$3_memory_$dyn_memory_ptr__to_t_uint16_t_uint24_t_array$_t_array$_t_address_$3_memory_$dyn_memory_ptr_(headStart, value2, value1, value0) -> tail + { + tail := add(headStart, 96) + abi_encode_t_uint16_to_t_uint16(value0, add(headStart, 0)) + abi_encode_t_uint24_to_t_uint24(value1, add(headStart, 32)) + mstore(add(headStart, 64), sub(tail, headStart)) + tail := abi_encode_t_array$_t_array$_t_contract$_C_$55_$3_memory_$dyn_memory_ptr_to_t_array$_t_array$_t_address_$3_memory_$dyn_memory_ptr(value2, tail) + } + function allocateMemory(size) -> memPtr + { + memPtr := mload(64) + let newFreePtr := add(memPtr, size) + if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) + { + revert(0, 0) + } + mstore(64, newFreePtr) + } + function array_allocation_size_t_array$_t_address_$dyn_memory(length) -> size + { + if gt(length, 0xffffffffffffffff) + { + revert(0, 0) + } + size := mul(length, 0x20) + size := add(size, 0x20) + } + function array_allocation_size_t_array$_t_array$_t_uint256_$2_memory_$dyn_memory_ptr(length) -> size + { + if gt(length, 0xffffffffffffffff) + { + revert(0, 0) + } + size := mul(length, 0x20) + size := add(size, 0x20) + } + function array_allocation_size_t_array$_t_uint256_$2_memory(length) -> size + { + if gt(length, 0xffffffffffffffff) + { + revert(0, 0) + } + size := mul(length, 0x20) + } + function array_allocation_size_t_array$_t_uint256_$dyn_memory(length) -> size + { + if gt(length, 0xffffffffffffffff) + { + revert(0, 0) + } + size := mul(length, 0x20) + size := add(size, 0x20) + } + function array_allocation_size_t_array$_t_uint256_$dyn_memory_ptr(length) -> size + { + if gt(length, 0xffffffffffffffff) + { + revert(0, 0) + } + size := mul(length, 0x20) + size := add(size, 0x20) + } + function array_dataslot_t_array$_t_array$_t_contract$_C_$55_$3_memory_$dyn_memory_ptr(memPtr) -> dataPtr + { + dataPtr := add(memPtr, 0x20) + } + function array_dataslot_t_array$_t_contract$_C_$55_$3_memory(memPtr) -> dataPtr + { + dataPtr := memPtr + } + function array_length_t_array$_t_array$_t_contract$_C_$55_$3_memory_$dyn_memory_ptr(value) -> length + { + length := mload(value) + } + function array_length_t_array$_t_contract$_C_$55_$3_memory(value) -> length + { + length := 0x3 + } + function array_nextElement_t_array$_t_array$_t_contract$_C_$55_$3_memory_$dyn_memory_ptr(memPtr) -> nextPtr + { + nextPtr := add(memPtr, 0x20) + } + function array_nextElement_t_array$_t_contract$_C_$55_$3_memory(memPtr) -> nextPtr + { + nextPtr := add(memPtr, 0x20) + } + function cleanup_assert_t_address(value) -> cleaned + { + cleaned := cleanup_assert_t_uint160(value) + } + function cleanup_assert_t_bool(value) -> cleaned + { + cleaned := iszero(iszero(value)) + } + function cleanup_assert_t_uint16(value) -> cleaned + { + cleaned := and(value, 0xFFFF) + } + function cleanup_assert_t_uint160(value) -> cleaned + { + cleaned := and(value, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) + } + function cleanup_assert_t_uint24(value) -> cleaned + { + cleaned := and(value, 0xFFFFFF) + } + function cleanup_revert_t_address(value) -> cleaned + { + cleaned := cleanup_assert_t_uint160(value) + } + function cleanup_revert_t_contract$_C_$55(value) -> cleaned + { + cleaned := cleanup_assert_t_address(value) + } + function cleanup_revert_t_uint256(value) -> cleaned + { + cleaned := value + } + function cleanup_revert_t_uint8(value) -> cleaned + { + cleaned := and(value, 0xFF) + } + function convert_t_contract$_C_$55_to_t_address(value) -> converted + { + converted := convert_t_contract$_C_$55_to_t_uint160(value) + } + function convert_t_contract$_C_$55_to_t_uint160(value) -> converted + { + converted := cleanup_assert_t_uint160(value) + } +} +// ---- +// fullSuite +// { +// { +// let _1 := 0x20 +// let _2 := 0 +// let _485 := mload(_2) +// let abi_encode_pos := _1 +// let abi_encode_length_68 := mload(_485) +// mstore(_1, abi_encode_length_68) +// let abi_encode_pos_590 := 64 +// abi_encode_pos := abi_encode_pos_590 +// let abi_encode_srcPtr := add(_485, _1) +// for { +// let abi_encode_i_69 := _2 +// } +// lt(abi_encode_i_69, abi_encode_length_68) +// { +// abi_encode_i_69 := add(abi_encode_i_69, 1) +// } +// { +// let _922 := mload(abi_encode_srcPtr) +// let abi_encode_pos_71_1029 := abi_encode_pos +// let abi_encode_length_72_1030 := 0x3 +// let abi_encode_srcPtr_73_1031 := _922 +// for { +// let abi_encode_i_74_1032 := _2 +// } +// lt(abi_encode_i_74_1032, abi_encode_length_72_1030) +// { +// abi_encode_i_74_1032 := add(abi_encode_i_74_1032, 1) +// } +// { +// mstore(abi_encode_pos_71_1029, and(mload(abi_encode_srcPtr_73_1031), 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) +// abi_encode_srcPtr_73_1031 := add(abi_encode_srcPtr_73_1031, _1) +// abi_encode_pos_71_1029 := add(abi_encode_pos_71_1029, _1) +// } +// abi_encode_srcPtr := add(abi_encode_srcPtr, _1) +// abi_encode_pos := add(abi_encode_pos, 0x60) +// } +// let _924 := 0x40 +// let _487 := mload(_924) +// let _488 := mload(_1) +// let abi_decode_value0_60_618 +// let abi_decode_value0_60 := abi_decode_value0_60_618 +// let abi_decode_value1_61_619 +// let abi_decode_value1_61 := abi_decode_value1_61_619 +// let abi_decode_value2_620 +// let abi_decode_value2 := abi_decode_value2_620 +// let abi_decode_value3_621 +// let abi_decode_value3 := abi_decode_value3_621 +// if slt(sub(_487, _488), 128) +// { +// revert(_2, _2) +// } +// { +// abi_decode_value0_60 := calldataload(_488) +// } +// { +// abi_decode_value1_61 := calldataload(add(_488, 32)) +// } +// { +// let abi_decode_offset_64 := calldataload(add(_488, abi_encode_pos_590)) +// let _931 := 0xffffffffffffffff +// if gt(abi_decode_offset_64, _931) +// { +// revert(_2, _2) +// } +// let _933 := add(_488, abi_decode_offset_64) +// if iszero(slt(add(_933, 0x1f), _487)) +// { +// revert(_2, _2) +// } +// let abi_decode_length_30_1038 := calldataload(_933) +// if gt(abi_decode_length_30_1038, _931) +// { +// revert(_2, _2) +// } +// let abi_decode_array_allo__561 := mul(abi_decode_length_30_1038, _1) +// let abi_decode_array_29_279_1039 := allocateMemory(add(abi_decode_array_allo__561, _1)) +// let abi_decode_dst_31_1040 := abi_decode_array_29_279_1039 +// mstore(abi_decode_array_29_279_1039, abi_decode_length_30_1038) +// let abi_decode_offset_27_281_1041 := add(_933, _1) +// abi_decode_dst_31_1040 := add(abi_decode_array_29_279_1039, _1) +// let abi_decode_src_32_1042 := abi_decode_offset_27_281_1041 +// if gt(add(add(_933, abi_decode_array_allo__561), _1), _487) +// { +// revert(_2, _2) +// } +// for { +// let abi_decode_i_33_1044 := _2 +// } +// lt(abi_decode_i_33_1044, abi_decode_length_30_1038) +// { +// abi_decode_i_33_1044 := add(abi_decode_i_33_1044, 1) +// } +// { +// mstore(abi_decode_dst_31_1040, calldataload(abi_decode_src_32_1042)) +// abi_decode_dst_31_1040 := add(abi_decode_dst_31_1040, _1) +// abi_decode_src_32_1042 := add(abi_decode_src_32_1042, _1) +// } +// abi_decode_value2 := abi_decode_array_29_279_1039 +// } +// { +// let abi_decode_offset_65 := calldataload(add(_488, 96)) +// let _936 := 0xffffffffffffffff +// if gt(abi_decode_offset_65, _936) +// { +// revert(_2, _2) +// } +// let _938 := add(_488, abi_decode_offset_65) +// let abi_decode__489_1048 := 0x1f +// if iszero(slt(add(_938, abi_decode__489_1048), _487)) +// { +// revert(_2, _2) +// } +// let abi_decode_length_6_1050 := calldataload(_938) +// if gt(abi_decode_length_6_1050, _936) +// { +// revert(_2, _2) +// } +// let abi_decode_array_5_254_1051 := allocateMemory(add(mul(abi_decode_length_6_1050, _1), _1)) +// let abi_decode_dst_7_1052 := abi_decode_array_5_254_1051 +// mstore(abi_decode_array_5_254_1051, abi_decode_length_6_1050) +// let abi_decode_offset_3_256_1053 := add(_938, _1) +// abi_decode_dst_7_1052 := add(abi_decode_array_5_254_1051, _1) +// let abi_decode_src_8_1054 := abi_decode_offset_3_256_1053 +// if gt(add(add(_938, mul(abi_decode_length_6_1050, _924)), _1), _487) +// { +// revert(_2, _2) +// } +// for { +// let abi_decode_i_9_1058 := _2 +// } +// lt(abi_decode_i_9_1058, abi_decode_length_6_1050) +// { +// abi_decode_i_9_1058 := add(abi_decode_i_9_1058, 1) +// } +// { +// if iszero(slt(add(abi_decode_src_8_1054, abi_decode__489_1048), _487)) +// { +// revert(_2, _2) +// } +// let abi_decode_abi_decode_length_14 := 0x2 +// if _2 +// { +// revert(_2, _2) +// } +// let allocateMe_memPtr_315 := mload(abi_encode_pos_590) +// let allocateMe_newFreePtr := add(allocateMe_memPtr_315, abi_encode_pos_590) +// if or(gt(allocateMe_newFreePtr, _936), lt(allocateMe_newFreePtr, allocateMe_memPtr_315)) +// { +// revert(_2, _2) +// } +// mstore(abi_encode_pos_590, allocateMe_newFreePtr) +// let abi_decode_abi_decode_dst_15 := allocateMe_memPtr_315 +// let abi_decode_abi_decode_src_16 := abi_decode_src_8_1054 +// if gt(add(abi_decode_src_8_1054, abi_encode_pos_590), _487) +// { +// revert(_2, _2) +// } +// for { +// let abi_decode_abi_decode_i_17 := _2 +// } +// lt(abi_decode_abi_decode_i_17, abi_decode_abi_decode_length_14) +// { +// abi_decode_abi_decode_i_17 := add(abi_decode_abi_decode_i_17, 1) +// } +// { +// mstore(abi_decode_abi_decode_dst_15, calldataload(abi_decode_abi_decode_src_16)) +// abi_decode_abi_decode_dst_15 := add(abi_decode_abi_decode_dst_15, _1) +// abi_decode_abi_decode_src_16 := add(abi_decode_abi_decode_src_16, _1) +// } +// mstore(abi_decode_dst_7_1052, allocateMe_memPtr_315) +// abi_decode_dst_7_1052 := add(abi_decode_dst_7_1052, _1) +// abi_decode_src_8_1054 := add(abi_decode_src_8_1054, _924) +// } +// abi_decode_value3 := abi_decode_array_5_254_1051 +// } +// sstore(abi_decode_value0_60, abi_decode_value1_61) +// sstore(abi_decode_value2, abi_decode_value3) +// sstore(_2, abi_encode_pos) +// } +// function allocateMemory(size) -> memPtr +// { +// let _199 := 64 +// let memPtr_315 := mload(_199) +// memPtr := memPtr_315 +// let newFreePtr := add(memPtr_315, size) +// if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr_315)) +// { +// let _204 := 0 +// revert(_204, _204) +// } +// mstore(_199, newFreePtr) +// } +// } |