argotorg / argotorg/solidity

[soltest] Incorrect semantics tests suggestions for unaligned hex strings.

Open
#6,703 2 comments 0 reactions 0 assignees View on GitHub
bug :bug: testing :hammer:
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
21

Description

```
Contract:
pragma experimental ABIEncoderV2;

contract C {
function f() public returns (bytes memory) {
bytes memory m = new bytes(64);
m[0] = 0x01;
m[1] = 0x02;
m[2] = 0x03;
m[3] = 0x04;
return m;
}
}

Expected result:
// f() -> 0x20, 4, hex"01020304", 0, hex"00000000000000000000000000000000000000000000000000000000"

Obtained result:
// f() -> 32, 64, hex"0102030400000000000000000000000000000000000000000000000000000000"
Warning: Encoding does not match byte range. The call returned 128 bytes, but 128 bytes were expected.
```

This also fails after "updating":
```
Contract:
pragma experimental ABIEncoderV2;

contract C {
function f() public returns (bytes memory) {
bytes memory m = new bytes(64);
m[0] = 0x01;
m[1] = 0x02;
m[2] = 0x03;
m[3] = 0x04;
return m;
}
}

Expected result:
// f() -> 32, 64, hex"0102030400000000000000000000000000000000000000000000000000000000"

Obtained result:
// f() -> 32, 64, hex"0102030400000000000000000000000000000000000000000000000000000000"

Attention: Updates on the test will apply the detected format displayed.
```

How I got to this and what works is the following:
```
pragma experimental ABIEncoderV2;

contract C {
struct S { uint8 a; bytes1 b; }
function g(S calldata s) external pure returns (bytes memory) {
return msg.data;
}
function f(uint256 a, uint256 b) public returns (bytes memory) {
S memory s = S(2,0x02);
return this.g(s);
}
}

// ----
// f(uint256,uint256): 1, 1 -> 0x20, 0x44, hex"15fc073c", 2, left(0x02), hex"00000000000000000000000000000000000000000000000000000000"
```
But this also yields weird suggestions for incorrect or short expectations, e.g.
```
Expected result:
// f(uint256,uint256): 1, 1 -> 0x20, 0x44, hex"15fc073c", 1, left(0x02), hex"00000000000000000000000000000000000000000000000000000000"

Obtained result:
// f(uint256,uint256): 1, 1 -> 32, 68, hex"15fc073c00000000000000000000000000000000000000000000000000000000"
```
Or

```
Expected result:
// f(uint256,uint256): 1, 1 -> 0x20, 0x44, hex"15fc073c"

Obtained result:
// f(uint256,uint256): 1, 1 -> 0x20, 0x44, hex"15fc073c00000000000000000000000000000000000000000000000000000000"

Attention: Updates on the test will apply the detected format displayed.
```

Ping @erak.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the supplied unaligned-hex and short-expectation cases through soltest, comparing the expected and obtained suggestions. Trace the semantics-test suggestion and update behavior for these contracts; done means mismatched, unaligned, and incomplete expectations produce correct suggestions and updates.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, solidity
Domain
compilers, testing-qa
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.