statetest: BLOCKHASH range check breaks when currentNumber > 2^63-1

Đang mở
#1,493 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
cpp
Lĩnh vực
blockchain

Hướng nghiên cứu

Start by reading lib/evmone/instructions.hpp around blockhash(), then trace how test/utils/statetest_loader.cpp and test/state/block.hpp represent the current block number. Run the provided reproducer with build/debug/bin/evmone-statetest; done means its post-state root matches the geth result for this high-number Cancun test.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

evmone-statetest diverges from geth on a valid Cancun state test when env.currentNumber is above INT64_MAX.

The test executes BLOCKHASH(currentNumber - 1) and then stores ISZERO(result).

  • geth returns non-zero BLOCKHASH (in-range lookup), so ISZERO is 0.
  • evmone-statetest returns 0x0 for the same in-range lookup, so ISZERO is 1.

This produces different post-state roots.

Reproducer

files/case12-statetest-blockhash-highnum/blockhash_highnum_state_test.json

Commands
# geth: passes
~/go/bin/evm statetest --statetest.fork Cancun files/case12-statetest-blockhash-highnum/blockhash_highnum_state_test.json

# evmone: fails
build/debug/bin/evmone-statetest files/case12-statetest-blockhash-highnum/blockhash_highnum_state_test.json

Observed:

  • geth state root: 0x27ebe6aaf81779a3f3516512f8bdd8d543be038c26b9bba4bba5d85cce73f02f (PASS)
  • evmone state root: 0x48e2b3fe41a421a38716c88d2e14ad390b55ff6301db7d3b24079e55dc01e768 (FAIL)
Trace difference

For the same bytecode (0x6780000000000000ff401560005500):

  • geth trace shows BLOCKHASH pushes non-zero.
  • evmone trace shows BLOCKHASH pushes 0x0.
Likely root cause

The statetest path stores block numbers as signed 64-bit and BLOCKHASH range checks with signed bounds:

  • test/utils/statetest_loader.cpp: currentNumber parsed via from_json<int64_t>.
  • test/state/block.hpp: BlockInfo::number is int64_t.
  • lib/evmone/instructions.hpp blockhash():
    • upper_bound = state.get_tx_context().block_number (signed)
    • lower_bound = std::max(upper_bound - 256, 0)
    • n = static_cast<int64_t>(number)
    • signed comparison path rejects what should be valid currentNumber-1 lookups above INT64_MAX.

The EVM BLOCKHASH semantics are based on unsigned block numbers modulo 2^256 on stack values, with recent-256 window check relative to the current block number. Using signed block numbers in this path causes incorrect behavior for values above 2^63-1.

Ngôn ngữ chính
C++
Star
979
Fork
340
Merge trung bình
12 giờ 16 phút
Pull request đã merge (30 ngày)
25

Chuẩn bị môi trường

  • Có Dockerfile hoặc tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ipsilon/evmone

Tất cả issue của ipsilon/evmone

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.