TxPool will not pack tx with invalid chainId
This commit is contained in:
parent
494a61ceb6
commit
b74a080a3d
|
@ -45,6 +45,9 @@ type
|
||||||
## Implied disposal, typically implied by greater nonces (fallback value)
|
## Implied disposal, typically implied by greater nonces (fallback value)
|
||||||
"implied disposal"
|
"implied disposal"
|
||||||
|
|
||||||
|
txInfoChainIdMismatch = ##\
|
||||||
|
## Tx chainId does not match with network chainId
|
||||||
|
"chainId mismatch"
|
||||||
# ------ Miscellaneous errors ----------------------------------------------
|
# ------ Miscellaneous errors ----------------------------------------------
|
||||||
|
|
||||||
txInfoErrUnspecified = ##\
|
txInfoErrUnspecified = ##\
|
||||||
|
|
|
@ -27,7 +27,7 @@ import
|
||||||
../../../transaction,
|
../../../transaction,
|
||||||
../../../vm_state,
|
../../../vm_state,
|
||||||
../../../vm_types,
|
../../../vm_types,
|
||||||
".."/[tx_chain, tx_desc, tx_item, tx_tabs, tx_tabs/tx_status],
|
".."/[tx_chain, tx_desc, tx_item, tx_tabs, tx_tabs/tx_status, tx_info],
|
||||||
"."/[tx_bucket, tx_classify]
|
"."/[tx_bucket, tx_classify]
|
||||||
|
|
||||||
type
|
type
|
||||||
|
@ -186,6 +186,10 @@ proc vmExecGrabItem(pst: TxPackerStateRef; item: TxItemRef): Result[bool,void]
|
||||||
xp = pst.xp
|
xp = pst.xp
|
||||||
vmState = xp.chain.vmState
|
vmState = xp.chain.vmState
|
||||||
|
|
||||||
|
if not item.tx.validateChainId(xp.chain.com.chainId):
|
||||||
|
discard xp.txDB.dispose(item, txInfoChainIdMismatch)
|
||||||
|
return ok(false) # continue with next account
|
||||||
|
|
||||||
# EIP-4844
|
# EIP-4844
|
||||||
if pst.numBlobPerBlock + item.tx.versionedHashes.len > MAX_BLOBS_PER_BLOCK:
|
if pst.numBlobPerBlock + item.tx.versionedHashes.len > MAX_BLOBS_PER_BLOCK:
|
||||||
return err() # stop collecting
|
return err() # stop collecting
|
||||||
|
|
|
@ -191,6 +191,19 @@ proc signTransaction*(tx: Transaction, privateKey: PrivateKey, chainId: ChainId,
|
||||||
result.R = UInt256.fromBytesBE(sig[0..31])
|
result.R = UInt256.fromBytesBE(sig[0..31])
|
||||||
result.S = UInt256.fromBytesBE(sig[32..63])
|
result.S = UInt256.fromBytesBE(sig[32..63])
|
||||||
|
|
||||||
|
# deriveChainId derives the chain id from the given v parameter
|
||||||
|
func deriveChainId*(v: int64, chainId: ChainId): ChainId =
|
||||||
|
if v == 27 or v == 28:
|
||||||
|
chainId
|
||||||
|
else:
|
||||||
|
((v - 35) div 2).ChainId
|
||||||
|
|
||||||
|
func validateChainId*(tx: Transaction, chainId: ChainId): bool =
|
||||||
|
if tx.txType == TxLegacy:
|
||||||
|
chainId.uint64 == deriveChainId(tx.V, chainId).uint64
|
||||||
|
else:
|
||||||
|
chainId.uint64 == tx.chainId.uint64
|
||||||
|
|
||||||
func eip1559TxNormalization*(tx: Transaction;
|
func eip1559TxNormalization*(tx: Transaction;
|
||||||
baseFee: GasInt): Transaction =
|
baseFee: GasInt): Transaction =
|
||||||
## This function adjusts a legacy transaction to EIP-1559 standard. This
|
## This function adjusts a legacy transaction to EIP-1559 standard. This
|
||||||
|
|
Loading…
Reference in New Issue