Skip to content

Adding rpc package with ethereum json rpc compatible methods + tests#1613

Open
otherview wants to merge 22 commits into
eth-equivalencefrom
pedro/eth_eq_json_rpc
Open

Adding rpc package with ethereum json rpc compatible methods + tests#1613
otherview wants to merge 22 commits into
eth-equivalencefrom
pedro/eth_eq_json_rpc

Conversation

@otherview
Copy link
Copy Markdown
Member

Description

Ethereum Compatibility: EIP-1559 Transactions & JSON-RPC Server

This PR adds first-class support for Ethereum EIP-1559 transactions to VeChain Thor and exposes an Ethereum-compatible JSON-RPC endpoint, enabling standard Ethereum tooling
(MetaMask, ethers.js, viem, Hardhat, Foundry) to interact with VeChain nodes without modification.


What's new

New transaction type: TypeEthTyped1559 (0x02)

A new native transaction type that conforms to the Ethereum EIP-1559 wire format (0x02 || RLP(body)), gated behind the new INTERSTELLAR fork:

  • Wire format: standard EIP-1559 (chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList, yParity, r, s)
  • Chain ID: derived deterministically from the genesis block ID via thor.GetEthChainID() — no config needed
  • Replay protection: chain ID replaces VeChain's chain tag for these transactions
  • Signature validation: low-S enforcement, ECDSA recovery, zero-sender rejection
  • Sender nonce: state.GetNonce / state.SetNonce tracks per-account ETH nonces in the state trie, matching Ethereum semantics
  • Fee model: EIP-1559 effective gas price (min(maxFeePerGas, baseFee + maxPriorityFeePerGas)) integrated into the existing GALACTICA fee deduction path
  • Block accounting: txFitsBlockSize enforced post-INTERSTELLAR; block GasUsed includes ETH tx gas
  • Consensus: validateBlockBody rejects malformed ETH txs, enforces field ranges and signature bounds
  • EthBuilder: tx.NewEthBuilder(TypeEthTyped1559) builder API for constructing and signing ETH transactions in Go

Ethereum JSON-RPC server (rpc/)

A new root-level rpc/ package (mirroring the structure of api/) implements a JSON-RPC 2.0 server exposing standard Ethereum methods. Launched separately from the REST API on its own
port.

Key projection semantics: VeChain blocks can contain a mix of native and ETH transactions. The JSON-RPC server projects only TypeEthTyped1559 transactions into the Ethereum-visible view — native transactions are invisible to ETH tooling.

Node wiring

  • New --eth-rpc-addr flag (default localhost:8646) starts the Ethereum JSON-RPC server alongside the existing REST API
  • cmd/thor/httpserver/eth_rpc_server.go assembles all sub-packages onto a dispatcher and applies CORS

Out of scope (tracked as TODOs)

  • Access lists (EIP-2930): rejected at the engine level until EIP-2929 warm/cold gas accounting is implemented in the VM
  • Mempool nonce validation: sequential nonce enforcement deferred to dedicated mempool work
  • Log bloom filters: logsBloom in blocks and receipts returns a zero placeholder
  • Merkle roots: transactionsRoot and receiptsRoot return zero hashes
  • OR-within-position topic filters in eth_getLogs: only the first alternative per position is used

Tests

  • Each rpc/ sub-package has a focused handler_test.go testing only its own methods in isolation
  • rpc/integration_test.go covers server- and dispatcher-level behaviour (batch processing, batch size limit, method-not-found, invalid JSON, wrong HTTP method)
  • rpc/testutil provides a shared ChainFixture (genesis + 1 block with both a native and an ETH tx) and helpers used across all sub-package tests
  • thorclient/rpc_test.go provides end-to-end integration tests across the full two-block chain: block retrieval, transaction visibility (ETH visible / VeChain invisible), receipt
    transactionIndex and cumulativeGasUsed assertions, fee history, simulation, and a full send → mine → read cycle via eth_sendRawTransaction

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • New and existing E2E tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have not added any vulnerable dependencies to my code

@otherview otherview requested a review from a team as a code owner May 6, 2026 16:35
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 6, 2026

Comment thread rpc/utils.go Outdated
@otherview otherview force-pushed the pedro/eth_eq_json_rpc branch from 3f3eb4f to fa57e7c Compare May 7, 2026 21:31
@otherview otherview changed the base branch from pedro/eth_eq_nonce to pedro/eth_eq_nonce_v2 May 8, 2026 11:35
@otherview otherview force-pushed the pedro/eth_eq_json_rpc branch from fa57e7c to 47892f7 Compare May 8, 2026 13:18
Base automatically changed from pedro/eth_eq_nonce_v2 to eth-equivalence May 8, 2026 13:30
otherview and others added 7 commits May 11, 2026 15:30
chainID is now sourced from repo.ChainID() internally in BuildEthBlock
and is not needed in ToEthReceipt (receipts carry no chainId field).
Also adds TODO comments flagging known gaps in gasUsedRatio, eth_getLogs
performance, topic OR-filtering, and ethSendRawTransaction guarantees.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@otherview otherview force-pushed the pedro/eth_eq_json_rpc branch from f640538 to be50fd2 Compare May 15, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants