argotorg / argotorg/solidity

Nested memory arrays not implemented in ABICoder V1

Open
#15,398 0 comments 0 reactions 0 assignees View on GitHub
bug :bug:
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
2d 19h
Merged PRs (30d)
29

Description

## Description
When I use abicoderV1 to encode a two-dimensional array, it executes normally. However, when decoding, a code generation error occurs.

## Environment

- Compiler version: 0.8.26
- Target EVM version (as per compiler settings): None
- Framework/IDE (e.g. Truffle or Remix): None
- EVM execution environment / backend / blockchain client: None
- Operating system: Linux

## Steps to Reproduce
```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma abicoder v1;
contract BuggyContract {
int[5][] public a;
function initialize() public {
a.push([int(1), int(-45), int(-78), int(56), int(60)]);
a.push([int(-1), int(42), int(334), int(-45455), int(-446)]);
a.push([int(1), int(10), int(-5435), int(45), int(-7)]);

bytes memory encodedA2 = abi.encode(a);
int[5][] memory decodedA2 = abi.decode(encodedA2, (int[5][]));

}
}
```
### Compile
```
solc test.sol
```
```
Compiler run successful. No output generated.
```
### Codegen
```
solc test.sol --bin
```
```
Unimplemented feature:
/solidity/libsolidity/codegen/CompilerUtils.cpp(287): Throw in function void solidity::frontend::CompilerUtils::abiDecode(const TypePointers&, bool)
Dynamic exception type: boost::wrapexcept
std::exception::what: Nested memory arrays not yet implemented here.
[solidity::util::tag_comment*] = Nested memory arrays not yet implemented here.
```
### Analyse

I believe this is a bug for the following two reasons:

1. During the compilation phase, there is no **error** indicating that abicoderV1 does not support two-dimensional arrays. If it were a struct, solc would directly throw an error to indicate this.
2. abicoderV1 supports encoding two-dimensional arrays, but it does not support decoding them back into two-dimensional arrays.

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with the provided test.sol and `solc test.sol --bin`, then inspect `solidity/libsolidity/codegen/CompilerUtils.cpp` around `abiDecode` at line 287. Trace the abicoder v1 path for `int[5][]` and verify that code generation completes without the nested-memory-arrays error while preserving the demonstrated encode/decode case.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, solidity
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.