Browse Source

Fixes in CALLDATACOPY

[Delivers #80644732]
cl-refactor
artur-zawlocki 10 years ago
parent
commit
42b14ae334
  1. 16
      evmcc/Compiler.cpp
  2. 1
      evmcc/test/ext/calldatacopy1.evm
  3. 13
      evmcc/test/ext/calldatacopy1.lll
  4. 1
      evmcc/test/ext/calldatacopy2.evm
  5. 13
      evmcc/test/ext/calldatacopy2.lll

16
evmcc/Compiler.cpp

@ -742,24 +742,26 @@ std::unique_ptr<llvm::Module> Compiler::compile(const dev::bytes& bytecode)
auto destMemIdx = stack.pop();
auto srcDataIdx = stack.pop();
auto reqByteCount = stack.pop();
auto reqBytes = stack.pop();
// FIXME: ensure memory size reqMemSize.
auto reqMemSize = builder.CreateAdd(destMemIdx, reqByteCount);
auto reqMemWord = builder.CreateSub(reqMemSize, ConstantInt::get(Type::i256, 32));
memory.loadWord(reqMemWord);
auto reqMemSize = builder.CreateAdd(destMemIdx, reqBytes, "req_mem_size");
memory.require(reqMemSize);
auto memPtr = memory.getData();
auto destPtr = builder.CreateGEP(memPtr, destMemIdx);
auto destPtr = builder.CreateGEP(memPtr, destMemIdx, "dest_mem_ptr");
auto calldataPtr = ext.calldata();
auto srcPtr = builder.CreateGEP(calldataPtr, srcDataIdx);
auto srcPtr = builder.CreateGEP(calldataPtr, srcDataIdx, "src_idx");
auto calldataSize = ext.calldatasize();
// remaining data bytes:
auto remDataSize = builder.CreateSub(calldataSize, srcDataIdx);
auto remSizeNegative = builder.CreateICmpSLT(remDataSize, zero256);
auto bytesToCopy = builder.CreateSelect(remSizeNegative, zero256, remDataSize);
auto remDataBytes = builder.CreateSelect(remSizeNegative, zero256, remDataSize, "rem_data_bytes");
auto tooLittleDataBytes = builder.CreateICmpULT(remDataBytes, reqBytes);
auto bytesToCopy = builder.CreateSelect(tooLittleDataBytes, remDataBytes, reqBytes, "bytes_to_copy");
builder.CreateMemCpy(destPtr, srcPtr, bytesToCopy, 0);

1
evmcc/test/ext/calldatacopy1.evm

@ -0,0 +1 @@
60146000600a37600053600a6014f2

13
evmcc/test/ext/calldatacopy1.lll

@ -0,0 +1,13 @@
(asm
20 ;; byte count
0 ;; source index in calldata array
10 ;; dest index in memory
CALLDATACOPY
0
MLOAD ;; to dump memory
10
20
RETURN
)

1
evmcc/test/ext/calldatacopy2.evm

@ -0,0 +1 @@
606464e8d4a510006000376000536000600af2

13
evmcc/test/ext/calldatacopy2.lll

@ -0,0 +1,13 @@
(asm
100 ;; byte count
1000000000000 ;; source index in calldata array
0 ;; dest index in memory
CALLDATACOPY
0
MLOAD ;; to dump memory
0
10
RETURN
)
Loading…
Cancel
Save