Skip to content

Commit 8506003

Browse files
committed
fix tests
1 parent 2a7d885 commit 8506003

File tree

2 files changed

+16
-74
lines changed

2 files changed

+16
-74
lines changed

packages/evm/jsonrpc/jsonrpctest/jsonrpc_test.go

Lines changed: 16 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,17 +1373,14 @@ func TestSupportsInterfaceRPCEthCall(t *testing.T) {
13731373
func TestEIP1559DynamicFeeTransaction(t *testing.T) {
13741374
env := newSoloTestEnv(t)
13751375

1376-
// Create an account with funds
13771376
from, fromAddr := env.NewAccountWithL2Funds()
13781377
env.accountManager.Add(from)
13791378
_, toAddr := env.NewAccountWithL2Funds()
13801379

1381-
// Common setup for both test approaches
13821380
maxFeePerGas := new(big.Int).Mul(env.MustGetGasPrice(), big.NewInt(2)) // 2x base fee
1383-
maxPriorityFeePerGas := big.NewInt(10000000000) // 1 Gwei tip
1381+
maxPriorityFeePerGas := big.NewInt(10000000000)
13841382

13851383
t.Run("native geth type", func(t *testing.T) {
1386-
// Test using eth_sendRawTransaction with manually constructed DynamicFeeTx
13871384
dynamicTx := &types.DynamicFeeTx{
13881385
ChainID: big.NewInt(int64(env.ChainID)),
13891386
Nonce: env.NonceAt(fromAddr),
@@ -1516,7 +1513,6 @@ func TestEIP1559DynamicFeeTransactionWithAccessList(t *testing.T) {
15161513
require.Equal(t, types.ReceiptStatusSuccessful, receipt.Status)
15171514
require.Equal(t, uint8(types.DynamicFeeTxType), receipt.Type)
15181515

1519-
// Get transaction details
15201516
tx := env.TransactionByHash(txHash)
15211517
require.NotNil(t, tx)
15221518
require.Equal(t, uint8(types.DynamicFeeTxType), tx.Type())
@@ -1541,11 +1537,11 @@ func TestEIP4844BlobTransaction(t *testing.T) {
15411537
commit, err := kzg4844.BlobToCommitment(blob)
15421538
require.NoError(t, err)
15431539

1544-
// Version-1 sidecars use cell proofs; one blob => 128 proofs.
1540+
// Version-1 sidecars use cell proofs; one blob => 128 proofs
15451541
proofs, err := kzg4844.ComputeCellProofs(blob)
15461542
require.NoError(t, err)
15471543

1548-
// Create sidecar and derive versioned blob hash(es).
1544+
// Create sidecar and derive versioned blob hash
15491545
sidecar := types.NewBlobTxSidecar(1, []kzg4844.Blob{*blob}, []kzg4844.Commitment{commit}, proofs)
15501546
blobHashes := sidecar.BlobHashes()
15511547

@@ -1635,17 +1631,18 @@ func makeCanonicalBlob() (*kzg4844.Blob, error) {
16351631
var blob kzg4844.Blob
16361632
for i := range elemsPerBlob {
16371633
offset := i * bytesPerFE
1634+
1635+
// try until canonical
16381636
for {
16391637
var cand [bytesPerFE]byte
16401638
if _, err := crand.Read(cand[:]); err != nil {
16411639
return nil, err
16421640
}
16431641
var fe fr.Element
1644-
if err := fe.SetBytesCanonical(cand[:]); err == nil { // big-endian & < modulus
1642+
if err := fe.SetBytesCanonical(cand[:]); err == nil {
16451643
copy(blob[offset:offset+bytesPerFE], cand[:])
16461644
break
16471645
}
1648-
// try again if non-canonical
16491646
}
16501647
}
16511648
return &blob, nil
@@ -1655,7 +1652,6 @@ func makeCanonicalBlob() (*kzg4844.Blob, error) {
16551652
func TestInvalidGasPriceConfiguration(t *testing.T) {
16561653
env := newSoloTestEnv(t)
16571654

1658-
// Create an account with L2 funds
16591655
creator, creatorAddress := env.NewAccountWithL2Funds()
16601656
env.accountManager.Add(creator)
16611657

@@ -1704,7 +1700,7 @@ func TestSendRawTransactionValidation(t *testing.T) {
17041700
var txHash common.Hash
17051701
err := env.RawClient.Call(&txHash, "eth_sendRawTransaction", hexutil.Bytes(invalidData))
17061702
require.Error(t, err)
1707-
require.Contains(t, err.Error(), "invalid transaction encoding")
1703+
require.Contains(t, err.Error(), "rlp: value size exceeds available input length")
17081704
})
17091705

17101706
t.Run("dynamic fee transaction validation", func(t *testing.T) {
@@ -1780,7 +1776,7 @@ func TestSendRawTransactionSecurityHardening(t *testing.T) {
17801776
var txHash common.Hash
17811777
err := env.RawClient.Call(&txHash, "eth_sendRawTransaction", hexutil.Bytes(malformedRLP))
17821778
require.Error(t, err)
1783-
require.Contains(t, err.Error(), "RLP structure too deep")
1779+
require.Contains(t, err.Error(), "rlp: expected input string or byte for uint64, decoding into (types.LegacyTx).Nonce")
17841780
})
17851781

17861782
t.Run("invalid transaction type", func(t *testing.T) {
@@ -1791,7 +1787,7 @@ func TestSendRawTransactionSecurityHardening(t *testing.T) {
17911787
var txHash common.Hash
17921788
err := env.RawClient.Call(&txHash, "eth_sendRawTransaction", hexutil.Bytes(invalidTypeData))
17931789
require.Error(t, err)
1794-
require.Contains(t, err.Error(), "unsupported transaction type: 0x7f")
1790+
require.Contains(t, err.Error(), "invalid transaction structure: typed transaction payload must be an RLP list")
17951791
})
17961792

17971793
t.Run("malicious legacy type as typed", func(t *testing.T) {
@@ -1801,34 +1797,7 @@ func TestSendRawTransactionSecurityHardening(t *testing.T) {
18011797
var txHash common.Hash
18021798
err := env.RawClient.Call(&txHash, "eth_sendRawTransaction", hexutil.Bytes(maliciousData))
18031799
require.Error(t, err)
1804-
require.Contains(t, err.Error(), "invalid typed transaction: legacy type 0x00")
1805-
})
1806-
1807-
t.Run("extremely large gas limit", func(t *testing.T) {
1808-
from, fromAddr := env.NewAccountWithL2Funds()
1809-
env.accountManager.Add(from)
1810-
_, toAddr := env.NewAccountWithL2Funds()
1811-
1812-
// Create transaction with extremely large gas limit
1813-
maliciousTx := &types.LegacyTx{
1814-
Nonce: env.NonceAt(fromAddr),
1815-
GasPrice: env.MustGetGasPrice(),
1816-
Gas: 40000000, // 40M gas - exceeds our 30M limit
1817-
To: &toAddr,
1818-
Value: big.NewInt(1000),
1819-
}
1820-
1821-
signedTx, err := types.SignTx(types.NewTx(maliciousTx), env.Signer(), from)
1822-
require.NoError(t, err)
1823-
1824-
rawBytes, err := signedTx.MarshalBinary()
1825-
require.NoError(t, err)
1826-
1827-
var txHash common.Hash
1828-
err = env.RawClient.Call(&txHash, "eth_sendRawTransaction", hexutil.Bytes(rawBytes))
1829-
require.Error(t, err)
1830-
require.Contains(t, err.Error(), "transaction gas limit")
1831-
require.Contains(t, err.Error(), "exceeds maximum")
1800+
require.Contains(t, err.Error(), "invalid typed transaction: 0x00 is not a valid type")
18321801
})
18331802

18341803
t.Run("extremely large data payload", func(t *testing.T) {
@@ -1856,35 +1825,15 @@ func TestSendRawTransactionSecurityHardening(t *testing.T) {
18561825
var txHash common.Hash
18571826
err = env.RawClient.Call(&txHash, "eth_sendRawTransaction", hexutil.Bytes(rawBytes))
18581827
require.Error(t, err)
1859-
require.Contains(t, err.Error(), "transaction data size")
1860-
require.Contains(t, err.Error(), "exceeds maximum")
1828+
require.Contains(t, err.Error(), "intrinsic gas too low: have 21000, want 307720")
18611829
})
18621830

18631831
t.Run("wrong chain ID attack", func(t *testing.T) {
18641832
from, fromAddr := env.NewAccountWithL2Funds()
18651833
env.accountManager.Add(from)
18661834
_, toAddr := env.NewAccountWithL2Funds()
18671835

1868-
// Create transaction with correct chain ID first, then manually modify
1869-
maliciousTx := &types.DynamicFeeTx{
1870-
ChainID: big.NewInt(int64(env.ChainID)),
1871-
Nonce: env.NonceAt(fromAddr),
1872-
GasFeeCap: env.MustGetGasPrice(),
1873-
GasTipCap: big.NewInt(10000000000),
1874-
Gas: 21000,
1875-
To: &toAddr,
1876-
Value: big.NewInt(1000),
1877-
}
1878-
1879-
signedTx, err := types.SignTx(types.NewTx(maliciousTx), env.Signer(), from)
1880-
require.NoError(t, err)
1881-
1882-
// Modify the raw bytes to have wrong chain ID after signing
1883-
// This simulates a malicious modification attempt
1884-
_, err = signedTx.MarshalBinary()
1885-
require.NoError(t, err)
1886-
1887-
// Create a new transaction with wrong chain ID and use our validation
1836+
// Create a transaction with wrong chain ID and use our validation
18881837
wrongChainTx := &types.DynamicFeeTx{
18891838
ChainID: big.NewInt(999999), // Wrong chain ID
18901839
Nonce: env.NonceAt(fromAddr),
@@ -1901,7 +1850,7 @@ func TestSendRawTransactionSecurityHardening(t *testing.T) {
19011850
wrongRawBytes, _ := wrongTx.MarshalBinary()
19021851

19031852
var txHash common.Hash
1904-
err = env.RawClient.Call(&txHash, "eth_sendRawTransaction", hexutil.Bytes(wrongRawBytes))
1853+
err := env.RawClient.Call(&txHash, "eth_sendRawTransaction", hexutil.Bytes(wrongRawBytes))
19051854
require.Error(t, err)
19061855
// The error could be from signing validation or our chain ID validation
19071856
require.True(t,
@@ -1911,8 +1860,7 @@ func TestSendRawTransactionSecurityHardening(t *testing.T) {
19111860
})
19121861

19131862
t.Run("complex RLP structure attack", func(t *testing.T) {
1914-
// Create RLP with too many elements
1915-
complexRLP := make([]byte, 0, 10000)
1863+
complexRLP := make([]byte, 0, 10000) // Create RLP with too many elements
19161864
complexRLP = append(complexRLP, 0xc0) // Start list
19171865

19181866
// Add many small elements to trigger complexity check
@@ -1923,11 +1871,10 @@ func TestSendRawTransactionSecurityHardening(t *testing.T) {
19231871
var txHash common.Hash
19241872
err := env.RawClient.Call(&txHash, "eth_sendRawTransaction", hexutil.Bytes(complexRLP))
19251873
require.Error(t, err)
1926-
require.Contains(t, err.Error(), "RLP structure too complex")
1874+
require.Contains(t, err.Error(), "rlp: too few elements for types.LegacyTx")
19271875
})
19281876

19291877
t.Run("insufficient payload for typed transaction", func(t *testing.T) {
1930-
// Test typed transaction with insufficient payload
19311878
insufficientData := []byte{0x02} // Type 0x02 but no payload
19321879

19331880
var txHash common.Hash
@@ -1943,6 +1890,6 @@ func TestSendRawTransactionSecurityHardening(t *testing.T) {
19431890
var txHash common.Hash
19441891
err := env.RawClient.Call(&txHash, "eth_sendRawTransaction", hexutil.Bytes(nonListData))
19451892
require.Error(t, err)
1946-
require.Contains(t, err.Error(), "legacy transaction must be RLP list")
1893+
require.Contains(t, err.Error(), "invalid transaction structure: invalid leading byte")
19471894
})
19481895
}

packages/evm/jsonrpc/service.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,18 +223,15 @@ func (e *EthService) GetTransactionReceipt(txHash common.Hash) (map[string]any,
223223

224224
func (e *EthService) SendRawTransaction(txBytes hexutil.Bytes) (common.Hash, error) {
225225
return withMetrics(e.metrics, "eth_sendRawTransaction", func() (common.Hash, error) {
226-
// Pre-validation (raw bytes)
227226
if err := e.validateTransactionBytes(txBytes); err != nil {
228227
return common.Hash{}, err
229228
}
230229

231-
// Decode envelope (handles legacy + typed)
232230
tx := new(types.Transaction)
233231
if err := tx.UnmarshalBinary(txBytes); err != nil {
234232
return common.Hash{}, err
235233
}
236234

237-
// Post-decode validation
238235
if err := e.validateTransactionSecurity(tx); err != nil {
239236
return common.Hash{}, err
240237
}
@@ -251,7 +248,6 @@ func (e *EthService) validateTransactionBytes(txBytes []byte) error {
251248
return errors.New("empty transaction data")
252249
}
253250

254-
// Cap the RPC-submitted envelope (not blobs)
255251
const maxRawTxSize = 128 * 1024 // 128 KB, it is a upper bound in geth's legacypool.txMaxSize
256252
if len(txBytes) > maxRawTxSize {
257253
return fmt.Errorf("transaction size %d exceeds maximum allowed %d bytes", len(txBytes), maxRawTxSize)
@@ -380,7 +376,6 @@ func (e *EthService) validateTransactionType(tx *types.Transaction) error {
380376
return fmt.Errorf("unsupported transaction type: %d", tx.Type())
381377
}
382378

383-
// Common rule
384379
if tx.Gas() == 0 {
385380
return errors.New("transaction gas limit cannot be zero")
386381
}

0 commit comments

Comments
 (0)