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

Avoid chainid underflow when v = 0 #14

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions cmd/rpcdaemon/commands/eth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,13 @@ func newRPCTransaction(tx types.Transaction, blockHash common.Hash, blockNumber
}
switch t := tx.(type) {
case *types.LegacyTx:
chainId = types.DeriveChainId(&t.V)
// if a legacy transaction has an EIP-155 chain id, include it explicitly, otherwise chain id is not included
if !chainId.IsZero() {
result.ChainID = (*hexutil.Big)(chainId.ToBig())
// avoid overflow by not calling DeriveChainId. chain id not included when v = 0
if !t.V.IsZero() {
chainId = types.DeriveChainId(&t.V)
// if a legacy transaction has an EIP-155 chain id, include it explicitly, otherwise chain id is not included
if !chainId.IsZero() {
result.ChainID = (*hexutil.Big)(chainId.ToBig())
}
}
result.GasPrice = (*hexutil.Big)(t.GasPrice.ToBig())
result.V = (*hexutil.Big)(t.V.ToBig())
Expand Down
11 changes: 7 additions & 4 deletions turbo/adapter/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,13 @@ func newRPCTransaction(tx types.Transaction, blockHash libcommon.Hash, blockNumb
}
switch t := tx.(type) {
case *types.LegacyTx:
chainId = types.DeriveChainId(&t.V)
// if a legacy transaction has an EIP-155 chain id, include it explicitly, otherwise chain id is not included
if !chainId.IsZero() {
result.ChainID = (*hexutil.Big)(chainId.ToBig())
// avoid overflow by not calling DeriveChainId. chain id not included when v = 0
if !t.V.IsZero() {
chainId = types.DeriveChainId(&t.V)
// if a legacy transaction has an EIP-155 chain id, include it explicitly, otherwise chain id is not included
if !chainId.IsZero() {
result.ChainID = (*hexutil.Big)(chainId.ToBig())
}
}
result.GasPrice = (*hexutil.Big)(t.GasPrice.ToBig())
result.V = (*hexutil.Big)(t.V.ToBig())
Expand Down