foundry-rs / foundry-rs/forge-std

bug(StdJson): readBytes cannot handle 20-byte values

Closed
#592 5 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Solidity
Stars
1.1k
Forks
520
Avg merge
3d 13h
Merged PRs (30d)
9

Description

## Summary

**stdJson appears to be broken in latest forge-std. Reading 20-byte values with `readBytes(json, path)` returns incorrect results or reverts.**

#### Versions

**forge-std: v1.2.0**

```
forge --version
forge 0.2.0 (26a7559 2024-07-31T00:19:23.655582000Z)
```

## Minimal reproduction

```solidity
pragma solidity ^0.8.21;

import {Test} from "forge-std/Test.sol";
import {stdJson} from "forge-std/StdJson.sol";

using stdJson for string;

contract JsonTest is Test {
function testJson() public {
string memory data = '{"data":"0x1234"}';
bytes memory hello = data.readBytes(".data");
assertEq(hello, hex"1234");

// 19 bytes = works
data = '{"data":"0x00000000000000000000000000000000000000"}';
hello = data.readBytes(".data");
assertEq(hello, hex"00000000000000000000000000000000000000");

// 21 bytes = works
data = '{"data":"0x000000000000000000000000000000000000000000"}';
hello = data.readBytes(".data");
assertEq(hello, hex"000000000000000000000000000000000000000000");

// 20 bytes = returns without error, WRONG DATA
data = '{"data":"0x0000000000000000000000000000000000000000"}';
hello = data.readBytes(".data");
assertEq(hello, hex"");

// 20 bytes = REVERTS
data = '{"data":"0x4bf5122f344554c53bde2ebb8cd2b7e3d1600ad6"}';
data.readBytes(".data");
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.