argotorg / argotorg/solidity

[soltest] Unable to test functions accepting fixed bytes types shorter than 32 bytes

Open
#13,989 1 comment 0 reactions 0 assignees View on GitHub
bug :bug: low effort low impact must have eventually should compile without error testing :hammer:
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
21

Description

## Description

When a function accepts a fixed bytes type other than `bytes32`, an attempt to call it in soltest expectations results in a failure.

The failure does not happen for integer types or when the argument passed to the function is `0`. UDVTs based on fixed bytes types are affected as well.

I suspect that soltest might be badly encoding the arguments. E.g. not padding them to full 32 bytes.

## Environment

- Compiler version: 0.8.18 (`develop`)

## Steps to Reproduce
Test case:
```solidity
contract C {
function testBytes1(bytes1 x) public returns (bytes1) { return x; }
function testBytes4(bytes4 x) public returns (bytes4) { return x; }
function testBytes32(bytes32 x) public returns (bytes32) { return x; }
function testUint64(uint64 x) public returns (uint64) { return x; }
}
// ----
// testBytes1(bytes1): 0x42 -> 0x42
// testBytes4(bytes4): 0x42 -> 0x42
// testBytes32(bytes32): 0x42 -> 0x42
// testUint64(uint64): 0x42 -> 0x42

// testBytes1(bytes1): 0 -> 0
// testBytes4(bytes4): 0 -> 0
// testBytes32(bytes32): 0 -> 0
// testUint64(uint64): 0 -> 0

```
Output
```
Expected result:
// testBytes1(bytes1): 0x42 -> 0x42
// testBytes4(bytes4): 0x42 -> 0x42
// testBytes32(bytes32): 0x42 -> 0x42
// testUint64(uint64): 0x42 -> 0x42
// testBytes1(bytes1): 0 -> 0
// testBytes4(bytes4): 0 -> 0
// testBytes32(bytes32): 0 -> 0
// testUint64(uint64): 0 -> 0

Obtained result:
// testBytes1(bytes1): 0x42 -> FAILURE
Warning: The call to "testBytes1(bytes1)" returned

// testBytes4(bytes4): 0x42 -> FAILURE
Warning: The call to "testBytes4(bytes4)" returned

// testBytes32(bytes32): 0x42 -> 0x42
// testUint64(uint64): 0x42 -> 0x42
// testBytes1(bytes1): 0 -> 0
// testBytes4(bytes4): 0 -> 0
// testBytes32(bytes32): 0 -> 0
// testUint64(uint64): 0 -> 0

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

Note that the test also has to pass via Yul.
Run Settings: evmVersion=paris, optimize=false, useABIEncoderV1=false, batch=1/1
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provided soltest case and trace how soltest encodes arguments for fixed bytes types shorter than bytes32. Done means the bytes1 and bytes4 calls, including nonzero values and affected UDVTs, pass alongside the existing bytes32 and integer cases through both EVM and Yul tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, solidity
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.