Skip to content

Commit 9a65413

Browse files
decofezerosnacks
andauthored
refactor: use native Solidity types for vm.rpc struct decoding (#14050)
Remove Tuple recursion from convert_to_bytes so nested Address and FixedBytes keep their native ABI types. Update test structs to use address/bytes32 instead of bytes with manual casting. Amp-Thread-ID: https://ampcode.com/threads/T-019d48d8-3368-7501-9ee0-49ac43fd1503 Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
1 parent 0534303 commit 9a65413

2 files changed

Lines changed: 22 additions & 27 deletions

File tree

crates/cheatcodes/src/evm/fork.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,6 @@ fn convert_to_bytes(token: &DynSolValue) -> DynSolValue {
599599
DynSolValue::Bytes(bytes.as_slice()[..*size].to_vec())
600600
}
601601
DynSolValue::Address(addr) => DynSolValue::Bytes(addr.to_vec()),
602-
// Convert tuple values to prevent encoding issues.
603-
// See: <https://github.com/foundry-rs/foundry/issues/7858>
604-
DynSolValue::Tuple(vals) => DynSolValue::Tuple(vals.iter().map(convert_to_bytes).collect()),
605602
val => val.clone(),
606603
}
607604
}

testdata/default/cheats/Fork2.t.sol

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -247,38 +247,38 @@ contract ForkTest is Test {
247247
bytes extraData;
248248
bytes gasLimit;
249249
bytes gasUsed;
250-
bytes hash;
250+
bytes32 hash;
251251
bytes logsBloom;
252-
bytes miner;
253-
bytes mixHash;
252+
address miner;
253+
bytes32 mixHash;
254254
bytes nonce;
255255
bytes number;
256-
bytes parentBeaconBlockRoot;
257-
bytes parentHash;
258-
bytes receiptsRoot;
259-
bytes sha3Uncles;
256+
bytes32 parentBeaconBlockRoot;
257+
bytes32 parentHash;
258+
bytes32 receiptsRoot;
259+
bytes32 sha3Uncles;
260260
bytes size;
261-
bytes stateRoot;
261+
bytes32 stateRoot;
262262
bytes timestamp;
263263
bytes32[] transactions;
264-
bytes transactionsRoot;
265-
bytes[] uncles;
264+
bytes32 transactionsRoot;
265+
bytes32[] uncles;
266266
Withdrawal[] withdrawals;
267-
bytes withdrawalsRoot;
267+
bytes32 withdrawalsRoot;
268268
}
269269

270270
function testRpcBlockByNumberFullReturndata() public {
271271
bytes memory data = vm.rpc("sepolia", "eth_getBlockByNumber", '["0x588b24", false]');
272272
BlockResult memory blockResult = abi.decode(data, (BlockResult));
273273
// Verify block hash
274274
assertEq(
275-
bytes32(blockResult.hash),
275+
blockResult.hash,
276276
bytes32(hex"50b08560cfeef4a4005333a78bef1190f3d8708a074c549e0e5d834c6d7eab3f"),
277277
"hash mismatch"
278278
);
279279
// Verify parent hash
280280
assertEq(
281-
bytes32(blockResult.parentHash),
281+
blockResult.parentHash,
282282
bytes32(hex"ee012f100cea384420e993e4eab8c3cf0ed35a49f75769eb8a37c9e0c93ea235"),
283283
"parentHash mismatch"
284284
);
@@ -323,18 +323,18 @@ contract ForkTest is Test {
323323

324324
// Struct matching a legacy (type 0) transaction fields sorted alphabetically.
325325
struct LegacyTransactionResult {
326-
bytes blockHash;
326+
bytes32 blockHash;
327327
bytes blockNumber;
328328
bytes chainId;
329-
bytes from;
329+
address from;
330330
bytes gas;
331331
bytes gasPrice;
332-
bytes hash;
332+
bytes32 hash;
333333
bytes input;
334334
bytes nonce;
335-
bytes r;
336-
bytes s;
337-
bytes to;
335+
bytes32 r;
336+
bytes32 s;
337+
address to;
338338
bytes transactionIndex;
339339
bytes type_;
340340
bytes v;
@@ -353,12 +353,10 @@ contract ForkTest is Test {
353353
);
354354
LegacyTransactionResult memory txn = abi.decode(data, (LegacyTransactionResult));
355355
assertEq(
356-
bytes32(txn.hash),
357-
bytes32(hex"e1a0fba63292976050b2fbf4379a1901691355ed138784b4e0d1854b4cf9193e"),
358-
"tx hash mismatch"
356+
txn.hash, bytes32(hex"e1a0fba63292976050b2fbf4379a1901691355ed138784b4e0d1854b4cf9193e"), "tx hash mismatch"
359357
);
360-
assertEq(address(bytes20(txn.from)), 0x8Be6209bC9BD1a8e6e015ADe090F6BE7BE6f032A, "tx from mismatch");
361-
assertEq(address(bytes20(txn.to)), 0xF04fd9a66DE511BC389D3b830C1F850a4A4A8c61, "tx to mismatch");
358+
assertEq(txn.from, 0x8Be6209bC9BD1a8e6e015ADe090F6BE7BE6f032A, "tx from mismatch");
359+
assertEq(txn.to, 0xF04fd9a66DE511BC389D3b830C1F850a4A4A8c61, "tx to mismatch");
362360
assertEq(txn.blockNumber, hex"588b24", "tx blockNumber mismatch");
363361
}
364362
}

0 commit comments

Comments
 (0)