libsolidity/codegen: Use calldatacopy to cheaply zero memory instead of

codecopy.

Motiviation:
  Zero'ing memory is commonplace in contracts, but with the upcoming
  Layer-2 EVM translation layers and other on-chain verification
  mechanisms, using `codecopy` becomes a `costly` operation in those
  sandboxes. Using `calldatacopy` achieves the same thing, gas costs
  are also the same as codecopy, and is significantly cheaper in the `sandbox` situation.
This commit is contained in:
pinkiebell
2020-01-22 17:56:56 +01:00
parent 29d7c7d065
commit bb6fb675e0
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -605,7 +605,7 @@ void CompilerUtils::zeroInitialiseMemoryArray(ArrayType const& _type)
Whiskers templ(R"({
let size := mul(length, <element_size>)
// cheap way of zero-initializing a memory range
codecopy(memptr, codesize(), size)
calldatacopy(memptr, calldatasize(), size)
memptr := add(memptr, size)
})");
templ("element_size", to_string(_type.memoryStride()));