Skip to content

Commit 22c7cd2

Browse files
Marenzcameel
authored andcommitted
Fix wrong cleanup when copying from calldata to memory
Co-authored-by: Kamil Śliwak <[email protected]>
1 parent 5b0f4a7 commit 22c7cd2

File tree

48 files changed

+393
-208
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+393
-208
lines changed

Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
### 0.8.16 (unreleased)
22

3+
Important Bugfixes:
4+
* Code Generation: Fix data corruption that affected ABI-encoding of calldata values represented by tuples: structs at any nesting level; argument lists of external functions, events and errors; return value lists of external functions. The 32 leading bytes of the first dynamically-encoded value in the tuple would get zeroed when the last component contained a statically-encoded array.
5+
36
Language Features:
47

58

@@ -10,6 +13,7 @@ Compiler Features:
1013
* Yul Optimizer: Add rule to convert `mod(add(X, Y), A)` into `addmod(X, Y, A)`, if `A` is a power of two.
1114
* Code Generator: More efficient code for checked addition and subtraction.
1215

16+
1317
Bugfixes:
1418
* Commandline Interface: Disallow the following options outside of the compiler mode: ``--via-ir``,``--metadata-literal``, ``--metadata-hash``, ``--model-checker-show-unproved``, ``--model-checker-div-mod-no-slacks``, ``--model-checker-engine``, ``--model-checker-invariants``, ``--model-checker-solvers``, ``--model-checker-timeout``, ``--model-checker-contracts``, ``--model-checker-targets``.
1519
* Type Checker: Fix null dereference in `abi.encodeCall` type checking of free function.

docs/bugs.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
[
2+
{
3+
"uid": "SOL-2022-6",
4+
"name": "AbiReencodingHeadOverflowWithStaticArrayCleanup",
5+
"summary": "ABI-encoding a tuple with a statically-sized calldata array in the last component would corrupt 32 leading bytes of its first dynamically encoded component.",
6+
"description": "When ABI-encoding a statically-sized calldata array, the compiler always pads the data area to a multiple of 32-bytes and ensures that the padding bytes are zeroed. In some cases, this cleanup used to be performed by always writing exactly 32 bytes, regardless of how many needed to be zeroed. This was done with the assumption that the data that would eventually occupy the area past the end of the array had not yet been written, because the encoder processes tuple components in the order they were given. While this assumption is mostly true, there is an important corner case: dynamically encoded tuple components are stored separately from the statically-sized ones in an area called the *tail* of the encoding and the tail immediately follows the *head*, which is where the statically-sized components are placed. The aforementioned cleanup, if performed for the last component of the head would cross into the tail and overwrite up to 32 bytes of the first component stored there with zeros. The only array type for which the cleanup could actually result in an overwrite were arrays with ``uint256`` or ``bytes32`` as the base element type and in this case the size of the corrupted area was always exactly 32 bytes. The problem affected tuples at any nesting level. This included also structs, which are encoded as tuples in the ABI. Note also that lists of parameters and return values of functions, events and errors are encoded as tuples.",
7+
"introduced": "0.5.8",
8+
"fixed": "0.8.16",
9+
"severity": "medium",
10+
"conditions": {
11+
"ABIEncoderV2": true
12+
}
13+
},
214
{
315
"uid": "SOL-2022-5",
416
"name": "DirtyBytesArrayToStorage",

0 commit comments

Comments
 (0)