diff options
author | chriseth <chris@ethereum.org> | 2018-05-07 22:23:39 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2018-06-13 01:51:40 +0800 |
commit | 1dc28c065d91416caf778770ef57b73b30462b8d (patch) | |
tree | 04aeb5e2eb3116f0a9b12e0b145f824cc792eade /libsolidity | |
parent | 71dc4011702c2ba047553aec1aad8dbae5dcabe7 (diff) | |
download | dexon-solidity-1dc28c065d91416caf778770ef57b73b30462b8d.tar.gz dexon-solidity-1dc28c065d91416caf778770ef57b73b30462b8d.tar.zst dexon-solidity-1dc28c065d91416caf778770ef57b73b30462b8d.zip |
Properly pad data from calldata.
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/codegen/ArrayUtils.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/libsolidity/codegen/ArrayUtils.cpp b/libsolidity/codegen/ArrayUtils.cpp index 14c887c3..2b77db8f 100644 --- a/libsolidity/codegen/ArrayUtils.cpp +++ b/libsolidity/codegen/ArrayUtils.cpp @@ -303,12 +303,17 @@ void ArrayUtils::copyArrayToMemory(ArrayType const& _sourceType, bool _padToWord m_context << _sourceType.length(); if (baseSize > 1) m_context << u256(baseSize) << Instruction::MUL; - // stack: target source_offset source_len - m_context << Instruction::DUP1 << Instruction::DUP3 << Instruction::DUP5; - // stack: target source_offset source_len source_len source_offset target - m_context << Instruction::CALLDATACOPY; - m_context << Instruction::DUP3 << Instruction::ADD; - m_context << Instruction::SWAP2 << Instruction::POP << Instruction::POP; + + string routine = "calldatacopy(target, source, len)\n"; + if (_padToWordBoundaries) + routine += R"( + // Set padding suffix to zero + mstore(add(target, len), 0) + len := and(add(len, 0x1f), not(0x1f)) + )"; + routine += "target := add(target, len)\n"; + m_context.appendInlineAssembly("{" + routine + "}", {"target", "source", "len"}); + m_context << Instruction::POP << Instruction::POP; } else if (_sourceType.location() == DataLocation::Memory) { |