Skip to content

Commit 783a0a8

Browse files
committed
consensus/dbft: forbid new transaction types in envelope verification
1 parent 0d2d149 commit 783a0a8

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

antimev/envelope.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var (
5151
// IsEnvelope checks whether a transaction is an Envelope transaction. The criteria
5252
// include receiver's address, data prefix and data length check.
5353
func IsEnvelope(tx *types.Transaction) bool {
54-
return IsEnvelopeToAddress(tx.To()) && IsEnvelopeData(tx.Data())
54+
return (tx.Type() != types.BlobTxType && tx.Type() != types.SetCodeTxType) && IsEnvelopeToAddress(tx.To()) && IsEnvelopeData(tx.Data())
5555
}
5656

5757
// IsEnvelopeToAddress checks whether an address pointer has the expected value for

consensus/dbft/dbft.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -926,13 +926,19 @@ func (c *DBFT) verifyPreBlockCb(b dbft.PreBlock[common.Hash]) bool {
926926
}
927927
ethBlock := dbftBlock.ToEthBlock()
928928

929-
errs := c.staticPool.Add(dbftBlock.transactions, false)
929+
// Only take legacy pool transactions.
930+
legacyTxs := make(types.Transactions, 0, len(dbftBlock.transactions))
931+
for _, tx := range dbftBlock.transactions {
932+
if tx.Type() != types.BlobTxType {
933+
legacyTxs = append(legacyTxs, tx)
934+
}
935+
}
936+
errs := c.staticPool.Add(legacyTxs, false)
930937
c.staticPool.ResetStatic()
931938
for i, err := range errs {
932939
if err != nil {
933940
log.Warn("proposed PreBlock has invalid transaction",
934-
"index", i,
935-
"hash", dbftBlock.transactions[i].Hash(),
941+
"hash", legacyTxs[i].Hash(),
936942
"error", err,
937943
)
938944
return false
@@ -1174,8 +1180,12 @@ func (c *DBFT) processPreBlockCb(b dbft.PreBlock[common.Hash]) error {
11741180
}
11751181
// No need to reinitialize static pool since it was already initialized in verifyPreBlockCb.
11761182
// Reset the static pool after processing all transactions.
1177-
for i := range pre.transactions {
1183+
for i, originTx := range pre.transactions {
11781184
var isEnvelope = j < len(pre.envelopesData) && pre.envelopesData[j].index == i
1185+
if originTx.Type() == types.BlobTxType { // Skip blob transactions.
1186+
txx[i] = originTx
1187+
continue
1188+
}
11791189
if !isEnvelope || // pre.transactions[i] is not an envelope, use it as-is.
11801190
decryptedTxsBytes[j] == nil { // pre.transactions[i] is Envelope, but its content failed to be decrypted, use Envelope as-is.
11811191
var reason string
@@ -1189,7 +1199,7 @@ func (c *DBFT) processPreBlockCb(b dbft.PreBlock[common.Hash]) error {
11891199
}
11901200
}
11911201
log.Info("Envelope data decrypted",
1192-
"envelope hash", pre.transactions[i].Hash(),
1202+
"envelope hash", originTx.Hash(),
11931203
"envelope index", i,
11941204
"data", hex.EncodeToString(decryptedTxsBytes[j]))
11951205
var decryptedTx = new(types.Transaction)
@@ -1201,7 +1211,7 @@ func (c *DBFT) processPreBlockCb(b dbft.PreBlock[common.Hash]) error {
12011211
break
12021212
}
12031213
}
1204-
err = c.validateDecryptedTx(parent, decryptedTx, pre.transactions[i], receipts[i])
1214+
err = c.validateDecryptedTx(parent, decryptedTx, originTx, receipts[i])
12051215
if err != nil {
12061216
if fallbackToEnvelope(i, true, fmt.Sprintf("decrypted transaction verification failed: %s", err)) {
12071217
continue
@@ -1295,6 +1305,11 @@ func (c *DBFT) initStaticPool(parent *types.Header, state *state.StateDB) error
12951305

12961306
// validateDecryptedTx checks the validity of the transaction to determine whether the outer envelope transaction should be replaced.
12971307
func (c *DBFT) validateDecryptedTx(head *types.Header, decryptedTx *types.Transaction, envelope *types.Transaction, envelopeReceipt *types.Receipt) error {
1308+
// Make sure the transaction type is supported by legacy tx pool
1309+
if decryptedTx.Type() == types.BlobTxType {
1310+
return fmt.Errorf("decryptedTx has unsupported type: %v", decryptedTx.Type())
1311+
}
1312+
12981313
// Make sure the transaction is signed properly and has the same sender and nonce with envelope
12991314
if decryptedTx.Nonce() != envelope.Nonce() {
13001315
return fmt.Errorf("decryptedTx nonce mismatch: decryptedNonce %v, envelopeNonce %v", decryptedTx.Nonce(), envelope.Nonce())

0 commit comments

Comments
 (0)