Skip to content

Commit

Permalink
fix: add tx protected check at eth_sendRawTranasaction api (#144)
Browse files Browse the repository at this point in the history
* add tx protected check at eth_sendRawTranasaction api

* update jsonrpc readme

* add test case
  • Loading branch information
beer-1 committed Jan 28, 2025
1 parent 9bcc1da commit 9d2df76
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jsonrpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The ETH JSON-RPC (Remote Procedure Call) is a protocol that allows clients to in
| eth | eth_fillTransaction | 🚫 | Fills the defaults (nonce, gas, gasPrice or 1559 fields) on a given unsigned transaction, and returns it to the caller for further processing (signing + broadcast). |
| eth | eth_sendTransaction | 🚫 | Creates a new message call transaction or a contract creation if the data field contains code. |
| eth | eth_resend | 🚫 | Remove the given transaction from the pool and reinsert it with the new gas price and limit. |
| eth | eth_sendRawTransaction | βœ… | Sends a signed transaction to the network. |
| eth | eth_sendRawTransaction | βœ… | Sends a signed transaction to the network. Only replay-protected (EIP-155) transactions are accepted. |
| eth | eth_call | βœ… | Executes a new message call immediately without creating a transaction on the block chain. |
| eth | eth_estimateGas | βœ… | Generates an estimate of how much gas is necessary to allow the transaction to complete. |
| eth | eth_getBlockByHash | βœ… | Returns information about a block by hash. |
Expand Down
5 changes: 5 additions & 0 deletions jsonrpc/backend/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ func (b *JSONRPCBackend) SendRawTransaction(input hexutil.Bytes) (common.Hash, e
return common.Hash{}, err
}

if !tx.Protected() {
// Ensure only eip155 signed transactions are submitted if EIP155Required is set.
return common.Hash{}, errors.New("only replay-protected (EIP-155) transactions allowed over RPC")
}

if err := b.SendTx(tx); err != nil {
return common.Hash{}, err
}
Expand Down

0 comments on commit 9d2df76

Please sign in to comment.