Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling eth_getTransactionByHash with rpc cheatcode failed #7858

Open
2 tasks done
bluele opened this issue May 5, 2024 · 1 comment
Open
2 tasks done

Calling eth_getTransactionByHash with rpc cheatcode failed #7858

bluele opened this issue May 5, 2024 · 1 comment
Labels
T-bug Type: bug

Comments

@bluele
Copy link

bluele commented May 5, 2024

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (aa333c6 2024-05-05T00:18:50.527833809Z)

What command(s) is the bug in?

forge test

Operating System

Linux

Describe the bug

When I call eth_getTransactionByHash with rpc cheatcode, always got an error [Revert] panic: memory allocation error (0x41).

A minimal reproducible example is the following:

pragma solidity ^0.8.13;

import {Test, console} from "forge-std/Test.sol";

contract RPCTest is Test {
    function test_fail_rpc_transactionByHash() public {
        string memory res = getTransactionByHash();
        console.log(res);
    }

    // https://sepolia.etherscan.io/tx/0xe1a0fba63292976050b2fbf4379a1901691355ed138784b4e0d1854b4cf9193e
    function getTransactionByHash() internal returns (string memory) {
        string memory param = string.concat('["0xe1a0fba63292976050b2fbf4379a1901691355ed138784b4e0d1854b4cf9193e"]');
        bytes memory res = vm.rpc("eth_getTransactionByHash", param);
        return string(res);
    } 
}

The execution result of forge test is the following:

$ forge test -vvvv --rpc-url https://ethereum-sepolia-archive.allthatnode.com --match-test test_fail
[⠊] Compiling...
No files changed, compilation skipped

Ran 1 test for test/RPC.t.sol:RPCTest
[FAIL. Reason: panic: memory allocation error (0x41)] test_fail_rpc_transactionByHash() (gas: 4020)
Traces:
  [4020] RPCTest::test_fail_rpc_transactionByHash()
    ├─ [0] VM::rpc("eth_getTransactionByHash", "[\"0xe1a0fba63292976050b2fbf4379a1901691355ed138784b4e0d1854b4cf9193e\"]")
    │   └─ ← [Return] 0x000000000000000000000000000000000000000000000000000000000000002050b08560cfeef4a4005333a78bef1190f3d8708a074c549e0e5d834c6d7eab3f000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002400000000000000000000000008be6209bc9bd1a8e6e015ade090f6be7be6f032a000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000002c0e1a0fba63292976050b2fbf4379a1901691355ed138784b4e0d1854b4cf9193e0000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000036006a0fc7389ed9bfc5bf6640f83532deb7a0655d9409e4d6ad34edcdb9573099243f5a576702efe6309bd01005d4742846b8878a01240b9216b9c182e7e7a4011000000000000000000000000f04fd9a66de511bc389d3b830c1f850a4a4a8c6100000000000000000000000000000000000000000000000000000000000003a000000000000000000000000000000000000000000000000000000000000003e0000000000000000000000000000000000000000000000000000000000000042000000000000000000000000000000000000000000000000000000000000004600000000000000000000000000000000000000000000000000000000000000003588b2400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003aa36a7000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030f4240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000047b9d0bef0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000241b7a66b1000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000103000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000401546d710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000
    └─ ← [Revert] panic: memory allocation error (0x41)

Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 944.69ms (230.48ms CPU time)

Ran 1 test suite in 1.53s (944.69ms CPU time): 0 tests passed, 1 failed, 0 skipped (1 total tests)

Failing tests:
Encountered 1 failing test in test/RPC.t.sol:RPCTest
[FAIL. Reason: panic: memory allocation error (0x41)] test_fail_rpc_transactionByHash() (gas: 4020)

Encountered a total of 1 failing tests, 0 tests succeeded

The forge config is

[profile.default]
src = "src"
test = "test"
script = "script"
out = "out"
libs = ["lib"]
remappings = ["forge-std/=lib/forge-std/src/"]
auto_detect_remappings = true
libraries = []
cache = true
cache_path = "cache"
broadcast = "broadcast"
allow_paths = []
include_paths = []
force = false
evm_version = "paris"
gas_reports = ["*"]
gas_reports_ignore = []
auto_detect_solc = true
offline = false
optimizer = true
optimizer_runs = 200
verbosity = 0
ignored_error_codes = [
    "license",
    "code-size",
    "init-code-size",
    "transient-storage",
]
ignored_warnings_from = []
deny_warnings = false
disable_block_gas_limit = false
isolate = false
ffi = false
always_use_create_2_factory = false
prompt_timeout = 120
sender = "0x1804c8ab1f12e6bbf3894d4083f33e07309d1f38"
tx_origin = "0x1804c8ab1f12e6bbf3894d4083f33e07309d1f38"
initial_balance = "0xffffffffffffffffffffffff"
block_number = 1
gas_limit = 9223372036854775807
block_base_fee_per_gas = 0
block_coinbase = "0x0000000000000000000000000000000000000000"
block_timestamp = 1
block_difficulty = 0
block_prevrandao = "0x0000000000000000000000000000000000000000000000000000000000000000"
memory_limit = 134217728
extra_output = []
extra_output_files = []
names = false
sizes = false
via_ir = false
ast = false
no_storage_caching = false
no_rpc_rate_limit = false
use_literal_content = false
bytecode_hash = "ipfs"
cbor_metadata = true
sparse_mode = false
build_info = false
unchecked_cheatcode_artifacts = false
cancun = false

[[profile.default.fs_permissions]]
access = "read"
path = "out"

[profile.default.rpc_storage_caching]
chains = "all"
endpoints = "all"

[fmt]
line_length = 120
tab_width = 4
bracket_spacing = false
int_types = "long"
multiline_func_header = "attributes_first"
quote_style = "double"
number_underscore = "preserve"
hex_underscore = "remove"
single_line_statement_blocks = "preserve"
override_spacing = false
wrap_comments = false
ignore = []
contract_new_lines = false
sort_imports = false

[doc]
out = "docs"
title = ""
book = "book.toml"
homepage = "README.md"
ignore = []

[fuzz]
runs = 256
max_test_rejects = 65536
dictionary_weight = 40
include_storage = true
include_push_bytes = true
max_fuzz_dictionary_addresses = 15728640
max_fuzz_dictionary_values = 6553600
gas_report_samples = 256
failure_persist_dir = "cache/fuzz"
failure_persist_file = "failures"

[invariant]
runs = 256
depth = 15
fail_on_revert = false
call_override = false
dictionary_weight = 80
include_storage = true
include_push_bytes = true
max_fuzz_dictionary_addresses = 15728640
max_fuzz_dictionary_values = 6553600
shrink_sequence = true
shrink_run_limit = 262144
preserve_state = false
max_assume_rejects = 65536
gas_report_samples = 256

[labels]
@mattsse
Copy link
Member

mattsse commented May 5, 2024

@DaniPopes It looks like this is due to encoded objects which results in a reverted call

let params_json: serde_json::Value = serde_json::from_str(params)?;
let result = RuntimeOrHandle::new()
.block_on(provider.raw_request(method.into(), params_json))
.map_err(|err| fmt_err!("{method:?}: {err}"))?;
let result_as_tokens = crate::json::json_value_to_token(&result)
.map_err(|err| fmt_err!("failed to parse result: {err}"))?;
Ok(result_as_tokens.abi_encode())

should we return to_string here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
None yet
Development

No branches or pull requests

2 participants